How to wait for the end of fwd() function before to continue execution[SOLVED]

Hi everybody !

I have a GoPiGo2 running with the Python library, and I use a website with PHP to launch an instruction on my robot (like forward, left etc…). Now, I’d like to execute a sequence of movements, like fwd/left/bwd/right.
So my php function uses “exec(“python …/forward.py 10”, $this->feedback);” to launch a python script, that make the robot moving forward of 10 cm, and create a “friendly” feedback.
But now, to launch every instructions of my sequence, I need to use a “foreach” in my php function, and so my probleme is : only the last instruction is correct, I mean make the robot moving with the right distance.

In other terms, every instruction is executed partially, because the “exec” receive a feedback at the begin of the moving function in Python (for exemple, fwd() send “None” feedback before finishing moving the robot)

So my question is : How do I wait the end of a moving instruction in python (fwd(), bwd() etc…) before to send the final feedback to php ?
Here is my script (forward.py) :

coding: utf-8

from gopigo import *
import sys

distance = sys.argv[1];

p = int(round(18*int(distance)/20.1, 0));

retour = “”;
a = 0;

a = enc_tgt(1,1,p);
if a == 1 :
r += "Distance : "+distance+“cm\n”;
a = fwd();
if a != -1 :
r += “Moving Forward”;
print®;

Thank you for any answer !

Nobody has an idea of how to do that?

Hi @Dreamwork57,

To know if the GoPiGo has finished executing a motion based function , you should keep checking the encoder status variable as shown here. Whenever the enc_stat variable reaches 0 it means the GoPiGo has stopped after executing the command. You can keep track to check when this variable reaches zero and send feedbacks through php.

Please let us know if this helps,
-Shoban

Thanks a lot @Shoban !

It works ! And it’s exactly what I needed !

Hi @Dreamwork57,

Glad that we were able to help you.

-Shoban

This topic was automatically closed after 24 hours. New replies are no longer allowed.