Backlash amount/direction variable type and persistence...
Posted: Sun Jul 24, 2022 8:49 pm
I'm currently using persist variables to move backlash amount and direction variables about my code for various reasons (such as being able to keep BL amount and direction after an axis has been .enabled and when my app is started and stopped. My code appears to be working but I'd like some clarity on the types I should be using and if I'm casting them correctly or just 'lucking out'.
As kept in the KFlop, should ch->Backlash be a float and ch->BacklashDirection be an int?
I'm currently using the following code to copy the values from the KFlop into the persist variables, which seems to work, but doesn't seem like it should.....
float Axis0_Backlash;
float Axis0_BacklashDirection;
Axis0_BacklashDirection=ch0->BacklashDirection;
Axis0_Backlash=ch0->Backlash;
persist.UserData[GPV__AXIS_0_BACKLASH] = *(int *) & Axis0_Backlash;
persist.UserData[GPV__AXIS_0_BACKLASHDIRECTION] = *(int *) & Axis0_BacklashDirection;
.....and this code to copy the values from the persist variables back into the KFlop......
float Axis0_Backlash;
float Axis0_BacklashDirection;
Axis0_Backlash = *(float *) &persist.UserData[GPV__AXIS_0_BACKLASH];
Axis0_BacklashDirection = *(float *) &persist.UserData[GPV__AXIS_0_BACKLASHDIRECTION];
ch0->Backlash=Axis0_Backlash;
ch0->BacklashDirection=Axis0_BacklashDirection;
I feel like I've got 'two wrongs making a right' somewhere here. I'd appreciate any suggestions.
As kept in the KFlop, should ch->Backlash be a float and ch->BacklashDirection be an int?
I'm currently using the following code to copy the values from the KFlop into the persist variables, which seems to work, but doesn't seem like it should.....
float Axis0_Backlash;
float Axis0_BacklashDirection;
Axis0_BacklashDirection=ch0->BacklashDirection;
Axis0_Backlash=ch0->Backlash;
persist.UserData[GPV__AXIS_0_BACKLASH] = *(int *) & Axis0_Backlash;
persist.UserData[GPV__AXIS_0_BACKLASHDIRECTION] = *(int *) & Axis0_BacklashDirection;
.....and this code to copy the values from the persist variables back into the KFlop......
float Axis0_Backlash;
float Axis0_BacklashDirection;
Axis0_Backlash = *(float *) &persist.UserData[GPV__AXIS_0_BACKLASH];
Axis0_BacklashDirection = *(float *) &persist.UserData[GPV__AXIS_0_BACKLASHDIRECTION];
ch0->Backlash=Axis0_Backlash;
ch0->BacklashDirection=Axis0_BacklashDirection;
I feel like I've got 'two wrongs making a right' somewhere here. I'd appreciate any suggestions.