G4P sliders not updating during calculations in Button Controller
Here is the problem I am having and have not been able to resolve this problem. Tried several solutions but no luck and have been working on this issue for several days.
I created a Button in Setup with no problem and it executes with no issue. The commands in the button are as follows:
public void button1_click1(GButton source, GEvent event) { //_CODE_:button1:289466:
ScriptEnabled = 1;
move_to_xyz(13.64, 0, 3.5849);
movePosition();
delay(5000);
move_to_xyz(14.64, 0, 3.5849);
movePosition();
delay(5000);
GripperFixedPitchAngle();
delay(5000);
ScriptEnabled = 0;
} //_CODE_:button1:289466:
The move_to_xyz(xxx, yyy, zzz) function calculates 6 angles for a robot and seems to work fine to calculate the values correctly. The movePosition() function commands the servos to move to the angles calculated from move_to_xyz(). The movePosition() function is shown below:
void movePosition() {
float t0, t1, t2, t3;
int flag0, flag1, flag2, flag3;
flag0 = flag1 = flag2 = flag3 = 0;
t0 = t1 = t2 = t3 = 0.0;
GripperFixedPitchAngle();
//updateFK();
for( int ii = 0; ii < 6; ii++) {
print(q[ii]*180/3.1451); print(" "); }
println(); println();
t0 = (float) q[0]*rad2deg;
t1 = (float) q[1]*rad2deg;
t2 = (float) q[2]*rad2deg;
t3 = (float) q[3]*rad2deg;
//Failsafe to avoid going beyond angle limits,i.e., set stops
if(t0 < -80 || t0 > 80) flag0 = 1;
if(t1 < 10 || t1 > 160) flag1 = 1;
if(t2 < -150 || t2 > 45) flag2 = 1;
if(t3 < 0 || t3 > 180) flag3 = 1;
if((flag0+flag1+flag2+flag3) == 0 ) {
slider1.setValue(t0);
slider3.setValue(t2);
slider2.setValue(t1);
slider4.setValue(t3);
}
}
Changes to the slider result in command to the servos to move. Below is the code for the one of the sliders (all others are the same except that the servo number changes:
public void slider1_change1(GSlider source, GEvent event) { //_CODE_:slider1:790724:
myPort.clear();
myPort.write("0,"+slider1.getValueI()+"\n");
acknowledge();
GripperFixedPitch();
if(FKenable == 1) updateFK();
}
} //_CODE_:slider1:790724:
The issue is that the sliders will not update until after the Button controller is completed and only the last move is displayed. Not sure how to fix the problem, i.e., getting the sliders to move so the arm can move at each move command is sent to the slider. By the way moving the sliders individually work fine to move the arm.
I also tried moving the commands to the draw() with the button just setting a flag but the sliders still did not update.
Any help would be appreciated.