
proteusy
I dont get this python. I am trying to add 1 to the variable "CLeft" but my code does not work. Anyone?Code:
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();
you are using the getvar correctly for the roomba, but not for anything else
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.Code:
If cleft does not need to be global, don’t use setvar and use a locall variable
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
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/javaCode:
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).Code:
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().