Skip to content

Quadrotor Flight with ROS2 and PX4 - Guide

This page describes how to fly a quadrotor using a motion capture (MOCAP) system. Instructions on how to fly a quadrotor using PX4 in offboard mode through QGroundControl and ROS2.

MOCAP Set-up

Basic overview:

  1. Create an asset
  2. Track and publish data via VRPN
  3. Start VRPN client node
  4. Subscribe to data on ROS2 topic

Create an Asset

See Leon's Tutorial for a detailed walk-through.

Publish MOCAP Data

See Leon's Tutorial for a detailed walk-through.

Note that you only need to enable the VRPN option. NatNet streaming enabled is not required.

Receive MOCAP Data

See Leon's Tutorial for a detailed walk-through.

The data of the asset (position and quaternion) will be published to a ROS2 topic.

Install vrpn-mocap package

sudo apt install ros-<rosdistro>-vrpn-mocap

Run the mocap node. The server number is something like 192.168.1.191

ros2 launch vrpn_mocap client.launch.yaml server:=<server number> port:=3883
# Or try this
ros2 run vrpn_client_ros vrpn_client_node 

Check mocap data being published. You must be connected to MAGICC wifi!

ros2 topic echo /vrpn_mocap/<asset_name>/pose

Check frequency of messages

ros2 topic hz /vrpn_mocap/<asset_name>/pose

Resources

PX4 Offboard Mode

To fly autonomously via ROS2 commands, the vehicle must be in offboard mode. This requires configuration of PX4 parameters as described below as well as a constant proof of life signal being published from the ROS2 controller program.

PX4 Parameters

  • EKF2_BARO_CTRL: 0
  • EKF2_EV_CTRL: 11
  • EKF2_GPS_CHECK: 0
  • EKF2_GPS_CTRL: 0
  • EKF2_EV_DELAY: 0.0ms
  • EKF2_HGT_REF: Vision
  • EKF2_MAG_CHECK: 0
  • EKF2_MAG_TYPE: None
  • EKF2_MULTI_IMU: 3
  • EKF2_RNG_CTRL: Disable range fusion

Parameter Values

Parameters set using QGroundControl

Resources

Helpful Commands for Debugging

Quick Reference

Start VRPN Client

ros2 launch vrpn_mocap client.launch.yaml server:=192.168.1.201 port:=3883

Login to Jetson

ssh magicc@ubuntu.local

Launch QGC

./Downloads/QGroundControl-x86_64.AppImage 

Clone px4_msgs package

git clone https://github.com/PX4/px4_msgs.git

ROS2 Commands

Check the published mocap data

ros2 topic echo /vrpn_mocap/x650_quad/pose
ros2 topic hz /vrpn_mocap/x650_quad/pose

Check the position data passed to PX4

ros2 topic echo /fmu/in/vehicle_visual_odometry
ros2 topic hz /fmu/in/vehicle_visual_odometry

Check odometry data published by EKF2

ros2 topic echo /fmu/out/vehicle_odometry
ros2 topic hz /fmu/out/vehicle_odometry

Rebuild the mocap_px4_bridge package

colcon build --packages-select mocap_px4_bridge
source install/setup.bash 
ros2 run mocap_px4_bridge mocap_px4_bridge

Playback saved mocap data from a rosbag

ros2 bag play mocap_data/

PX4 Console Debugging

This is in the MAVLink Console

# Check flight status
commander status
# See the recent data received on any PX4 topic
listener vehicle_visual_odometry
listener vehicle_status
listener vehicle_odometry
listener estimator_status
listener vehicle_local_position
# Manage ekf2 
ekf2 stop
ekf2 start
ekf2 status
# Check PX4's internal time
uorb top -1 vehicle_visual_odometry
# Other checks
listener estimator_innovations
listener estimator_innovation_variances
listener estimator_status_flags
listener sensor_combined
commander check