Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: MRAB Newsgroups: comp.lang.python Subject: Re: GoPiGo script Date: Mon, 2 Nov 2015 15:21:16 +0000 Lines: 79 Message-ID: References: <197fe872-0501-4ce8-a273-5220d4527c1f@googlegroups.com> <5qKZx.1282$u_1.105@fx05.am1> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de lNc4FXt9406905xZ3ZN40glhQh7cUonx2ESuQ7A8BBQg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '__name__': 0.07; 'imported': 0.09; 'subject:script': 0.09; 'syntax': 0.13; 'def': 0.13; 'ignore': 0.14; '"while"': 0.16; "'__main__':": 0.16; 'boolean': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'instead:': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'syntaxerror:': 0.16; 'wrote:': 0.16; 'script.': 0.18; 'variable': 0.18; '2015': 0.20; 'defined': 0.23; 'wrote': 0.23; 'errors': 0.23; 'tried': 0.24; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'script': 0.25; 'header:User- Agent:1': 0.26; 'errors.': 0.27; 'correct': 0.28; 'function': 0.28; 'restart': 0.29; 'sleep': 0.29; 'print': 0.30; 'code': 0.30; 'another': 0.32; 'received:84': 0.32; 'statement': 0.32; 'run': 0.33; 'file': 0.34; 'previous': 0.34; 'gives': 0.35; 'fail': 0.35; 'false': 0.35; 'nothing.': 0.35; 'skip:p 30': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'monday,': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'thanks': 0.37; 'missing': 0.37; 'things': 0.38; 'itself': 0.38; 'thank': 0.38; 'end': 0.39; 'does': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'determine': 0.61; 'email addr:gmail.com': 0.62; 'further': 0.62; 'making': 0.62; 'between': 0.65; 'reply': 0.68; '(while': 0.84; 'mike,': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=MbeRwMLf c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=EBOSESyhAAAA:8 a=IkcTkHD0fZMA:10 a=pGLkceISAAAA:8 a=FRyMo_umxH_mg1sFwCkA:9 a=QEXdDO2ut3YA:10 a=J2hGmUjFLZcA:10 X-AUTH: mrabarnett@:2500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: <5qKZx.1282$u_1.105@fx05.am1> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:98108 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 >> > >> > >> > >> >> 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() >>