Using Routine Variables
Variables can be added to routines in a robot program, and then used to add complexity and define conditions for If and While statements. A routine variable is a local variable of a robot program and cannot be used by a statement in a different routine.
Add Variable
Supported types of variables (Boolean, integer, real and string) can be added to any routine in a robot program. Once a variable is added to a routine, you cannot change that variable's type.
- Click the PROGRAM tab, and the use the Jog command to select a robot.
- In the Program Editor panel, select a routine.
- In the Routine Properties panel, Add new variables list, click the type of variable you want to add to the routine.
Edit Variable
The name and value of a variable can be edited directly by accessing the properties of its routine.
- Click the PROGRAM tab, and the use the Jog command to select a robot.
- In the Program Editor panel, select a routine.
- In the Routine Properties panel, Variables table, edit the Name and Value fields of variables you want to update in the routine.
Note: When you reset a simulation, a routine variable will revert to its initial value.
Assign Value
An Assign Variable statement allows you to set the value of a robot variable, which includes routine variables. In some cases, you would assign values to variables at the start of a simulation or when a subroutine is executed in its program. In other cases, you would increment the value of variables used in a loop or subprocess of a routine.
- Click the PROGRAM tab, and the use the Jog command to select a robot.
- In the Program Editor panel, select the routine containing the variable you want to assign a value, and then add an Assign Variable statement.
- In the Statement Properties panel, do all of the following:
- Set TargetProperty to be name of the variable you want to assign a value.
- In ValueExpression, define an expression that when evaluated returns a value that can be assigned to the target variable.
Define Conditional Statement
Variables in a routine can be used to define a condition for executing If and While statements.
- Click the PROGRAM tab, and the use the Jog command to select a robot.
- In the Program Editor panel, select a routine, and then do one of the following:
- To add a conditional statement for executing one of two branches of statements, add an If statement.
- To add a conditional statement for repeating the execution of a branch of statements, add a While statement.
- In the Statement Properties panel, in Condition, define an expression that when evaluated returns a True or False value. If you need help writing the expression, press CTRL+SPACEBAR to turn on autocomplete.
Tip: The I/O ports of a robot can be used by any conditional statement in a robot program. For example, IN[100] would refer to input port 100 in a robot.