Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_DDS/README.md
Views: 1798
Testing with DDS/micro-Ros
Architecture
Ardupilot contains the DDS Client library, which can run as SITL. Then, the DDS application runs a ROS 2 node, an eProsima Integration Service, and the MicroXRCE Agent. The two systems communicate over serial or UDP.
Installing Build Dependencies
While DDS support in Ardupilot is mostly through git submodules, another tool needs to be available on your system: Micro XRCE DDS Gen.
Follow the wiki here to set up your environment.
Serial Only: Set up serial for SITL with DDS
On Linux, creating a virtual serial port will be necessary to use serial in SITL, because of that install socat.
Setup ardupilot for SITL with DDS
Set up your SITL. Run the simulator with the following command. If using UDP, the only parameter you need to set it DDS_ENABLE
.
Name | Description | Default |
---|---|---|
DDS_ENABLE | Set to 1 to enable DDS, or 0 to disable | 1 |
SERIAL1_BAUD | The serial baud rate for DDS | 57 |
SERIAL1_PROTOCOL | Set this to 45 to use DDS on the serial port | 0 |
DDS is currently enabled by default, if it's part of the build. To disable it, run the following and reboot the simulator.
Setup ROS 2 and micro-ROS
Follow the steps to use the microROS Agent
Install ROS Humble (as described here)
Install geographic_msgs
Install and run the microROS agent (as described here). Make sure to use the
humble
branch.Follow the instructions for the following:
Do "Installing ROS 2 and the micro-ROS build system"
Skip the docker run command, build it locally instead
Skip "Creating a new firmware workspace"
Skip "Building the firmware"
Do "Creating the micro-ROS agent"
Source your ROS workspace
Using the ROS 2 CLI to Read Ardupilot Data
After your setups are complete, do the following:
Source the ROS 2 installation
Next, follow the associated section for your chosen transport, and finally you can use the ROS 2 CLI.
UDP (recommended for SITL)
Run the microROS agent
Run SITL (remember to kill any terminals running ardupilot SITL beforehand)
Serial
Start a virtual serial port with socat. Take note of the two
/dev/pts/*
ports. If yours are different, substitute as needed.Run the microROS agent
Run SITL (remember to kill any terminals running ardupilot SITL beforehand)
Use ROS 2 CLI
You should be able to see the agent here and view the data output.
The static transforms for enabled sensors are also published, and can be received like so:
In order to consume the transforms, it's highly recommended to create and run a transform broadcaster in ROS 2.
Using ROS 2 services
The AP_DDS
library exposes services which are automatically mapped to ROS 2 services using appropriate naming conventions for topics and message and service types. An earlier version of AP_DDS
required the use of the eProsima Integration Service to map the request / reply topics from DDS to ROS 2, but this is no longer required.
List the available services:
Call the arm motors service:
Call the mode switch service:
Call the prearm check service:
Call the takeoff service:
Commanding using ROS 2 Topics
The following topic can be used to control the vehicle.
/ap/joy
(typesensor_msgs/msg/Joy
): overrides a maximum of 8 RC channels, at least 4 axes must be sent. Values are clamped between -1.0 and 1.0. UseNaN
to disable the override of a single channel. A channel defaults back to RC after 1 second of not receiving commands.
/ap/cmd_gps_pose
(typeardupilot_msgs/msg/GlobalPosition
): sends a waypoint to head to when the selected mode is GUIDED.
Contributing to AP_DDS
library
Adding DDS messages to Ardupilot
Unlike the use of ROS 2 .msg
files, since Ardupilot supports native DDS, the message files follow OMG IDL DDS v4.2. This package is intended to work with any .idl
file complying with those extensions.
Over time, these restrictions will ideally go away.
To get a new IDL file from ROS 2, follow this process:
If the message is custom for ardupilot, first create the ROS message in Tools/ros2/ardupilot_msgs/msg/GlobalPosition.msg
. Then, build ardupilot_msgs with colcon. Finally, copy the IDL folder from the install directory into the source tree.
Rules for adding topics and services
Topics and services available from AP_DDS
are automatically mapped into ROS 2 provided a few rules are followed when defining the entries in the topic and service tables.
ROS 2 message and service interface types
ROS 2 message and interface definitions are mangled by the rosidl_adapter
when mapping from ROS 2 to DDS to avoid naming conflicts in the C/C++ libraries. The ROS 2 object namespace::Struct
is mangled to namespace::dds_::Struct_
for DDS. The table below provides some example mappings:
ROS 2 | DDS |
---|---|
rosgraph_msgs::msg::Clock | rosgraph_msgs::msg::dds_::Clock_ |
sensor_msgs::msg::NavSatFix | sensor_msgs::msg::dds_::NavSatFix_ |
ardupilot_msgs::srv::ArmMotors_Request | ardupilot_msgs::srv::dds_::ArmMotors_Request_ |
ardupilot_msgs::srv::ArmMotors_Response | ardupilot_msgs::srv::dds_::ArmMotors_Response_ |
Note that a service interface always requires a Request / Response pair.
ROS 2 topic and service names
The ROS 2 design article: Topic and Service name mapping to DDS describes the mapping of ROS 2 topic and service names to DDS. Each ROS 2 subsystem is provided a prefix when mapped to DDS. The request / response pair for services require an additional suffix.
ROS 2 subsystem | DDS Prefix | DDS Suffix |
---|---|---|
topics | rt/ | |
service request | rq/ | Request |
service response | rr/ | Reply |
service | rs/ | |
parameter | rp/ | |
action | ra/ |
The table below provides example mappings for topics and services
ROS 2 | DDS |
---|---|
ap/clock | rt/ap/clock |
ap/navsat | rt/ap/navsat |
ap/arm_motors | rq/ap/arm_motorsRequest, rr/ap/arm_motorsReply |
Refer to existing mappings in AP_DDS_Topic_Table
and AP_DDS_Service_Table
for additional details.
Development Requirements
Astyle is used to format the C++ code in AP_DDS. This is required for CI to pass the build. To run the automated formatter, run:
Pre-commit is used for other things like formatting python and XML code. This will run the tools automatically when you commit. If there are changes, just add them back your staging index and commit again.
Install pre-commit python package.
Install ArduPilot's hooks in the root of the repo, then commit like normal
Testing DDS on Hardware
With Serial
The easiest way to test DDS is to make use of some boards providing two serial interfaces over USB such as the Pixhawk 6X. The Pixhawk6X/hwdef.dat file has this info.
For example, build, flash, and set up OTG2 for DDS
Then run the Micro ROS agent
If connection fails, instead of running the Micro ROS agent, debug the stream
The same steps can be done for physical serial ports once the above works to isolate software and hardware issues.