# Using Mocap with ROS 2 for Starling 2

Source: https://forum.modalai.com/topic/3560/using-mocap-with-ros-2-for-starling-2
Category: Development Drones (https://forum.modalai.com/category/44/development-drones)
Tags: starling
Posted: 2024-06-18 00:52:35 UTC by labkit
Replies: 4 · Views: 1802

## labkit · 2024-06-18 00:52:35 UTC

The flight cage I am using has an Optitrack motion capture camera system installed that communicates my Starling 2 drone's position data on the LAN using NatNet protocol. I have a ROS 2 package on my computer that can receive this data. I plan to transmit this data to the drone after it has been converted to the appropriate format. By referencing [this guide](https://docs.px4.io/main/en/ros/external_position_estimation.html), I see that mocap data should be published to the `vehicle_visual_odometry` topic. When PX4 is running on the drone, I can access the ROS 2 topic `/fmu/in/vehicle_visual_odometry`. However,when I publish test data to this topic it does not have any obvious effect. By using the `ros2 topic echo` command I can see that the data is indeed getting published. However, echoing the /fmu/out commands return nothing, including the commands that are supposed to return the drone's position.

Publishing to /fmu/in/vehicle_visual_odometry
![02df36e2-67e4-4f42-816d-8c10fe9f589d-image.png](https://forum.modalai.com/assets/uploads/files/1718670872846-02df36e2-67e4-4f42-816d-8c10fe9f589d-image-resized.png) 

Listening to /fmu/in/vehicle_visual_odometry while publishing topic
![da3eb454-a2d3-47c0-b8c7-9b04b7fb1d0e-image.png](https://forum.modalai.com/assets/uploads/files/1718671050409-da3eb454-a2d3-47c0-b8c7-9b04b7fb1d0e-image.png) 

Attempting to listen to /fmu/out topics
![e85822f3-0373-459e-bc12-df7999476f03-image.png](https://forum.modalai.com/assets/uploads/files/1718671601988-e85822f3-0373-459e-bc12-df7999476f03-image.png)

When I disable PX4 with `systemctl disable voxl-px4` I am able to view the data from these /fmu/out topics. But still, publishing to vehicle_visual_odometry does not change the /fmu/out readings that display vehicle position.

**Images of /fmu/out commands when not publishing to /fmu/in/vehicle_visual_odometry**
![86d3c2e7-4285-414b-b1c0-3a750fc59d0e-image.png](https://forum.modalai.com/assets/uploads/files/1718672788509-86d3c2e7-4285-414b-b1c0-3a750fc59d0e-image.png) 

![b5bd5c26-ffee-4646-acf9-f37be9ecb945-image.png](https://forum.modalai.com/assets/uploads/files/1718673024588-b5bd5c26-ffee-4646-acf9-f37be9ecb945-image.png) 

**when publishing to /fmu/in/vehicle_visual_odometry**
![72af74a1-9b31-4fa1-9001-1bdb4e017309-image.png](https://forum.modalai.com/assets/uploads/files/1718673554809-72af74a1-9b31-4fa1-9001-1bdb4e017309-image.png) 

![42fa3eb3-7974-47d5-be38-e7a0afe6dbdc-image.png](https://forum.modalai.com/assets/uploads/files/1718673622653-42fa3eb3-7974-47d5-be38-e7a0afe6dbdc-image.png)

## Reply by Zachary Lowell 0 · 2024-06-18 17:26:59 UTC

@labkit can you confirm if you have VIO actively going as well? There could be competing information for incoming odometry messages - can you send a screenshot of `voxl-inspect-services` and then also show what you have for the value of ekf2_ev_ctrl.

Thanks!
Zach

## Reply by labkit · 2024-06-18 21:40:08 UTC (in reply to Zachary Lowell 0)

@Zachary-Lowell-0 I said yesterday that echoing the /fmu/out topics only worked if voxl-px4 was disabled on startup and run in a terminal with voxl-px4. This no longer appears to be the case, although I don't know what changed from yesterday to cause this. Now `ros2 topic echo` can print those topics when px4 is launched at startup. However, the topics still don't print the data I would expect if the drone were correctly reading the data I publish to `/fmu/in/visual_odometry`, unchanged from yesterday.

The qvio server was on. I disabled it, but that didn't fix the issue of the drone not using the data from /fmu/in/vehicle_visual_odometry. I believe that shutting down this server should disable VIO, correct? This is the output after disabling qvio server and having px4 enabled to launch at startup.
![a73ed027-db6e-4892-ae6d-13dca2712780-image.png](https://forum.modalai.com/assets/uploads/files/1718745480986-a73ed027-db6e-4892-ae6d-13dca2712780-image.png) 

Here is the output of /fmu/out/vehicle odometry when I am not publishing to /fmu/in/vehicle_visual_odometry
![6de15cf0-ea0d-4103-b0b1-3f4790418efc-image.png](https://forum.modalai.com/assets/uploads/files/1718746154059-6de15cf0-ea0d-4103-b0b1-3f4790418efc-image.png) 

And here is the output when I am publishing to it using the command `topic pub /fmu/in/vehicle_visual_odometry px4_msgs/msg/VehicleOdometry '{timestamp: 1234567890, timestamp_sample: 1, pose_frame: 1, position: [1.23, 4.56, 7.89], q: [0.707, 0.707, 0.0, 0.0], velocity_frame: 1, velocity: [0.5, 1.0, -2.3], angular_velocity: [0.1, 0.2, -0.3], position_variance: [0.01, 0.02, 0.03], orientation_variance: [0.001, 0.002, 0.003], velocity_variance: [0.005, 0.01, 0.02], reset_counter: 0, quality: 1}'` which is supposed to provide it with test mocap data. 

![90d37817-3739-4f43-ac8b-cd45656ec2cb-image.png](https://forum.modalai.com/assets/uploads/files/1718746469477-90d37817-3739-4f43-ac8b-cd45656ec2cb-image.png) 

This is the value of ekf2_ev_ctrl from QGroundControl. 
![d29e0b89-eb6c-4a6d-988c-523f3b63b663-image.png](https://forum.modalai.com/assets/uploads/files/1718745765299-d29e0b89-eb6c-4a6d-988c-523f3b63b663-image.png)

## Reply by Zachary Lowell 0 · 2024-06-20 18:53:54 UTC

Understood - ofcourse disabling wont do much as it is the same thing as running it from command line/bash vs in systemd - I am surprised it created different results when running in systemd vs bash. 

Reason I want to disable/stop qvio is so that when you echo the /out topic you arent receiving anything from the ekf2 inside PX4 that is ingesting and creating the output.

Lastly, the fmu/in/visual_odometry, and fmu/out/visual_odometry are not supposed to be the same - the fmu/out is post processing - they should differ as it fuses all sensor data and such - what is the movement you are expecting?

Also have you checked the yaml file for PX4 - looks like there is a ros2 message specific just for mocap odometry.

https://github.com/modalai/px4-firmware/blob/636ffefcb1a96ad2b53e988d23bf6419955b69ea/src/modules/microdds_client/dds_topics.yaml#L73

## Reply by Ricardo Metral · 2025-07-29 14:34:13 UTC (in reply to Zachary Lowell 0)

I am having the exact same issue, if by any chance you see this @lakbit can you let me know if you found a solution since this thread?
