arrow-left

All pages
gitbookPowered by GitBook
1 of 4

Loading...

Loading...

Loading...

Loading...

Auto-start microRTPS client/agent on FMU/NavQ

hashtag
Creating a systemd service to auto-start the microRTPS agent on NavQ

Generate a start up script for the micrortps client under /usr/local/bin

with content

Save the file and exit nano. Make the file executable

Generate a systemd service file to start the startup script at boot

with content

Save the file and exit nano. Check if the process starts

You should see an state active (running), quit with <q> Enable the systemd service file finally to be active at boot

hashtag
Auto-start the microRTPS client on the FMU

circle-info

To run fastRTPS over Ethernet with NavQ board the is needed.

hashtag
Building PX4 with microRTPS

circle-info

You will need a Linux VM or computer to complete this step.

In order to use the microRTPS client on NavQ, you'll need to build PX4 with the _rtps tag for the fmuk66-v3 build target. To do this, you will need to have both the FastRTPS and Fast-RTPS-Gen packages installed. You can just follow the previous guide on your Linux development VM or computer.

Once you have successfully installed those two packages, you can navigate to your cloned PX4 repository and run the following:

hashtag
Flashing your FMU with the updated binary

You will need to flash your FMU with the updated RTPS binary. If you don't know how to do this yet, follow the guide here:

hashtag
Creating a startup file on the SD card

To make the microRTPS client start at boot on the FMU, you will need to have an SD card inserted. On your SD card, make a file at /etc/extras.txt and insert one of the following options:

circle-info

Calling set +e at beginning / set -e at end is needed to prevent from boot errors. Further details can be found on

sudo nano /usr/local/bin/start_micrortps_agent.sh
#!/bin/bash
## startup script for micro_rtps_agent
## agent will communicate to FMUK66 via UDP
## FMUK66 IPv4 addr = 10.0.0.2 
##
## Author: Gerald Peklar <gerald.peklar@nxp.com>  

source /opt/ros/foxy/setup.bash
source ~/px4_ros_com_ros2/install/setup.bash

# Comment out the line that you are not using:

# If you're using T1 Ethernet communication:
micrortps_agent -t UDP -i 10.0.0.2

# If you're using UART communication over the UART3 port:
micrortps_agent -d /dev/ttymxc2 -b 921600
sudo chmod +x /usr/local/bin/start_micrortps_agent.sh
RDDRONE-T1ADAPT
https://dev.px4.io/master/en/concept/system_startup.html#replacing-the-system-startuparrow-up-right
sudo nano /etc/systemd/system/micrortps_agent.service
[Unit]
Description=PX4 micrortps service
After=network.target

[Service]
Restart=always
TimeoutStartSec=10
User=navq
Group=navq
WorkingDirectory=~
ExecStart=/usr/local/bin/start_micrortps_agent.sh

[Install]
WantedBy=multi-user.target
sudo systemctl start micrortps_agent.service
sudo systemctl status micrortps_agent.service
sudo systemctl enable micrortps_agent.service
$ make nxp_fmuk66-v3_rtps
set +e
# For T1 Ethernet communication:
micrortps_client start -t UDP -i <NavQ_IP_Address>

# For UART communication over the TELEM port:
micrortps_client start -d /dev/ttyS4 -b 921600

# For UART communication over the IR/TELM2 port:
micrortps_client start -d /dev/ttyS1 -b 921600
set -e
Program software using debugger | NXP HoverGamesnxp.gitbook.iochevron-right
Logo

Detecting AprilTags with ROS2

[WORK IN PROGRESS]

hashtag
Overview

triangle-exclamation

NOTE: This guide is currently a work in progress. Some details may not be finished.

In this section, we will guide you through the process needed to detect AprilTags on your NavQ. There are a few things that need to be done to accomplish this:

  1. Install ROS2 image tools

  2. Build and install AprilTag detection nodes

  3. Calibrate the camera on your NavQ using a checkerboard pattern

hashtag
Prerequisites

Before we start, you will need a few things:

hashtag
Checkerboard

To create a checkerboard for camera calibration, download this PDF:

hashtag
Desktop Setup

In order to calibrate the camera, you will need to set up your NavQ with a mouse, keyboard, and monitor. Use the included microUSB hub and HDMI connector to do so.

hashtag
Installing required ROS2 software

Install the following packages with the apt package manager by running the commands below:

Once that is finished, move on to the next step.

hashtag
Calibrating the camera

circle-info

This section is a consolidation of the specific commands for the NavQ. If you run into any issues with this section of the guide, email landon.haugh@nxp.com and refer to the official guide:

Hook up your NavQ to a monitor with the provided HDMI cord and connect a USB mouse + keyboard through the included microUSB hub. Open the terminal by clicking the icon at the top left of the screen and open the bash shell by running:

Have your printed checkerboard ready in a well lit environment and run the camera calibration software by running the following commands:

Now use the link in the note above to run through calibarating the camera.

hashtag
Detecting AprilTags

hashtag
Building apriltag_msgs

A prerequisite for the apriltag_ros node is apriltag_msgs. Clone the repo and build it by running these commands:

Make sure to source the install/setup.bash file so that apriltag_msgs can see it when being built.

hashtag
Building the apriltag_ros node

First, in order to detect AprilTags, we need to build the apriltag_ros node written by christianrauch. You can clone his repository by using this git repo:

To make his repo work with ROS2 Foxy, you will need to make a small change in the CMakeLists.txt file. Go to line 26 in that file and delete the apriltag:: token in the AprilTagNode apriltag::apriltag part.

Next, you'll want to save that file and run colcon build in the apriltag_ros folder. Once it is done building, you'll want to source the install/setup.bash file. Add this line to your .bashrc:

hashtag
Creating a new package to concatenate camera information to each camera frame

In order to make the apriltag_ros node work, we need to make sure that camera info messages are being sent in sync with each camera frame published by the cam2image node. We have written an example node that does just that. You can download it here:

You will need to replace the matrices in the node file to match your camera calibration parameters. The source file is located at pypysub/py_pysub/publisher_member_function.py. Once you have done that, make sure to build and install the node and source the install/setup.bash file.

hashtag
Running the code

To run the code, you'll need to run the following ROS nodes:

Run!
https://www.mrpt.org/downloads/camera-calibration-checker-board_9x7.pdfarrow-up-right
https://navigation.ros.org/tutorials/docs/camera_calibration.htmlarrow-up-right
file-archive
86KB
py_pysub.zip
archive
arrow-up-right-from-squareOpen
Full Camera Republish Node Workspace
$ sudo apt install ros-foxy-cv-bridge \
ros-foxy-image-tools \
ros-foxy-image-transport \
ros-foxy-image-transport-plugins \
ros-foxy-image-pipeline \
ros-foxy-camera-calibration-parsers \
ros-foxy-camera-info-manager \
ros-foxy-launch-testing-ament-cmake 
$ bash
# Start publishing camera images to ROS2 topic /camera/image_raw
$ ros2 run image_tools cam2image --ros-args -p device_id:=0 -p width:=640 -p height:=480 -r /image:=/camera/image_raw > /dev/null 2>&1 &
# Start the camera calibration software
$ ros2 run camera_calibration cameracalibrator --size 7x9 --square 0.02
$ git clone https://github.com/christianrauch/apriltag_msgs
$ cd apriltag_msgs
$ colcon build
$ git clone https://github.com/christianrauch/apriltag_ros
source /home/navq/<apriltag_ros folder>/install/setup.bash
$ ros2 run image_tools cam2image --ros-args -p device_id:=0 -p width:=640 -p height:=480 -r /image:=/camera_image > /dev/null 2>&1 &
$ ros2 run py_pysub talker > /dev/null 2>&1 &
$ ros2 launch apriltag_ros tag_16h5_all.launch.py --ros-args -p image_transport:=raw > apriltag_log.txt 2>&1 &

Building and Installing FastRTPS for ROS2 communication to FMU

hashtag
FastRTPS and the microRTPS Agent

FastRTPS and the microRTPS agent are needed on NavQ in order to bridge uORB topics from PX4 to ROS2 on NavQ over a UART or UDP connection. Follow the guide below to build and install these packages.

circle-info

NOTE: FastRTPS and PX4 ROS Com work differently from MAVROS (ROS1). PX4 ROS Com subscribes to uORB topics rather than MAVLINK messages. See below for a diagram of how microRTPS and PX4 ROS Com works.

Follow the link below for more details on microRTPS and PX4 ROS Com:

hashtag
Installing FastRTPS and PX4 ROS Com on NavQ

hashtag
Prerequisites

hashtag
FastRTPS installation

First, we will install the FastRTPS project from eProsima. Use the following commands below to do so:

hashtag
px4_ros_com installation

Next, we will build and install the necessary software that will allow us to use ROS2 to communicate with the microRTPS bridge. First, run the following commands:

triangle-exclamation

URGENT: Building px4_ros_com requires a lot of ram. Enabling a swap disk is highly recommended. This will take up 1GB of space on your storage medium.

Run the following commands to enable a 1GB swapfile:

Now, build the workspace:

circle-info

This will take a long time to build on NavQ. In our experience, it takes anywhere from 45 minutes to an hour. Make sure you have a stable connection to NavQ over UART or SSH, and do not let the NavQ lose power!

hashtag
Sourcing ROS2 bash files

In order to run all of your specific ROS2 software successfully, you must source the install/setup.bash files in each of your ROS2 workspace folders. Add the following lines to your .bashrc to do so:

hashtag
Next steps

Continue to the next page to set up a systemd service that will automatically start the micrortps agent on your NavQ. The guide will also cover how to automatically start the client on the FMU.

~$ sudo apt update
~$ sudo apt install cmake python3-pip gradle python3-colcon-common-extensions gradle
~$ pip3 install --user pyros-genmsg
~$ mkdir src && cd src
~/src$ git clone --recursive https://github.com/eProsima/Fast-RTPS.git -b 1.8.x FastRTPS-1.8.2
~/src$ cd FastRTPS-1.8.2
~/src/FastRTPS-1.8.2$ mkdir build
~/src/FastRTPS-1.8.2$ cd build 
~/src/FastRTPS-1.8.2/build$ cmake -DTHIRDPARTY=ON -DSECURITY=ON .. 
~/src/FastRTPS-1.8.2/build$ make 
~/src/FastRTPS-1.8.2/build$ sudo make install
cd ~/src
~/src$ git clone --recursive https://github.com/eProsima/Fast-RTPS-Gen.git -b v1.0.4 Fast-RTPS-Gen
~/src$ cd Fast-RTPS-Gen
~/src/Fast-RTPS-Gen$ unset TERM
~/src/Fast-RTPS-Gen$ ./gradlew assemble
~/src/Fast-RTPS-Gen$ sudo su
~/src/Fast-RTPS-Gen$ unset TERM
~/src/Fast-RTPS-Gen# ./gradlew install
~/src/Fast-RTPS-Gen# exit
~/src/Fast-RTPS-Gen$
$ cd ~/
~$ mkdir -p ~/px4_ros_com_ros2/src

~$ git clone https://github.com/PX4/px4_ros_com.git ~/px4_ros_com_ros2/src/px4_ros_com
~$ git clone https://github.com/PX4/px4_msgs.git ~/px4_ros_com_ros2/src/px4_msgs
$ sudo fallocate -l 1G /swapfile
$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile
$ sudo swapon /swapfile
$ sudo vim /etc/fstab
Insert: /swapfile swap swap defaults 0 0
$ sudo swapon --show
(make sure swap is active)
~$ ./px4_ros_com_ros2/src/px4_ros_com/scripts/build_ros2_workspace.bash
source /opt/ros/foxy/setup.bash
source ~/px4_ros_com_ros2/install/setup.bash

ROS2

hashtag
ROS2 Foxy Fitzroy Install Guide

circle-info

NOTE: ROS2 is new, but we suggest you use it over ROS1, as ROS1 will be deprecated in the near future. You may run into issues with the ROS2 section of this Gitbook. If you have any issues with the guide, please email landon.haugh@nxp.com if external, or use Teams/Email if internal. MAVROS is not compatible with ROS2. MicroRTPS and PX4 ROS Com replace MAVROS.

Follow the guide at the link below to install ROS2 Foxy Fitzroy on your NavQ running the Demo image.

circle-exclamation

Note 1: at Setup Sources step you might get an error message by curl. To avoid this, run the following commands:

circle-exclamation

Note 2: at Install ROS2 package step, run the ros-foxy-ros-base installer, as the Desktop tools are not needed on NavQ:

hashtag

sudo rm -rf /usr/lib/libcurl*
sudo apt install curl
sudo apt install ros-foxy-ros-base
https://docs.px4.io/master/en/middleware/micrortps.htmldocs.px4.iochevron-right
https://index.ros.org/doc/ros2/Installation/Foxy/Linux-Install-Debians/#setup-sourcesindex.ros.orgchevron-right