How to make sure the joint has reached the desired angle before the code continues to the next operation?
Posted: 04 Dec 2022, 11:43
I am trying to make my quadruped robot walk. I have written a move_COB function the moves the center of body to a stable position and a move_leg function that move a leg throw a path.
I want my robot to finish the move_COB and only after the joints reach the target position I want the robot to move the leg using the move_leg function.
Both functions work perfectly but when I write them in my python script one after the other they happen at the same time (the COB and the leg both move together).
When I add a while loop that waits for the robot to reach the target position (using: delta = sim.getjointpositon()-target_position and a while loop: while(delta<0.01)) the loop is running but while the loop runs the robot doesn't move in the simulation so the while loop never ends- the joint position doesn't change.
I have also tried a for loop instead of the while loop and i saw that the robot COB moves only after the for loop ends (I printed the i iteration and I saw that the print happens before the robot start moving even though it is written below in the script code) .
Any ideas why is this happening? and how can I make those two functions run one after the other and not parallel (let the second function wait that the first one has ended)?
I want my robot to finish the move_COB and only after the joints reach the target position I want the robot to move the leg using the move_leg function.
Both functions work perfectly but when I write them in my python script one after the other they happen at the same time (the COB and the leg both move together).
When I add a while loop that waits for the robot to reach the target position (using: delta = sim.getjointpositon()-target_position and a while loop: while(delta<0.01)) the loop is running but while the loop runs the robot doesn't move in the simulation so the while loop never ends- the joint position doesn't change.
I have also tried a for loop instead of the while loop and i saw that the robot COB moves only after the for loop ends (I printed the i iteration and I saw that the print happens before the robot start moving even though it is written below in the script code) .
Any ideas why is this happening? and how can I make those two functions run one after the other and not parallel (let the second function wait that the first one has ended)?