GoPiGo script

input/ldompeling at casema.nl input/ldompeling at casema.nl
Mon Nov 2 09:28:17 EST 2015


He mike,

Thank you or making this script.
Only I get errors for sleep.
I also tried to change it to time.sleep() but that also gives errors.

File "test05.py", line 23
    sleep(2)
        ^
SyntaxError: invalid syntax
-------------------------------------------------------------------------------

In reply to "hakugin.gin at gmail.com" who wrote the following:

> On Monday, November 2, 2015 at 8:45:35 AM UTC-5, hakug... at gmail.com wrote:
> > On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld... at casema.nl 
> > wrote:
> > > 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
> > 
> > <snip>
> > 
> 
> Ignore that last suggestion... between auto correct and other things there 
are
> some issues with it.
> 
> Try this instead:
> 
> from gopigo import *
> from time import sleep
> 
> # Boolean variable for the "while" loop
> KEEP_GOING = True
> 
> enable_servo()
> mindist = 80
> servo(90)
> 
> set_right_speed(150)
> set_left_speed(105)
> 
> def MainLoop():
>   # A check statement can be added to set KEEP_GOING to False
>   # and allow the function to end
>     while KEEP_GOING:
>         fwd()
>         print("forward1x")
>         if mindist > us_dist(15):
>             bwd()
>             print("backward1x",us_dist(15)
>             sleep(2)
>             left_rot()
>             print("left rot",us_dist(15))
>             sleep(3)
>             stop()
>         if mindist < us_dist(15):
>             fwd()
>             print("forward2x",us_dist(15))
>             time.sleep(2)
>             stop()
> 
> # This is a simple check to determine if the script was run by itself
> # or if it was imported by another script. If it was imported it will
> # fail this check and not run the code but will allow access to the
> # function defined above.
> if __name__ == '__main__':
>     MainLoop()
> 
> - Mike




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




More information about the Python-list mailing list