Proteus
Portugal
Asked
— Edited
setVar(CLeft,0);
def loop():
if getVar("$RoombaLightBumperCenterLeft")==1:
Navigation.SetNavigationStatusToPause();
print "Bumper Center Left";
setVar(CLeft)+=1;
sleep(5);
if getVar(CLeft)== 2:
Movement.left(100, 1500);
setVar(CLeft) == 0;
sleep(2)
else:
Navigation.SetNavigationStatusToNavigating();
time.sleep(1);
loop();
loop();
I dont get this python. I am trying to add 1 to the variable "CLeft" but my code does not work. Anyone?
Related Hardware Roomba
Related Control
EZ-Script Console
Does your code require global variables for cleft?
you are using the getvar correctly for the roomba, but not for anything else
I dont think it needs to be global. I get this output in the console: Start can't assign to function call Done (00:00:00.0316139)
I have no way to test your code (no roomba) but the indentation is totally incorrect. Now this may be because of the way you uploaded the code. Also python does not use the semi-colons at the end of each line like C does (unless ARC has it's own interpretation) and you use sleep() and time.sleep(), would you have to import time to use these? If you alter the value of setVar() inside the function you may have to declare it as global inside the function. I have altered the indentation and removed the semi-colons so this may help someone who can test the code. NB from memory ARC uses python2.
Hi Skidroe, the indentation is correct, it must have gotten that way when I did the 'past'. I will try it tomorrow. Thanks.
Again you’re using setvar incorrectly. The incorrect syntax.
If cleft does not need to be global, don’t use setvar and use a locall variable
Read python manual: https://synthiam.com/Support/python-api/python-overview
BUT, again i don't think your code requires cLeft to be a global variable. So don't bother using either setVar or getVar at all. Just use a regular python variable. setVar and getVar are for global variables that you wish to share across ARC environment.
Since you keep mentioning it, look at both setVar and getVar
proteusy, looks like the sleep() command uses milliseconds so first sleep should probably be sleep(5000)
DJ, this code is an example taken from the ARC support documentation on python navigation
Line 1: The REM statement in python is the hash sign # not the double forward slash as in c/java
Line 2: Any if command should be terminated with a colon. ie if(test):
Line 3 and 5 : Each of these lines terminate with a semicolon ? This is not python syntax.
Line 4: Same as line 2, should terminate with a colon ie else:
Just trying to clarify. Is ARC using it's own python variant or is the example incorrect?
Got it working with the while(true) instead of def (loop). I use the getVar becouse the roomba variables are global. I dont understand the semicolon usage in this python. The Movement.Left does not stop the movement after 4000ms, i must use the Movement.Stop().
Yes, the use of getvar for roomba variable is correct. It was cleft that I only mentioned