Skip to main content

Motion Capture

Motion capture allows for non-GPS navigation by sending pose estimation data to the flight controller's EKF. ROS makes this easy as there are drivers and packages that allow us to publish pose topics into the ROS framework. We can then relay those topics directly into MAVROS which will then send the poses to the flight controller.

Qualisys Motion Capture

This assumes that you have already set up your Qualisys motion capture system and configured a rigid body for your UAV.

QTM is only supported via Windows, so we will use another computer utilizing a Linux distro to act as our ROS pose publisher. The best practice is to connect these two machines via Ethernet to avoid latency and packet loss.

Docker

Setting up Qualisys ROS on Linux is made easy via Docker.

This tutorial will assume you are running on a Linux OS, but Docker can be used on both Mac and Windows via Docker Desktop.

First, make sure you installed Docker Engine. It is also recommend you follow the Linux Post-Installation Steps as well to manage Docker as a non-root user.

We can verify our Docker installation via:

$ docker run hello-world

We can now build our Docker mocap image via the following commands:

$ cd ~/mavrospy/docker/mocap
$ bash run_docker.sh

This script will automatically build the mocap image and open it in a Docker container.

CTRL+C to exit.

PX4 Parameters

If you wish to use a motion caputure system as your means for navigating without a GPS, you must configure the following PX4 parameters.

EKF2_HGT_REF = Vision
EKF2_EV_DELAY = 50.0ms
EKF2_GPS_CTRL = 0
EKF2_BARO_CTRL = Disabled
EKF2_RNG_CTRL = Disable range fusion
EKF2_REQ_NSATS = 5
MAV_USEHILGPS = Enabled
EKF2_MAG_TYPE = None

Timesync

For the pose topic to be understood properly between computers, it's important that both machines are in sync. On both systems, run:

$ timedatectl

In the output, you should see:

System clock synchronized: yes
NTP service: active

If the output indicates that the NTP service isn't active, turn it on via:

$ sudo timedatectl set-ntp on

After this, run timedatectl again to confirm the network time status.

Motion Capture Demo

warning

If you are following this tutorial after the GPS Navigation Tutorial please remove the outdoor MAVROSPY container:

$ docker container rm -f mavrospy2-rpi-outdoor-container

Before you can start publishing pose topics, you must first modify the motion capture configuration file to specify the IP address of your QTM server. Open the file cfg.yaml:

$ nano ~/mavrospy/docker/mocap/cfg.yaml

Find the line that reads:

hostname: "10.24.5.189"

Replace the IP address with the IP address of your QTM server. Save and exit the file.

You can now start publishing. Start by opening the mocap Docker container:

$ cd ~/mavrospy/docker/mocap
$ ./run_docker.sh

Next, run the following command to start publishing pose topics:

$ ros2 launch motion_capture_tracking launch.py

To verify your pose topics are being published, run the following on your companion computer:

$ cd ~/mavrospy/docker/rpi
$ ./run_docker.sh
$ ros2 topic echo /poses

You can now start our motion capture control node on our companion computer via:

$ ros2 launch mavrospy mocap.py
info

You can specify the flight pattern via the pattern argument. If unspecified, it will default to square.

$ ros2 launch mavrospy mocap.py pattern:=figure8

Available Patterns: square, square_head, circle, circle_head, figure8, figure8_head, spiral, and spiral_head. Where _head will specify the drone to face in the direction of motion.

You can verify that your flight controller is receiving our pose topic by entering the following command on your companion computer in another terminal:

$ ros2 topic echo /mavros/vision_pose/pose

CTRL+C to exit.

You can now switch to OFFBOARD mode and watch it fly!