Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98005 > unrolled thread

GoPiGo script

Started byinput/ldompeling@casema.nl
First post2015-10-30 16:58 +0000
Last post2015-10-31 21:12 +0000
Articles 20 on this page of 23 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  GoPiGo script input/ldompeling@casema.nl - 2015-10-30 16:58 +0000
    Re: GoPiGo script Peter Pearson <pkpearson@nowhere.invalid> - 2015-10-30 17:27 +0000
      Re: GoPiGo script input/ldompeling@casema.nl - 2015-11-02 13:29 +0000
        Re: GoPiGo script hakugin.gin@gmail.com - 2015-11-02 05:45 -0800
          Re: GoPiGo script hakugin.gin@gmail.com - 2015-11-02 05:49 -0800
            Re: GoPiGo script input/ldompeling@casema.nl - 2015-11-02 14:28 +0000
              Re: GoPiGo script hakugin.gin@gmail.com - 2015-11-02 07:19 -0800
              Re: GoPiGo script MRAB <python@mrabarnett.plus.com> - 2015-11-02 15:21 +0000
                Re: GoPiGo script hakugin.gin@gmail.com - 2015-11-02 07:30 -0800
        Re: GoPiGo script Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-11-02 09:10 -0500
          Re: GoPiGo script input/ldompeling@casema.nl - 2015-11-02 14:32 +0000
            Re: GoPiGo script Robin Koch <robin.koch@t-online.de> - 2015-11-02 20:31 +0100
              Re: GoPiGo script Larry Hudson <orgnut@yahoo.com> - 2015-11-02 13:06 -0800
                Re: GoPiGo script Robin Koch <robin.koch@t-online.de> - 2015-11-03 01:45 +0100
    Re: GoPiGo script hakugin.gin@gmail.com - 2015-10-30 10:32 -0700
      Re: GoPiGo script input/ldompeling@casema.nl - 2015-10-30 18:18 +0000
        Re: GoPiGo script hakugin.gin@gmail.com - 2015-10-30 12:59 -0700
          Re: GoPiGo script input/ldompeling@casema.nl - 2015-10-31 10:28 +0000
            Re: GoPiGo script MRAB <python@mrabarnett.plus.com> - 2015-10-31 17:42 +0000
              Re: GoPiGo script input/ldompeling@casema.nl - 2015-10-31 18:59 +0000
                Re: GoPiGo script MRAB <python@mrabarnett.plus.com> - 2015-10-31 19:42 +0000
                  Re: GoPiGo script input/ldompeling@casema.nl - 2015-10-31 20:18 +0000
                    Re: GoPiGo script MRAB <python@mrabarnett.plus.com> - 2015-10-31 21:12 +0000

Page 1 of 2  [1] 2  Next page →


#98005 — GoPiGo script

Frominput/ldompeling@casema.nl
Date2015-10-30 16:58 +0000
SubjectGoPiGo script
Message-ID<IkNYx.3165$PJ.1385@fx05.am1>
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.

Thanks
-------------------------------------------------------------------------------

from gopigo import *
import time


set_right_speed(150)
set_left_speed(105)

while True:
#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))
                                             


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

[toc] | [next] | [standalone]


#98006

FromPeter Pearson <pkpearson@nowhere.invalid>
Date2015-10-30 17:27 +0000
Message-ID<d9hnjqF4lbuU1@mid.individual.net>
In reply to#98005
On Fri, 30 Oct 2015 16:58:16 GMT, input/ldompeling@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.

[toc] | [prev] | [next] | [standalone]


#98097

Frominput/ldompeling@casema.nl
Date2015-11-02 13:29 +0000
Message-ID<AyJZx.1$Gy4.0@fe40.am1>
In reply to#98006
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@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
------------------- ----- ---- -- -

[toc] | [prev] | [next] | [standalone]


#98098

Fromhakugin.gin@gmail.com
Date2015-11-02 05:45 -0800
Message-ID<7bcb9d61-e610-47e3-9cba-35eba075e993@googlegroups.com>
In reply to#98097
On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld...@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>

Try this: (hopefully the indentation is preserved)

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:
        mindist = 90
        server(90)
        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

[toc] | [prev] | [next] | [standalone]


#98099

Fromhakugin.gin@gmail.com
Date2015-11-02 05:49 -0800
Message-ID<197fe872-0501-4ce8-a273-5220d4527c1f@googlegroups.com>
In reply to#98098
On Monday, November 2, 2015 at 8:45:35 AM UTC-5, hakug...@gmail.com wrote:
> On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld...@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

[toc] | [prev] | [next] | [standalone]


#98102

Frominput/ldompeling@casema.nl
Date2015-11-02 14:28 +0000
Message-ID<5qKZx.1282$u_1.105@fx05.am1>
In reply to#98099
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@gmail.com" who wrote the following:

> On Monday, November 2, 2015 at 8:45:35 AM UTC-5, hakug...@gmail.com wrote:
> > On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld...@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
------------------- ----- ---- -- -

[toc] | [prev] | [next] | [standalone]


#98107

Fromhakugin.gin@gmail.com
Date2015-11-02 07:19 -0800
Message-ID<e4e11fd6-01b2-4b86-9fc9-13c50b25342f@googlegroups.com>
In reply to#98102
On Monday, November 2, 2015 at 9:28:35 AM UTC-5, input/ld...@casema.nl wrote:
> 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
> -------------------------------------------------------------------------------
> 

And this is why I shouldn't code while tired hahaha...

I reviewed the code I submitted and found a couple of other errors. If you are changing the "sleep()" lines to "time.sleep()" you will need to change the line "from time import sleep" to "import time", otherwise you will most likely encounter something like:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'time' is not defined

Since you are just beginning with Python I would suggest reading various entry level books such as Python 101 by Mike Driscoll, which I have read and own. I am not Mike Driscoll, but his book and blog, http://www.blog.pythonlibrary.org/ have been extremely helpful. There are MANY resources available for learning the Python programming language out there, including https://wiki.python.org/moin/BeginnersGuide

[toc] | [prev] | [next] | [standalone]


#98108

FromMRAB <python@mrabarnett.plus.com>
Date2015-11-02 15:21 +0000
Message-ID<mailman.69.1446477686.4463.python-list@python.org>
In reply to#98102
On 2015-11-02 14:28, input/ldompeling@casema.nl wrote:
> 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
> -------------------------------------------------------------------------------
>
The previous line is missing a ")"; it should end with two of them, not
just one.

> In reply to "hakugin.gin@gmail.com" who wrote the following:
>
>> On Monday, November 2, 2015 at 8:45:35 AM UTC-5, hakug...@gmail.com wrote:
>> > On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld...@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()
>>

[toc] | [prev] | [next] | [standalone]


#98109

Fromhakugin.gin@gmail.com
Date2015-11-02 07:30 -0800
Message-ID<5fb9577c-175f-402a-9307-3d9e7f448cc7@googlegroups.com>
In reply to#98108
On Monday, November 2, 2015 at 10:21:46 AM UTC-5, MRAB wrote:
> On 2015-11-02 14:28, input/ldom...@casema.nl wrote:
> > 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
> > -------------------------------------------------------------------------------
> >
> The previous line is missing a ")"; it should end with two of them, not
> just one.
> 

Yep, I shouldn't code while tired... I also forgot to change line 31 from "time.sleep(2)" to "sleep(2)".

> > In reply to "haku...@gmail.com" who wrote the following:
> >
> >> On Monday, November 2, 2015 at 8:45:35 AM UTC-5, hakug...@gmail.com wrote:
> >> > On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld...@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()
> >>

[toc] | [prev] | [next] | [standalone]


#98101

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2015-11-02 09:10 -0500
Message-ID<mailman.64.1446473424.4463.python-list@python.org>
In reply to#98097
On Mon, 02 Nov 2015 13:29:04 GMT, input/ldompeling@casema.nl declaimed the
following:

>I tried to use def loop(): now for to restart the script.
>but its only restart "fwd()" print ("forward 1x") and then stop.

>def loop():
>    fwd()
>    print ("forward 1x")
>    time.sleep(2)
>    stop()
>
>if mindist > us_dist(15):

	Which is exactly what you told it to do. You have defined a function
containing four statements: fwd(), print(), sleep(), and stop(); after
executing the stop the function will return to where it was called -- the
end of your program.

	All of your"if" statements will be executed after "loop" is defined
(but not executed) and before the call to "loop" at the bottom. They are
NOT part of "loop". Please reread the Python language reference manual,
focusing on the part that describes indentation and block structuring.


>loop()
>

	Also, just calling something "loop" does not make it a loop. This
function will be called just one time and then the program will exit.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#98104

Frominput/ldompeling@casema.nl
Date2015-11-02 14:32 +0000
Message-ID<tuKZx.1283$u_1.517@fx05.am1>
In reply to#98101
Thank you for the explanation for it.
I must tell you that  i yust beginning with python.
I bought the book beginning programming with python.









In reply to "Dennis Lee Bieber" who wrote the following:

> On Mon, 02 Nov 2015 13:29:04 GMT, input/ldompeling@casema.nl declaimed the
> following:
> 
> > I tried to use def loop(): now for to restart the script.
> > but its only restart "fwd()" print ("forward 1x") and then stop.
> 
> > def loop():
> >    fwd()
> >    print ("forward 1x")
> >    time.sleep(2)
> >    stop()
> > 
> > if mindist > us_dist(15):
> 
>  Which is exactly what you told it to do. You have defined a function
> containing four statements: fwd(), print(), sleep(), and stop(); after
> executing the stop the function will return to where it was called -- the
> end of your program.
> 
>  All of your"if" statements will be executed after "loop" is defined
> (but not executed) and before the call to "loop" at the bottom. They are
> NOT part of "loop". Please reread the Python language reference manual,
> focusing on the part that describes indentation and block structuring.
> 
> 
> > loop()
> > 
> 
>  Also, just calling something "loop" does not make it a loop. This
> function will be called just one time and then the program will exit.
> --
>  Wulfraed                 Dennis Lee Bieber         AF6VN
>     wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/




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

[toc] | [prev] | [next] | [standalone]


#98115

FromRobin Koch <robin.koch@t-online.de>
Date2015-11-02 20:31 +0100
Message-ID<n18dmg$hvo$1@news.albasani.net>
In reply to#98104
Am 02.11.2015 um 15:32 schrieb input/ldompeling@casema.nl:

> Thank you for the explanation for it.
> I must tell you that  i yust beginning with python.
> I bought the book beginning programming with python.

Have you programming experience with other languages?

Well, the very first thing you should have learned is the basic syntax 
of Python. (That's how a program has to be written to work properly.)

And one of those first things is that python code is structured not by 
braces (like many other programming languages), but by intendation (as 
mentioned by others before).

That means that everything "depending" of a line somehow has to be 
intended deeper than that line.

Those lines are typically lines starting with "if", "for", "while", 
"def" or other keywords and end with a colon.

In your code the ifs and fors (and the following lines) are correctly 
intended. But you are using the "while" and "def" kind of wrong.

Let me give an example (note that the line numbers are only for this 
posting to prevent funny formating business and to talk about the single 
lines!):

01 for i in [1,2,3]:
02     print('A')
03     print('B')
04 print('C')

The first line (01) starts a loop. (Starting with a for, ending with a 
colon.) For every entry in the given list "something" is supposed to be 
repeated. But what is repeated and what isn't?

Easy: All following *intended* lines (02-03) are repeated.
Line 04 isn't intended and marks the point where the loop ends.

The output of the above is:

A
B
A
B
A
B
C


If we change the code just a tiny bit:

01 for i in [1,2,3]:
02     print('A')
03 print('B')
04 print('C')

(Notice, that the only change is the removed whitespace in line 03.)

only line 02 is repeated:

A
A
A
B
C


That works also for if and while:

01 if False:
02     print("This isn't printed.")
03     print("This neigther.")
03 print("But this is!")

01 c = 1
02 while c < 10:
03     print(c)
04     c = c*2
05 print("done")

prints

1
2
4
8
done


And of course those are mixable:

01 for a in [3,5,7]:
02    b = 1
03    while a*b < 10:
04	if a*b % 2 != 0:
05            print(a*b)
06        b = b+1
07    print("Next a")
08 print("done")

prints:

3
9
Next a
5
Next a
7
Next a
done


And this is where your problems seems to be.

You start with

"while True:"

which does start an endless loop.

But: As explained it only repeats the lines theat follow and are intended!

In your original post the next line isn't intended at all, which is 
considered an error.
In your second attempt you intended only the first 5 lines. So those 
(and only those) are repeated.

The next line ("if mindist > us_dist(15):") wasn't intended and 
therefore *not* repeated.

If you just learning programming with Python you migth want to start 
with smaller examples to understand the syntax better.
Do you understand what the script is supposed to do in every line?

-- 
Robin Koch

[toc] | [prev] | [next] | [standalone]


#98118

FromLarry Hudson <orgnut@yahoo.com>
Date2015-11-02 13:06 -0800
Message-ID<GIqdnXbZo7v1TarLnZ2dnUU7-Y_OydjZ@giganews.com>
In reply to#98115
On 11/02/2015 11:31 AM, Robin Koch wrote:
> Am 02.11.2015 um 15:32 schrieb input/ldompeling@casema.nl:
>
>> Thank you for the explanation for it.
>> I must tell you that  i yust beginning with python.
>> I bought the book beginning programming with python.
>
> Have you programming experience with other languages?
>
> Well, the very first thing you should have learned is the basic syntax of Python. (That's how a
> program has to be written to work properly.)
>
> And one of those first things is that python code is structured not by braces (like many other
> programming languages), but by intendation (as mentioned by others before).
                                  ^^^^^^^^^^^

[snip a lot of text, also using the word intend...]

The word you want is indent not intend.
Intend means something entirely different,
and is not a Python term.

      -=- Larry -=-

[toc] | [prev] | [next] | [standalone]


#98120

FromRobin Koch <robin.koch@t-online.de>
Date2015-11-03 01:45 +0100
Message-ID<n19033$jkj$1@news.albasani.net>
In reply to#98118
Am 02.11.2015 um 22:06 schrieb Larry Hudson:

> [snip a lot of text, also using the word intend...]
>
> The word you want is indent not intend.

Oops. Of course you are right.
You might have noticed, english isn't my native language.
Not an excuse, but an explanation. ;-)

I can only hope, that Loek does understand what I meant.

> Intend means something entirely different,
> and is not a Python term.

Yes, I know the difference. I just didn't pay enough attention to it.

Ironically enough I wrote actually another post about Android-intends 
earlier.

-- 
Robin Koch

[toc] | [prev] | [next] | [standalone]


#98007

Fromhakugin.gin@gmail.com
Date2015-10-30 10:32 -0700
Message-ID<145f0361-1341-481a-a839-b024d7775b34@googlegroups.com>
In reply to#98005
On Friday, October 30, 2015 at 12:58:43 PM UTC-4, input/ld...@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.
> 
> Thanks
> -------------------------------------------------------------------------------
> 
> from gopigo import *
> import time
> 
> 
> set_right_speed(150)
> set_left_speed(105)
> 
> while True:
> #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))
>                                              
> 
> 
> -- 
> --------------------------------- --- -- -
> Posted with NewsLeecher v7.0 Beta 2
> Web @ http://www.newsleecher.com/?usenet
> ------------------- ----- ---- -- -

Can you please provide a copy/paste of the errors you are receiving? I will also try to provide an example of a constant loop when I get a chance between tasks I am working on.

[toc] | [prev] | [next] | [standalone]


#98008

Frominput/ldompeling@casema.nl
Date2015-10-30 18:18 +0000
Message-ID<mwOYx.20809$Xp5.13765@fx03.am1>
In reply to#98007
Thank you or the reply.
This is the errorwith while True:
 
File "test03.py", line 10
    enable_servo()


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

> On Friday, October 30, 2015 at 12:58:43 PM UTC-4, input/ld...@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.
> > 
> > Thanks
> > 
----------------------------------------------------------------------------
> > ---
> > 
> > from gopigo import *
> > import time
> > 
> > 
> > set_right_speed(150)
> > set_left_speed(105)
> > 
> > while True:
> > #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))
> > 
> > 
> > 
> > --
> > --------------------------------- --- -- -
> > Posted with NewsLeecher v7.0 Beta 2
> > Web @ http://www.newsleecher.com/?usenet
> > ------------------- ----- ---- -- -
> 
> Can you please provide a copy/paste of the errors you are receiving? I will 
> also try to provide an example of a constant loop when I get a chance between 
> tasks I am working on.




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

[toc] | [prev] | [next] | [standalone]


#98010

Fromhakugin.gin@gmail.com
Date2015-10-30 12:59 -0700
Message-ID<105057e9-3747-4f25-bda7-336f0cafa510@googlegroups.com>
In reply to#98008
On Friday, October 30, 2015 at 2:19:21 PM UTC-4, input/ld...@casema.nl wrote:
> Thank you or the reply.
> This is the errorwith while True:
>  
> File "test03.py", line 10
>     enable_servo()
> 
> 
> In reply to "haku...@gmail.com" who wrote the following:
> 
> > On Friday, October 30, 2015 at 12:58:43 PM UTC-4, input/ld...@casema.nl 
> wrote:
> > > The GoPiGo is a little robot on wheels.
> > > 

<snip>
> > > enable_servo()
<snip>

If it is returning an error with "enable_servo()" then there are a few possible causes. I would make sure everything is indented correctly, as well as check and ensure the function is in the gopigo library. Those would be the 2 most likely causes. As for the issue with the while loop, I would definitely follow Peter's advice. I started to create a small example script but found that what I classify as simple may not be as simple for others, but I will do my best to get something done over the weekend if you haven't found a solution by Monday.

[toc] | [prev] | [next] | [standalone]


#98017

Frominput/ldompeling@casema.nl
Date2015-10-31 10:28 +0000
Message-ID<yJ0Zx.11318$vU.8390@fe15.am1>
In reply to#98010
I intended the rules under while True: 
The script is working now only the wheels go's only forward "(fwd)",so the 
sensor not detect any obstacles.(sensor=us_dist(15).

-------------------------------------------------------------------------------

from gopigo import *
import time


set_right_speed(150)
set_left_speed(105)

while True:
#def test():
    enable_servo()
    mindist = 80
    servo(90)
    fwd()
    print ("forward1x")
#time.sleep(5)
#stop()

if mindist > us_dist(15):
     #enc_tgt(1,1,72)
    bwd()
    print ("backward1x",us_dist(15))
    time.sleep(2)
    left_rot()
    print("left rot",us_dist(15))
    time.sleep(3)
    stop()

if mindist < us_dist(15):
   #enc_tgt(1,1,72)
    fwd()
    print("forward2x",us_dist(15))
    time.sleep(2)
    stop()

for x in range(3):

    if mindist > us_dist(15):
         bwd()
         print("backward2x",us_dist(15))




















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

> On Friday, October 30, 2015 at 2:19:21 PM UTC-4, input/ld...@casema.nl wrot=
> e:
> > Thank you or the reply.
> > This is the errorwith while True:
> > =20
> > File "test03.py", line 10
> >     enable_servo()
> > =20
> > =20
> > In reply to "haku...@gmail.com" who wrote the following:
> > =20
> > > On Friday, October 30, 2015 at 12:58:43 PM UTC-4, input/ld...@casema.nl=
> =20
> > wrote:
> > > > The GoPiGo is a little robot on wheels.
> > > > =20
> 
> <snip>
> > > > enable_servo()
> <snip>
> 
> If it is returning an error with "enable_servo()" then there are a few poss=
> ible causes. I would make sure everything is indented correctly, as well as=
>  check and ensure the function is in the gopigo library. Those would be the=
>  2 most likely causes. As for the issue with the while loop, I would defini=
> tely follow Peter's advice. I started to create a small example script but =
> found that what I classify as simple may not be as simple for others, but I=
>  will do my best to get something done over the weekend if you haven't foun=
> d a solution by Monday.




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

[toc] | [prev] | [next] | [standalone]


#98019

FromMRAB <python@mrabarnett.plus.com>
Date2015-10-31 17:42 +0000
Message-ID<mailman.0.1446313334.4463.python-list@python.org>
In reply to#98017
On 2015-10-31 10:28, input/ldompeling@casema.nl wrote:
> I intended the rules under while True:
> The script is working now only the wheels go's only forward "(fwd)",so the
> sensor not detect any obstacles.(sensor=us_dist(15).
>
> -------------------------------------------------------------------------------
>
> from gopigo import *
> import time
>
>
> set_right_speed(150)
> set_left_speed(105)
>
The body of the 'while' loop extends from the line:

     enable_servo()

to the line:

     print ("forward1x")

Would that explain it?

> while True:
> #def test():
>      enable_servo()
>      mindist = 80
>      servo(90)
>      fwd()
>      print ("forward1x")
> #time.sleep(5)
> #stop()
>
> if mindist > us_dist(15):
>       #enc_tgt(1,1,72)
>      bwd()
>      print ("backward1x",us_dist(15))
>      time.sleep(2)
>      left_rot()
>      print("left rot",us_dist(15))
>      time.sleep(3)
>      stop()
>
> if mindist < us_dist(15):
>     #enc_tgt(1,1,72)
>      fwd()
>      print("forward2x",us_dist(15))
>      time.sleep(2)
>      stop()
>
> for x in range(3):
>
>      if mindist > us_dist(15):
>           bwd()
>           print("backward2x",us_dist(15))
>

[toc] | [prev] | [next] | [standalone]


#98020

Frominput/ldompeling@casema.nl
Date2015-10-31 18:59 +0000
Message-ID<nc8Zx.6937$Ct7.770@fe48.am1>
In reply to#98019
> The body of the 'while' loop extends from the line:
> 
>      enable_servo()
> 
> to the line:
> 
>      print ("forward1x")
> 
> Would that explain it?

When i run this scipt its only print a lot off print1x.
Do you mean that ?

Thanks

In reply to "MRAB" who wrote the following:

> On 2015-10-31 10:28, input/ldompeling@casema.nl wrote:
> > I intended the rules under while True:
> > The script is working now only the wheels go's only forward "(fwd)",so the
> > sensor not detect any obstacles.(sensor=us_dist(15).
> > 
> > 
----------------------------------------------------------------------------
> > ---
> > 
> > from gopigo import *
> > import time
> > 
> > 
> > set_right_speed(150)
> > set_left_speed(105)
> > 
> The body of the 'while' loop extends from the line:
> 
>      enable_servo()
> 
> to the line:
> 
>      print ("forward1x")
> 
> Would that explain it?
> 
> > while True:
> > #def test():
> >      enable_servo()
> >      mindist = 80
> >      servo(90)
> >      fwd()
> >      print ("forward1x")
> > #time.sleep(5)
> > #stop()
> > 
> > if mindist > us_dist(15):
> >       #enc_tgt(1,1,72)
> >      bwd()
> >      print ("backward1x",us_dist(15))
> >      time.sleep(2)
> >      left_rot()
> >      print("left rot",us_dist(15))
> >      time.sleep(3)
> >      stop()
> > 
> > if mindist < us_dist(15):
> >     #enc_tgt(1,1,72)
> >      fwd()
> >      print("forward2x",us_dist(15))
> >      time.sleep(2)
> >      stop()
> > 
> > for x in range(3):
> > 
> >      if mindist > us_dist(15):
> >           bwd()
> >           print("backward2x",us_dist(15))
> >




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

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.python


csiph-web