3.2 Application and global Logic Program Variables
This section describes the topics and services used to read and modify application (shared) variables, and to receive variable updates.
The topics and services described here are listed together with the other topics and services in Topics and Services.
3.2.1 Variable data format
All variable data is exchanged as a JSON string, wrapped in a VariableUpdate message. The message has a header field with the timestamp of the update, and a data.json_string.data field with the JSON string.
A variable update has the following structure:
{
"update_type": "full",
"shared_variables": {
"counter": 123,
"name": "abc",
"temperature": 33.334455,
"waypoint": {"_ur_pose": [0.1, 0.5, 0, 3.14, 0, 0]}
}
}
Key |
Description |
|---|---|
|
|
|
The shared (application) variables as |
|
The global variables of the logic programs, see global_variable_update |
Variable values are encoded as follows:
URScript type |
JSON representation |
|---|---|
int |
Number without a decimal point (signed 32 bit) |
float |
Number with a decimal point |
bool |
|
string |
String |
list |
Array, e.g. |
list with capacity |
|
pose |
|
3.2.3 global_variable_update topic
Topic that publishes changes of the global variables of the logic programs. A message is published when the global variables of a logic program change, and when a logic program is started or stopped.
The data.json_string.data field of the message contains the JSON variable update. The variables are grouped by logic program name under the global_variables key:
{
"update_type": "diff",
"global_variables": {
"logic_program_id": 1,
"my_program": {"global2": 5, "global4": 7}
}
}
Key |
Description |
|---|---|
|
Id of the logic program the update belongs to |
|
The global variables of that logic program as |
When a logic program is started, an initial full update is published in which the variables that are not yet assigned have the value null.
3.2.5 get_variables service
Service that returns the current values of all variables as a full update (update_type is full).
Note
There must be at least 500 ms between two calls of this service. Use it only to get the initial state, for example in clients that join late. To follow later changes, subscribe to the shared_variable_update and global_variable_update topics instead. Polling this service continuously puts a high load on the system, and one client that calls it too often can starve all other clients.
Request
The request is empty.
Response
Field |
Description |
|---|---|
|
Timestamp of the update |
|
JSON variable update with all variables |
If the variables cannot be read, json_string.data contains a JSON error description instead, for example {"error" : "Too many requests made"} when the minimum interval between calls was not kept.
Example:
ros2 service call /UR20225300015/get_variables urinterfaces/srv/VariablesViewer "{}"