Syntax and Operations
Here we briefly describe its syntax and operations.- Constants includes numbers in decimal notation, strings enclosed in single or double quotes, the boolean values
falseandtrueandnull. - Arithmetic and logical operations include
+,-,*(multiplication),/(division),%(remainder),^(exponentiation) as well asnot,and,or(boolean operators). - Comparison includes
==,!==,>=,<=,>and<(equals, not equals, etc.) - All sub-expressions can be grouped using parenthesis
(and)to make precedence explicit. - Arrays (list of values) are accessed through subscript operator
[], e.g.a[3]. They can be concatenated with||. - Functions calls are denoted using their name, followed by parenthesis with optionally argument values separated by commas. For example,
minValue("battery", 30). - Variables can be assigned with
=to reuse values; and these assignments are separated using the;delimiter. For examplex=3; y=4; sqrt(x*x + y*y).
(...): groupingf(),a[i]: Function calls, array indexing (left-associative)^: Exponentiation (right-associative)+,-,not,sqrtunary operators (full list below)*,/,%: Product, division and remainder+,-,||: Addition and subtraction (arithmetic) and concatenation (strings and lists)==,!=,>=,<=,>,<,in: Comparison operators and inclusion operator (x in ameans “is elementxincluded in lista)and: Logical ANDor: Logical ORx ? y : z: Ternary conditional: ifxthenyelsez.=: Variable assignment;: Expression separator
Unary Operators
The unary operators include in addition to+ and - (sign), many algebra and trigonometry functions:
abs(absolute value)ceil,sign,round,trunc(sign, rounding and truncation)sqrtandcbrt(square and cubic root)ln,log10,log2(logarithms)sin,cos,tan,tanh,asin,acos,atan,atanh(trigonometric functions)length(array length)
acos(x).
Robot-Specific Functions
Additionally, robot-specific functions allow evaluating conditions on robot-reported data:Language Functions
get(<value>, <field>, <defaultValue>): Given an object, it returns the value of one of its fields. Normally used for robot attributes of type “JSON”. If<value>is not an object, or it does not contain the given<field>, it returns<defaultValue>(which is optional, when omitted it is assumed to benull).
Robot Data Functions
-
getValue(<ds>): The current value of the robot data source identified by<ds>. -
getValueAgeMs(<ds>): The age of the robot data source identified by<ds>in milliseconds; defined as the time that has passed since this data source value was last sent by the robot. -
minValue(<ds>, <secs>),maxValue(<ds>, <secs>),meanValue(<ds>, <secs>): Aggregation operators to obtain the minimum (resp. maximum, average) value of the data source identified by<ds>during the last N seconds. -
hasTag(<tag>): Determines if a robot contains a tag (tags are labels applied to robots for filtering and organization) -
distinctValues(<ds>, <seconds>)andsustainedValue(<ds>, <seconds>): Determine all unique values of a given source<ds>for the last<seconds>time window. The functiondistinctValuesreturns all these values in a list (see array operators above). The functionsustainedValuecan be used to know if the data source has reported one unique value over that time: in that case it returns this value; otherwise it returnsnull.
Both functions require enabling storage of values history. Refer to
DataSourceDefinition in StatusDefinitions.Localization Data Functions
-
visitedAreaDiagonal(<seconds>): The diagonal length of the smallest bounding box containing all of the robot positions during the last N seconds. It allows determining if the robot is actually moving; beyond its linear or angular distance (e.g. the robot can be moving in circles attempting to go around an obstacle). -
visitedAreaSide(<seconds>): Similar tovisitedAreaDiagonal, except it reports the largest side of the smallest bounding box containing all of the robot positions during the last N seconds. -
match(<regularExpression>, <variable>): Performs regular expression matching. The result isnullif there is no match, or a list of strings when matched (which can also be used as “true” value for a boolean expression). This list contains the entire match as first element, and any captured groups as subsequent elements. Regular expressions follow ECMASCRIPT language specification, refer to this cheatsheet. Character classes, grouping and other regular expression features are supported. -
inRectangleArea(x0, y0, x1, y1, frameId): Returns a boolean value indicating if the robot current pose lies within the rectangle determined by any two opposite corners(x0, y0)and(x1, y1). The function is only calculated if the robot reports a pose, and the givenframeIdmatches. The last argumentframeIdis optional, and the coordinates would match the robot pose from any coordinate frame (this is not recommended, but it makes testing easier when only one frame is in use). This function can be used to define simple rules based on robots position in a map, such as no-go or exclusion zones.
Traffic Management Functions
When using Traffic Management, expressions can use functions to query about the state ofTrafficZones.
-
isRobotInZone(<zoneId>, [<locationId>]): Determines if the current robot (where the expression is being evaluated) is currently inside the zonezoneId. This identifier is normally sufficient to identify the zone, which must be defined in the robot’s current location. Optionally thelocationId(a tag) can also be provided. As some expressions (e.g. in Mission Definitions or Zone Events) can be evaluated in arbitrary robots, this function can also be used to ask if any robot is currently inside a configured zone. -
isZoneOccupied(<zoneId>, [<locationId>]): Tells if there is currently at least one robot in a given zone. The zone is identified in the same way as inisRobotInZone. For example, a mission step mightwaitUntila zone becomes empty (for example to drop some cargo or to move on a narrow area).
Examples
The following examples assume some data sources and tags exist for the robots; the data source ids are given as example and should be self-explanatory.
ABOVE or BELOW rules in a StatusDefinition.
{ sustainedForSeconds: 180 }, it would trigger if the robot has not docked after three minutes of changing its program to "DOCKING"
"motorTemperatureId". The ‘StatusDefinition’ example below shows how absent motor temperature readings could generate an alert after 120 seconds:
event JSON object attribute, if the robot is seeing one of the configured landmarks, this expression would take a "lobby" value, if not it default to the "current_floor" data source instead. Note that the expression works in multiple lines or a single line.