GetVariable (beta feature)#

This command returns the value of a robot variable.

For more information, see Variable management commands (beta).

Syntax#

GetVariable(name)

Arguments#

  • name: name of the variable to get (e.g., “myVar”).

Responses#

  • [2551] [name, value, cyclicId, volatile]

    • name:

      • A unique name for this variable (e.g., “myVar”);

      • Variable names are case sensitive;

      • May include several case-sensitive prefixes (e.g., “myGroup.mySubgroup.mainWrf”);

      • If the name already exists, the behavior of CreateVariable depends on the override argument.

    • value:

      • The value to assign to the variable;

      • The value can be any basic JSON type: boolean, number, string, or array (but not a JSON object). Remember that in JSON syntax, boolean values must be lowercase (i.e., true or false).

      • Examples:

        • a boolean: CreateVariable(myBoolVar, true)

        • a number: CreateVariable(myIntVar, -0.153)

        • a string: CreateVariable(myStringVar, "Hello world!")

        • an array: CreateVariable(myArrayVar, [190.0, 0.0, 308.9, 0, 90, 0])

    • cyclicId (optional, 0 by default):

      • The unique ID used to refer to this variable in cyclic protocols in the range [10000,19999] or 0;

      • When 0 (or omitted), no cyclic ID is associated with the variable;

      • If the provided cyclic ID is already in use, CreateVariable will fail with error [1552];

      • If a non-zero cyclic ID is used, the value must be a number or an array of numbers, otherwise CreateVariable will fail with error [1552].

    • volatile (optional, 0 by default):

      • Specifies whether the variable is volatile (1) or persistent (0):

        • 0: the variable is persistent and saved on the robot disk. It remains available after a reboot;

        • 1: the variable is volatile and is not saved on the robot disk. It is discarded on reboot.

  • [1551] [errorMsg]

    • errorMsg:

      • An error message explaining why the variable could not be retrieved;

      • e.g., “Variable ‘myVar’ does not exist”.

Usage restrictions#

This command can be executed in any robot state.

Cyclic protocols#

This command is not available in cyclic protocols. See Managing variables with cyclic protocols.