Skip to main content

ROS2

The ROS2 plugin connects the ROS2 network on your ROS2-based robot to the Rocos platform. In order to use the ROS plugin, it is required to be installed separately beside the rocos-agent. Subsequently, the ROS2 plugin will appear as a ROS2 node to other ROS2 components on your robot.

The ROS plugin is bidirectional; it can both subscribe to ROS messages and send them upstream to the DroneDeploy's Ground Robotics (DDGR) platform, as well as receive downstream messages from the DDGR platform and publish them into the ROS network.

Installing The Plugin

Currently, the plugin is only available for Linux systems. A rocos-agent version of v1.6.9 and above is required for running the ros2 plugins. If the rocos-agent is installed via apt, then the plugin installation steps are:

sudo apt-get update
sudo apt install rocos-agent-plugin-ros2-$ROS_DISTRO

Where $ROS_DISTRO could be eloquent, foxy, galactic, or humble. The Debian packages are available for amd46 and arm64 architectures.

Data Model

The data model for the message sent and received by the ROS2 plugin is determined by the ROS2 message topics used on the ROS2 network to which the plugin is connected.

Receiving (Upstream) Messages

In order to send ROS messages to your robot, the ROS2 plugin needs to understand the dialect of the ROS messages being used. In order to do this, the ROS2 plugin needs access to the shared object files which are built for each ROS package, and contain all the necessary code to read/write the ROS messages which are defined by that package. You will need to configure the ROS2 plugin with the location of these files by setting the LD_LIBRARY_PATH env variable as described in the Configuration section.

The ROS2 plugin searches for message files once each time that it starts up; if you change or create a message file while the Agent is running, you will need to disable and then re-enable the ROS2 plugin so that it searches for new messages.

The ROS2 plugin will automatically discover the topics being published on the connected ROS2 network and expose them as data URIs that you can read data from. The content of ROS messages is automatically converted into a JSON representation to allow access and binding to individual message fields.

Once the message files have been discovered by the Agent, then when ROS message topics become available (i.e. when a ROS node begins advertising a topic) the topic, and the fields contained therein, will become visible in the data picker:

ROS messages received automatically have two pieces of metadata applied:

Metadata FieldDescriptionExample
ros.typeThe ROS message type of the original message."geometry_msgs/Twist"
ros.nodeThe name of the ROS node which published the message."sensor1"

Sending (Downstream) Messages

In order to send ROS messages to your robot, the ROS2 plugin needs to understand the dialect of the ROS messages being used. In order to do this, the ROS2 plugin needs access to the shared object files. You will need to configure the ROS plugin with the location of these files by setting the LD_LIBRARY_PATH env variable as described in the Configuration section.

The ROS plugin needs to know the ROS message type for each downstream message being sent. You should include this information in the Metadata field for each control message, for example:

{
"ros.type": "geometry_msgs/Twist"
}

The ROS2 plug needs the contents of each downstream message being sent, in the Payload Template field, to be structured in a particular JSON representation. For example, the contents of the geometry_msgs/PoseStamped message might look like:

{
"header":{
"stamp": {
"secs": 0,
"nsecs": 0
},
"frame_id": "map",
"seq": 1
},
"pose":{
"position": {
"x": 1,
"y": 2,
"z": 3
},
"orientation": {
"x": 0,
"y": 0,
"z": 0,
"w": 1
}
}
}

Configuration

To use the ROS2 plugin, your agent will need a section in its agent-settings.json file which enables the ros2 component, as shown below. For more information on how to configure the agent plugins, see Agent Configuration.

...
"components": [
...
{
"enabled": true,
"id": "plugin",
"settings": {
"logLevel": 4,
"name": "plugin_ros",
"envVariables": {
"LD_LIBRARY_PATH": "/home/ros_ws/install/velodyne_msgs/lib:/opt/ros/humble/lib/aarch64-linux-gnu:/opt/ros/humble/lib",
"RMW_IMPLEMENTATION": "rmw_cyclonedds_cpp",
},
"plugin": "/opt/rocos-agent/bin/rocos-agent-plugin-ros2",
"delayNewPubs": 200
}
},
...
]

The ROS plugin understands the following configuration parameters:

NameDescriptionUnitDefault
enabledWhether to enable the ROS plugin or not.false
nameHow this instance of the ROS plugin should be named.
logLevelThe logging verbosity: 1 - very quiet, 6 - very talkative.4
pluginThe path to the plugin executable. If installed via apt it should be /opt/rocos-agent/bin/rocos-agent-plugin-ros2
envVariablesAny environment variables pair to send to plugin executable such as LD_LIBRARY_PATH, RMW_IMPLEMENTATION or ROS_DOMAIN_ID(if applicable).
ROS_NAMESPACEAllows pushing the ROS plugin's node down into a namespace.
pollingPeriodHow frequently the ROS plugin should look for any new ROS topics which are available to subscribe to.ms2000
keepOldTopicsWhether topics which no longer have any ROS publishers should continue to be listed as available or not.false
publisherLifetimeWhen the ROS plugin publishes a downstream message from the platform, a ROS publisher is created and advertised by the ROS plugin's node. This setting determines how long that publisher should continue to be advertised after each downstream message. If set to a non-positive value, then the plugin's ROS publishers will never expire.s300
delayNewPubsWhen the ROS plugin publishes a downstream message from the platform, a ROS publisher is created and advertised by the ROS plugin's node. This setting determines how long the ROS plugin should wait between creating the publisher and transmitting the first message. Allowing a short delay here may help other ROS nodes from missing the published message if they are slow at subscribing.ms0