Search code examples
pythontimerobotics

How do I change the duration of the robot going backwards


I am just wondering if someone could help me out. I am controlling a robot via a Raspberry Pi, using Python and want to know how I can change the amount of time the robot moves backwards for. It's currently on half a second and I would like it to be three seconds. I have listed the code below that I am using thus far.

import time
from gopigo import *  # Has the basic functions for controlling the GoPiGo Robot
import sys  # Used for closing the running program

now = time.time()
future = now + 0.500
while time.time() < future:
    bwd()  # Move backward
stop()  
sys.exit()

Solution

  • From what I can see, time here is now ("0") plus 0.500 ("half a second"). To change to 3 secs, you need to do "now" plus "3".

    Try this and let us know!

    import time
    from gopigo import *
    import sys
    
    now = time.time()
    future = now + 3
    
    while time.time() < future:
        bwd()
    
    stop()
    sys.exit()