ROS 2 topics¶
xparo_ros talks to the rest of your robot through ordinary ROS 2
topics. Any node on the robot can use them, and so can you from a terminal,
with no XPARO-specific code.
Every command on this page was run against a live robot. Open a terminal on the robot and source your workspace first:
source /opt/ros/jazzy/setup.bash
source ~/xparo_ws/install/setup.bash
At a glance¶
Topic and type |
Direction |
Use it to |
|---|---|---|
|
in |
Ask the project’s AI assistant a question. |
|
out |
Read the assistant’s answers and other server messages (JSON). |
|
in |
Run a task on this robot without the dashboard. |
|
out |
Get the result of every task run on this robot (JSON). |
|
in |
Save your own record in the project’s task history. |
|
in |
Show live node states from your own behaviour tree executor on the dashboard. |
|
in |
Nav2’s behaviour tree log, forwarded to the dashboard automatically.
Only subscribed when |
|
out |
Receive the dashboard’s Teleop controls. |
|
in and out |
Report health to the dashboard; XPARO also publishes its own status. |
|
in |
ERROR and FATAL log lines from every node are collected for the dashboard’s Health & Errors view. |
|
in |
Start or stop ROS bag recording. |
|
out |
Current recording state. |
|
out |
Whether a ROS bag recorder is running. |
See it for yourself:
ros2 node list # /xparo_ros with the launch file, /xparo with ros2 run
ros2 node info /xparo_ros # every topic above, plus the recorder service clients
Ask the AI assistant¶
Publish a question on /xparo/ask and read the answer on
/xparo/response. It is the same assistant as the dashboard’s Ask
here…. bar and answers on the project’s LLM keys, the built-in XPARO free
key included (see The AI assistant).
# terminal 1: watch for the answer
ros2 topic echo /xparo/response
# terminal 2: ask
ros2 topic pub --once /xparo/ask std_msgs/msg/String "data: 'what can you do'"
The answer arrives as JSON inside a message object. When the project has
no usable key (all switched off, suspended or deleted) it looks like this:
data: '{"message": {"bot_response": "No valid API keys available. Please add or check key statuses.", "responded_by": "llm"}}'
Note
xparo_ros converts the question to upper case before sending it. The
question is also saved in the project’s Prompts database, linked to
this robot.
/xparo/response also carries other messages from the server that
xparo_ros does not handle itself, for example a copy of the project sync
when the robot connects. Check for the message key when you only want
answers.
Run a task from the robot¶
Every task in the project is synced to the robot whenever it connects and
whenever a task is added, edited, copied or deleted. Publishing a task’s ID on
/xparo/run_task runs it right here: the robot builds the tree and its
input values from its own copy, so no server round trip is needed to
start it, and it even works while the robot is offline. The result is still
reported to the dashboard (straight away, or when the connection is back).
To find the task ID, open the task (its row’s … menu, then Edit) and
go to the Task Overview tab. Under Run it on the robot (recommended)
is the command below with the task’s real ID (a long code such as
1497bd47-3553-446c-b72d-92b6db027dcd) already filled in: copy it from
there. The name in the badge of the Title column
(my-project::ward-delivery) is not the task ID; the robot answers it with
unknown_task.
# terminal 1: watch results
ros2 topic echo --full-length /xparo/task_result
# terminal 2: run it
ros2 topic pub --once /xparo/run_task std_msgs/msg/String \
"data: '{\"task_id\": \"<task-id>\", \"override_params\": {\"destination\": \"ward_3\"}}'"
override_params is optional. Its keys are the names of the task’s
params (the ones you added under Params in the task form); anything you
leave out uses that param’s default. A key that is not one of the task’s
params is ignored, and the result names it (ignored_override_params, and
a sentence in explanation).
A task the robot has not synced yet (created while it was offline) finishes
immediately with the outcome unknown_task:
data: '{"task_id": "does-not-exist", "run_id": null, "success": false, "duration_s": 0.0, "outcome": "unknown_task", "retryable": false, ...}'
The stage rule still applies: the task’s stage must be one this robot’s
xparo_stage accepts, or the result is stage_mismatch.
Several robots on one network¶
ROS 2 topics reach every robot in the same ROS_DOMAIN_ID (default 0).
Two robots in one restaurant on the default domain would both run a
/xparo/run_task message. Give each robot its own ROS_DOMAIN_ID (any
number from 0 to 101, set in the environment before ros2 launch), and/or
name the robot in the message. A robot ignores a message that names another
robot (by its device id or hostname):
ros2 topic pub --once /xparo/run_task std_msgs/msg/String \
"data: '{\"task_id\": \"<task-id>\", \"robot\": \"<device-id or hostname>\"}'"
The same task can’t run twice at once on one robot: a second request while
it runs (for example a double tap on a kiosk) finishes straight away with the
outcome busy and nothing moves. Send "allow_parallel": true to run
another copy on purpose.
Note
For runs started on the robot, inputs mapped From env are read from the
environment files synced to custom_envs/custom_maps/. If one of them
can’t be filled (the environment or the variable isn’t on the robot yet),
the run doesn’t start: it finishes at once with the outcome
invalid_request and an error naming the input. A mapping for an input
the tree no longer uses is ignored, with one warning in the robot’s log.
Stopping a task¶
There is no ROS topic that stops a task, and none that asks the AI to pick
one. A run stops when its tree finishes, when it hits its time limit
(outcome timeout), or when someone presses Cancel on the dashboard
(outcome cancelled, see Tasks (Step 2)). The task’s Task
Overview tab shows Cancel for a run that started while the tab was open,
and the robot must be connected.
A stop button on the robot has to stop the motors through your own nodes. To
end the run as well, make the tree check the button: a custom condition node
(Custom nodes) that fails while it’s pressed, as the first child of a
ReactiveSequence, ends the run at once with outcome failed.
Task results¶
/xparo/task_result gets one JSON message at the end of every task run on
this robot, however it was started (Run now, Auto launch, or
/xparo/run_task). The fields are described in Run results. The
node also writes a line to its log when a task starts and when it ends:
[INFO] [xparo_ros]: Task 'Deliver medicine' started (run 423eee8ceb45, trigger run_now, time limit 120s)
[INFO] [xparo_ros]: Task 'Deliver medicine' finished: SUCCESS in 11.8s (run 423eee8ceb45)
The trigger is run_now for the dashboard’s Run now, ros_topic for
/xparo/run_task, auto_launch for Auto launch tasks and
restart_on_failure for a retry.
A message for people¶
explanation is written for engineers (“The tree finished with FAILURE at
fail_table_unknown (AlwaysFailure) …”). For the person at the robot, such as
restaurant staff on a kiosk or the client’s dashboard, set the
user_message blackboard key in the tree before it fails. It comes back
as user_message in the task result and in the task history (empty when
not set):
<Fallback>
<CheckTableOnMap location="{table_key}" env_file="{env_file}"/>
<Sequence>
<SetBlackboard output_key="user_message"
value="This table is not on this outlet's map. Please serve it by hand."/>
<AlwaysFailure name="table_not_on_map"/>
</Sequence>
</Fallback>
A custom node can write it too: self.blackboard["user_message"] = "…".
Save your own task history¶
Anything published on /xparo/task_updates is saved as a row in the
project’s Tasks database, linked to this robot. Use it to record work
your own nodes do.
ros2 topic pub --once /xparo/task_updates std_msgs/msg/String \
"data: '{\"type\": \"door_check\", \"input_data\": {\"door\": \"ward-3\"}, \"output_data\": {\"status\": \"closed\"}}'"
All fields are optional: type (default generic_task), input_data
and output_data (any JSON objects) and created_at (ISO time; default
now). If the connection is down, the record waits in memory and is sent when
the robot reconnects (it is lost if xparo_ros is restarted first).
Show your own behaviour tree live¶
If you run behaviour trees with your own executor, publish each node’s state
change on /bt_xparo_log and the Behaviour page lights up the node with the
same name, just like it does for XPARO’s own engine.
ros2 topic pub --once /bt_xparo_log std_msgs/msg/String \
"data: '{\"node_name\": \"check_door\", \"node_type\": \"Script\", \"prev\": \"RUNNING\", \"curr\": \"SUCCESS\"}'"
Fields: node_name (match it to the node’s name attribute in the
tree), node_type, prev and curr (IDLE, RUNNING,
SUCCESS, FAILURE), and optionally uid, timestamp and
datetime.
Nav2 users get this for free: when nav2_msgs is installed, xparo_ros
subscribes to Nav2’s /behavior_tree_log and forwards every event the same
way.
Teleop drives /joy¶
When someone uses Teleop on the Robots Fleet page, xparo_ros
publishes the gamepad or keyboard input as sensor_msgs/Joy on /joy,
with at least 4 axes and 3 buttons. Point your motor controller (for example
teleop_twist_joy) at /joy and the dashboard drives the robot.
ros2 topic echo /joy
Health: /diagnostics and /rosout¶
The dashboard’s Health & Errors view is built from two standard topics:
every
diagnostic_msgs/DiagnosticArraypublished on/diagnosticsby any node (warnings and errors become problems on the dashboard), andevery ERROR or FATAL line logged by any node (
/rosout).
So the usual ROS 2 ways of reporting health just work. xparo_ros also
publishes its own status on /diagnostics once per second:
Status name |
Meaning |
|---|---|
|
|
|
Recording state, |
|
|
|
Warning from 85 % full, error from 95 %. |
ros2 topic echo --once /diagnostics
ROS bag recording¶
ros2 topic pub --once /ros2_bag_control std_msgs/msg/String "data: 'start'"
ros2 topic pub --once /ros2_bag_control std_msgs/msg/String "data: 'stop'"
ros2 topic pub --once /ros2_bag_control std_msgs/msg/String "data: 'status'"
ros2 topic echo /ros2_bag_control/recording_status
See ROS bag recording for how recording works.