Portugal
Asked — Edited

Adding Values To Variable

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

ARC Pro

Upgrade to ARC Pro

With ARC Pro, your robot is not just a machine; it's your creative partner in the journey of technological exploration.

PRO
Synthiam
#1  

Does your code require global variables for cleft?

you are using the getvar correctly for the roomba, but not for anything else

PRO
Portugal
#2  

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)

England
#3   — 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()
     sleep(1)
loop()
loop()

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.

PRO
Portugal
#4  

Hi Skidroe, the indentation is correct, it must have gotten that way when I did the 'past'. I will try it tomorrow. Thanks.

PRO
Synthiam
#5  

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

PRO
Synthiam
#6   — Edited

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

User-inserted image

England
#7  

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

// Pause navigating if the ping sensor detects an object less than 100 distance and continue if greater
if (Ping.get(d0, d0) < 100)
  Navigation.SetNavigationStatusToPause();
else
  Navigation.SetNavigationStatusToNavigating();

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?

PRO
Portugal
#8  
import time
ab = 0
while(True):

  if getVar("$RoombaLightBumperCenterLeft")==1:
     Navigation.SetNavigationStatusToPause();
     print "Bumper Center Left";
     ab += 1;
     print ab
  
  if ab == 2:
     Movement.Left(10,4000);
     Movement.Stop();
     ab = 0;
     print ab
     
  else:
     Navigation.SetNavigationStatusToNavigating();
     time.sleep(1);
 

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().

PRO
Synthiam
#9  

Yes, the use of getvar for roomba variable is correct. It was cleft that I only mentioned