arrow-left

All pages
gitbookPowered by GitBook
1 of 3

Loading...

Loading...

Loading...

MicroDDS Agent/MicroROS

hashtag
Introduction

circle-check

The following was user contributed content and edited by NXP. Note that there are several methods available for communication between ROS and PX4. This documents an established method.

hashtag
Setting up the MicroDDS Agent/MicroROS

One method used to communicate between the NavQPlus and the FMUK66v3 using T1 or Serial is by using MicroROS or the XRCE-dds Agent. To install these tools:

If using yocto, you can use the WIP meta package in your recipe.

Alternatively, you can install micro-ROS through the ubuntu snap store

Another way to get micro-ROS is through Github as a ROS2 package. You can use the colcon build tools after sourcing the ROS setup.bash script in "/opt/ros/galactic/setup.bash"

Follow the instructions for each package on how to run the agent. The agent is a broker for clients on the network (including the FMUK66) and allows topics from the pixhawk to be shared with the DDS global space.

To set up the NavQ+, follow instructions in the Setup Guide -eMMC for a static IP. The FMUK66 is IP "10.0.0.1". As an example, you can set the NavQ+ to "10.0.0.3" with a blank ipv4.gateway (no quotes or anything) on Wired Connection 1.

Then start the microdds agent that is installed in the home directory in the Micro-XRCE-DDS-Agent build folder.

On the FMUK66, ensure you have flashed to main and enter the following command.

You should see the topic listed in the mavlink console after running the client start, as well as topic, publishers, data writers, and creators on the agent side.

git clone https://github.com/eProsima/Micro-XRCE-DDS-Agent
cd Micro-XRCE-DDS-Agent
mkdir build && cd build
cmake ..
make
sudo make install
https://github.com/dirksavage88/meta-dds
colcon build --symlink-install
./MicroXRCEAgent udp4 -p 2019
microdds_client start -t udp -h 10.0.0.3 -p 2019

ROS2

circle-info

If using an downloaded image, check first that these packages are not already installed.

circle-check

See MR-B3RB for an already pre-configures ROS2 installation. This is the preferred method.

hashtag
Installing ROS2 on the NavQPlus

We have prepared an install script that will install ROS2 and all necessary packages on the NavQPlus.

To get the install script and run it, you can run the following in the terminal:

ROS2 example

A simple ROS2 example

hashtag
Introduction

This page will go through a simple example using ROS on the NavQPlus. More examples and details can be found on the ROS webpage linked bellow. This example is a shortened version of the Publisher Subscriber for Python tutorial. You will need to have ROS2 installed already before trying this example.

wget https://raw.githubusercontent.com/rudislabs/nxp_install/main/install.sh
chmod +x install.sh
./install.sh
hashtag
ROS2 Publisher Subscriber in Python example

In this tutorial, you will create nodesarrow-up-right that pass information in the form of string messages to each other over a topicarrow-up-right. The example used here is a simple “talker” and “listener” system; one node publishes data and the other subscribes to the topic so it can receive that data.

hashtag
Step 1 - Create workspace

First step is to make a workspacearrow-up-right for your project to build in. Go to your home folder and create a workspace called /ros2_ws. With another directory inside /src for your project to be in.

Then move into the /src directory:

hashtag
Step 2 - Create package

Now we want to create a package inside the directory we just created.

Your terminal will return a message verifying the creation of your package py_pubsub and all its necessary files and folders.

hashtag
Step 3 - Publisher code

Navigate to the new directory location created.

Now download the example publisher code:

You should now see a new file located in the py_pubsub directory. To understand more about the code, follow the tutorial through the ROS webpagearrow-up-right.

hashtag
Step 4 - Subscriber code

For the subscriber code stay in the same directory and download the following:

With this done you will have both publisher_member_function.py and subscriber_member_function.py files in your directory. Plus, the __init__.py.

hashtag
Step 5 - Add dependencies

The next step is to modify some of the files created to support the code we just downloaded. We will be adding the dependencies. Navigate one level back to ~/ros2_ws/src/pubsub.

Open the package.xml file with a text editor. We will be using nano for this tutorial.

After the <license> line add the following lines of code:

Your new file now should look something similar to this:

Exit the file editor and save.

hashtag
Step 6 - Add entry point

The next file you will have to modify is the setup.py file.

Add the following line within the console_scripts brackets of the entry_points field:

Don't forget to save!

hashtag
Step 7 - Building and running

First, go back to the root of your workspace:

Then, check if you have any missing dependencies in your code by running:

If everything is installed successfully you can build your package with colcon:

With the build finished we need to source the setup files.

Finally, we can run the code. You will need two terminals to run both the publisher and subscriber.

circle-exclamation

On the new terminal you will have to go to the workspace the project is in and source the setup files.

In one terminal run the publisher:

You should see that the code starts running and prints:

On the other terminal run the subscriber:

When you run the listener, you will start to see the message from the publisher:

Use Ctlr + C in each terminal to stop the code.

hashtag
Summary

You created two nodes to publish and subscribe to data over a topic. Before running them, you added their dependencies and entry points to the package configuration files.

mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
ros2 pkg create --build-type ament_python py_pubsub
cd ~/ros2_ws/src/py_pubsub/py_pubsub
wget https://raw.githubusercontent.com/ros2/examples/humble/rclpy/topics/minimal_publisher/examples_rclpy_minimal_publisher/publisher_member_function.py
wget https://raw.githubusercontent.com/ros2/examples/humble/rclpy/topics/minimal_subscriber/examples_rclpy_minimal_subscriber/subscriber_member_function.py
nano package.xml
<exec_depend>rclpy</exec_depend>
<exec_depend>std_msgs</exec_depend>
nano setup.py
entry_points={
        'console_scripts': [
                'talker = py_pubsub.publisher_member_function:main',
                'listener = py_pubsub.subscriber_member_function:main',
        ],
},
cd ~/ros2_ws
rosdep install -i --from-path src --rosdistro humble -y
colcon build --packages-select py_pubsub
source install/setup.bash
ros2 run py_pubsub talker
[INFO] [minimal_publisher]: Publishing: "Hello World: 0"
[INFO] [minimal_publisher]: Publishing: "Hello World: 1"
[INFO] [minimal_publisher]: Publishing: "Hello World: 2"
[INFO] [minimal_publisher]: Publishing: "Hello World: 3"
[INFO] [minimal_publisher]: Publishing: "Hello World: 4"
...
ros2 run py_pubsub listener
[INFO] [minimal_subscriber]: I heard: "Hello World: 10"
[INFO] [minimal_subscriber]: I heard: "Hello World: 11"
[INFO] [minimal_subscriber]: I heard: "Hello World: 12"
[INFO] [minimal_subscriber]: I heard: "Hello World: 13"
[INFO] [minimal_subscriber]: I heard: "Hello World: 14"
GitHub - micro-ROS/micro_ros_setup: Support macros for building micro-ROS-based firmware.GitHubchevron-right
micro-ROS package
Install micro-ros-agent on Ubuntu using the Snap Store | SnapcraftSnapcraftchevron-right
micro-ROS snap package
Logo
Tutorials — ROS 2 Documentation: Humble documentationdocs.ros.orgchevron-right
Logo