Bus
Share data with the rest of the robot through the Robot Bus: publish messages on topics and read them back, call services that robot skills, ARCx and other programs provide, look up where one frame (a camera, the robot's body) is from another, and record topics to play back later. Messages are JSON, so a script publishes plain JavaScript objects and gets objects back. The same topics and services are open to robot skills, AI assistants and programs outside ARCx (Python, JavaScript, ROS nodes through the ROS Connector), which connect to the robot's Robot Bus address when it is turned on in Options → Preferences → Robot Bus. Views → Robot Bus shows everything on the bus, live.
Bus.publish("/my_robot/status", { state: "patrolling", lap: 3 });
var pose = Bus.getLatest("/arcx/nms/pose");
if (pose != null)
print("At " + pose.x + ", " + pose.y);
var heard = Bus.waitForMessage("/arcx/speech/recognized", 10000);
if (heard != null)
Bus.call("/arcx/speech/say", { text: "You said " + heard.text });
var camera = Bus.lookupTransform("base_link", "camera"); // [x, y, z, roll, pitch, yaw]
Where to find it: type Bus. in a JavaScript script, or open the ARCx API view of the script editor and expand Bus
Commands
| Command | What it does |
|---|---|
| Bus.call | Calls a service and waits for its answer. |
| Bus.exists | Checks whether a topic exists. |
| Bus.getAge | Gets how many seconds ago the latest message on a topic was published. |
| Bus.getField | Gets one field of the latest message on a topic by its path, such as x or pose.yaw or objects.0.name. |
| Bus.getFrames | Lists every frame name in the transform tree, sorted. |
| Bus.getLatest | Gets the latest message published on a topic, as an object. |
| Bus.getRate | Gets how many messages per second a topic is receiving right now. |
| Bus.getServices | Lists the names of every service on the bus, or those a pattern matches. |
| Bus.getTopics | Lists the names of every topic on the bus, or those a pattern matches. |
| Bus.lookupTransform | Gets where one frame is as seen from another, as [x, y, z, roll, pitch, yaw] in metres and radians. |
| Bus.publish | Publishes a message on a topic. |
| Bus.setTransform | Sets where a frame is relative to its parent, such as a camera on the robot. |
| Bus.startPlayback | Plays a recording back onto the bus with its original timing. |
| Bus.startRecording | Starts recording topics to a file in ARCx Data\Recordings. |
| Bus.stopPlayback | Stops the playback, if one is running. |
| Bus.stopRecording | Stops the recording being made. |
| Bus.transformPoint | Converts a point from one frame to another, such as an object the camera sees into the robot's frame. |
| Bus.waitForMessage | Waits for the next message on a topic. |
Details
Bus.call
Calls a service and waits for its answer. Throws when the call fails or the time runs out, so the reason shows in the script console; wrap it in try and catch to carry on instead.
Bus.call(service)
Bus.call(service, args)
Bus.call(service, args, timeoutMs)
| Value | Type | What it is |
|---|---|---|
service |
string | The service name, such as /arcx/speech/say. |
args |
object | Optional. The arguments as an object, such as { text: "Hello" }. |
timeoutMs |
number | Optional. The longest to wait in milliseconds. 0 or less uses the default of 30 seconds. |
Gives back: object. What the service returned.
Bus.exists
Checks whether a topic exists.
Bus.exists(topic)
| Value | Type | What it is |
|---|---|---|
topic |
string | The topic name. |
Gives back: boolean. Whether anyone has published or advertised it.
Bus.getAge
Gets how many seconds ago the latest message on a topic was published.
Bus.getAge(topic)
| Value | Type | What it is |
|---|---|---|
topic |
string | The topic name. |
Gives back: number. The age in seconds, or -1 when nothing has been published on the topic.
Bus.getField
Gets one field of the latest message on a topic by its path, such as x or pose.yaw or objects.0.name.
Bus.getField(topic, path)
| Value | Type | What it is |
|---|---|---|
topic |
string | The topic name, such as /arcx/nms/pose. |
path |
string | The field, with dots between levels and numbers for array items. |
Gives back: object. The field's value, or null when the topic or field does not exist.
Bus.getFrames
Lists every frame name in the transform tree, sorted.
Bus.getFrames()
Gives back: string[]. The frame names.
Bus.getLatest
Gets the latest message published on a topic, as an object.
Bus.getLatest(topic)
| Value | Type | What it is |
|---|---|---|
topic |
string | The topic name, such as /arcx/nms/pose. |
Gives back: object. The message data, or null when nothing has been published on the topic.
Bus.getRate
Gets how many messages per second a topic is receiving right now.
Bus.getRate(topic)
| Value | Type | What it is |
|---|---|---|
topic |
string | The topic name. |
Gives back: number. The rate in messages per second, or 0 when it is quiet or does not exist.
Bus.getServices
Lists the names of every service on the bus, sorted, or only those a pattern matches, such as /arcx/recorder/* .
Bus.getServices()
Bus.getServices(pattern)
| Value | Type | What it is |
|---|---|---|
pattern |
string | Optional. A pattern: * matches one level, ** any number of levels. |
Gives back: string[]. The service names.
Bus.getTopics
Lists the names of every topic on the bus, sorted, or only those a pattern matches, such as /arcx/** .
Bus.getTopics()
Bus.getTopics(pattern)
| Value | Type | What it is |
|---|---|---|
pattern |
string | Optional. A pattern: * matches one level, ** any number of levels. |
Gives back: string[]. The topic names.
Bus.lookupTransform
Gets where one frame is as seen from another, as [x, y, z, roll, pitch, yaw] in metres and radians. Throws when the frames are not connected.
Bus.lookupTransform(target, sourceFrame)
| Value | Type | What it is |
|---|---|---|
target |
string | The frame to measure from, such as odom. |
sourceFrame |
string | The frame being measured, such as camera. |
Gives back: number[]. The position and rotation of sourceFrame in target.
Bus.publish
Publishes a message on a topic. Every robot skill, script and external program subscribed to the topic receives it, and it becomes the topic's latest message. Naming the type tells others what fields to expect.
Bus.publish(topic, data)
Bus.publish(topic, data, type)
| Value | Type | What it is |
|---|---|---|
topic |
string | The topic name, such as /my_robot/status. |
data |
object | What to publish: an object, an array, a number or text. |
type |
string | Optional. The message type, such as my_robot/Status. |
Bus.setTransform
Sets where a frame is relative to its parent, such as a camera on the robot, and optionally whether it is fixed (bolted down) or moving. Metres and radians, +X forward, +Y left, +Z up.
Bus.setTransform(parent, child, x, y, z, roll, pitch, yaw)
Bus.setTransform(parent, child, x, y, z, roll, pitch, yaw, isStatic)
| Value | Type | What it is |
|---|---|---|
parent |
string | The parent frame, such as base_link. |
child |
string | The frame being placed, such as camera. |
x |
number | Metres forward of the parent. |
y |
number | Metres left of the parent. |
z |
number | Metres above the parent. |
roll |
number | Rotation about the forward axis in radians. |
pitch |
number | Rotation about the left axis in radians; positive tilts down. |
yaw |
number | Rotation about the up axis in radians; positive turns left. |
isStatic |
boolean | Optional. True for something that never moves relative to its parent. |
Bus.startPlayback
Plays a recording back onto the bus with its original timing, or faster or slower.
Bus.startPlayback(name)
Bus.startPlayback(name, speed)
| Value | Type | What it is |
|---|---|---|
name |
string | The recording's name. |
speed |
number | Optional. 1 is real time, 2 twice as fast, 0.5 half speed. |
Bus.startRecording
Starts recording topics to a file in ARCx Data\Recordings. Use ** to record everything.
Bus.startRecording(topics)
| Value | Type | What it is |
|---|---|---|
topics |
string | A topic or pattern, or several separated by commas, such as /arcx/nms/,/arcx/vision/ . |
Gives back: string. The recording's name.
Bus.stopPlayback
Stops the playback, if one is running.
Bus.stopPlayback()
Bus.stopRecording
Stops the recording being made.
Bus.stopRecording()
Gives back: number. How many messages were recorded, or 0 when nothing was recording.
Bus.transformPoint
Converts a point from one frame to another, such as an object the camera sees into the robot's frame. Throws when the frames are not connected.
Bus.transformPoint(target, sourceFrame, x, y, z)
| Value | Type | What it is |
|---|---|---|
target |
string | The frame to convert into, such as base_link. |
sourceFrame |
string | The frame the point is in, such as camera. |
x |
number | The point's X in sourceFrame, metres. |
y |
number | The point's Y in sourceFrame, metres. |
z |
number | The point's Z in sourceFrame, metres. |
Gives back: number[]. The point in the target frame as [x, y, z].
Bus.waitForMessage
Waits for the next message on a topic, with no time limit or until the time limit passes.
Bus.waitForMessage(topic)
Bus.waitForMessage(topic, timeoutMs)
| Value | Type | What it is |
|---|---|---|
topic |
string | The topic name, or a pattern such as /arcx/vision/** . |
timeoutMs |
number | Optional. The longest to wait in milliseconds. 0 or less waits with no limit. |
Gives back: object. The message data, or null when the time ran out.