Simple Pythonscript

I make this script but it does not sleep and the wheels only goes forward not backward.
Have someboy an idea ?

from gopigo import *
import time
fwd ()
time.sleep (2)
bwd ()
print volt ()
stop ()

Can you try out the example here and give it “w”,“s”,“d”,“a” commands and see if it works properly for you.


He karan,
The work by me properly.

Were you able to take pointers from the basic_teat_all and to get your script working.


He karan,
karan if you watch this video you can see that time.sleep is not working properly.
Are there no technics at Dexter inudstries to solve the problem wit time.sleep.
If you open a terminal and exute sudo python and then fwd() and then time.sleep(2) the weels keep spinning because time.sleep won’t listen. And what do yo mean by taking pointers from the basic_test_all.


Just saw the video. It does look awesome and it’s great to see that GoPiGo working well.

So there are a few pointers that you can use with the GoPiGo, the GoPiGo does not stop after you the time.sleep(2) is because the GoPiGo expects a stop() command to stop. If you just give the sleep and don’t call any function after it, the GoPiGo won’t stop.

What we have with the software right now is encoder_targeting, where you tell how many times you want the wheels to rotate, and the GoPiGo stops after that many rotations. Here is the test code for it: .

Also, I don’t remember exactly, but the ultrasonic sensor might be returning the distance in mm and it starts giving out bad values if the obstacle is very far away. It might easy to test out what distance it gives and then tune the distance you want to use.
Do let us know if this is what you were looking for and if we could help you with anything else.

Feel free to suggest improvements to the functionality in or features that we can add for the GoPiGo.


He Karan,
I am glad that the examplescript works fine with time.sleep. But do you have also examples with “import time” in it.
I have also another question about the ultrasonic sensor i saw on the internet the hc-sr04 sensor
But it says it is for Arduino can i use that to for the GoPiGo. here is the link:


Almost every GoPiGo example does use time.sleep in some way. You can check out the projects here to have a look:

The ultrasonic sensor that we use is made by Seeedstudio and from the looks of it, it does look like a variant of HC-SR04: There is one big difference though, the sensor that we sell, has only 1 pin for input and output. When we were selecting the Ultrasonic sensors, we found that we got the best performance from the Seeed sensors and that’s why we stuck to them. The sensor that you have linked might work but you might face problems with bad data too.