GoPiGo script

input/ldompeling at casema.nl input/ldompeling at casema.nl
Mon Nov 2 08:29:04 EST 2015


I tried to use def loop(): now for to restart the script.
but its only restart "fwd()" print ("forward 1x") and then stop.
It does not look further for the if function.
Is there another way to restart this script ?
I also tried with (while True:) but that does nothing.

Thanks


-------------------------------------------------------------------------------
from  gopigo import *
import time


set_right_speed(150)
set_left_speed(105)

enable_servo
mindist = 80
servo(90)
def loop():
    fwd()
    print ("forward 1x")
    time.sleep(2)
    stop()

if mindist > us_dist(15):
    bwd()
    print ("backward 1x",us_dist(15))
    time.sleep(2)
    left_rot()
    print("left rot",us_dist(15))
    time.sleep(3)
    stop()

if mindist < us_dist(15):
    fwd()
    print("forward 2x",us_dist(15))
    time.sleep(2)
    stop()

#for x in range(3):

if mindist > us_dist(15):
    bwd()
    print("backward 2x",us_dist(15))
    time.sleep(2)
    stop()
    right()

else:
     fwd()
     print("forward else",us_dist(15))
     time.sleep(4)
     stop()

if mindist > us_dist(15):
    bwd()
    print("backward 3x")
    time.sleep(2)
    stop()
    left_rot()
    print("left rot")
    time.sleep(1)
    stop()
    mindist = 80
loop()

































In reply to "Peter Pearson" who wrote the following:

> On Fri, 30 Oct 2015 16:58:16 GMT, input/ldompeling at casema.nl wrote:
> > The GoPiGo is a little robot on wheels.
> > 
> > I want that this script restart when its ends.
> > I tried with "while True"and"return"and also "continue"
> > But those functions gives me errors.
> > What for function else can I use to restart this script.
> > 
> [snip]
> > 
> > from gopigo import *
> > import time
> > 
> > 
> > set_right_speed(150)
> > set_left_speed(105)
> > 
> > while True:
> 
> Is this the "while True" that gave you errors?  I think it
> should, since a "while" should be followed by an indented block
> of code.  Perhaps you should use this "while True" to replace
> the "for x in range(3)" near the bottom.
> 
> > #def test():
> > enable_servo()
> > mindist = 80
> > servo(90)
> > fwd()#wheels go forward
> > print ("forward1x")
> > #time.sleep(5)
> > #stop()
> > 
> > if mindist > us_dist(15):
> >      #enc_tgt(1,1,72)
> >     bwd()#wheels go backward
> >     print ("backward1x",us_dist(15))
> >     time.sleep(2)
> >     left_rot()#wheels rotate left
> >     print("left rot",us_dist(15))
> >     time.sleep(3)
> >     stop()
> > 
> > if mindist < us_dist(15):
> >    #enc_tgt(1,1,72)
> >     fwd()#wheels go forward
> >     print("forward2x",us_dist(15))
> >     time.sleep(2)
> >     stop()
> > 
> > for x in range(3):
> > 
> >     if mindist > us_dist(15):
> >          bwd()#wheels go backward
> >          print("backward2x",us_dist(15))
> 
> In future questions, it might help if you explained which of these
> print statements you would like to see executed how many times.
> 
> --
> To email me, substitute nowhere->runbox, invalid->com.




-- 
--------------------------------- --- -- -
Posted with NewsLeecher v7.0 Beta 2
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -




More information about the Python-list mailing list