# PX4-ROS2 VIO navigation in GPS denied condition

**URL:** <https://discuss.px4.io/t/px4-ros2-vio-navigation-in-gps-denied-condition/24861>\
**Category:** ROS 1 / ROS 2\
**Created:** [November 2, 2021, 8:12pm UTC](https://discuss.px4.io/t/px4-ros2-vio-navigation-in-gps-denied-condition/24861 "2021-11-02T20:12:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vince94](https://discuss.px4.io/user_avatar/discuss.px4.io/vince94/32/8622_2.png) [@Vince94](https://discuss.px4.io/u/Vince94)\
**Post date:** [November 2, 2021, 8:12pm UTC](https://discuss.px4.io/t/px4-ros2-vio-navigation-in-gps-denied-condition/24861/1 "2021-11-02T20:12:19Z")

</div>

HI guys,

I’m trying to replicate what has been already done for ROS with MAVROS, but this time with ROS2, having a pose external source (T265, ecc…) replacing the GPS.  
I’ve already configured the system, installing on a RPi, ROS2 and Fast DDS, checking that everithing worked as described in [https://docs.px4.io/master/en/ros/ros2\_comm.html](https://docs.px4.io/master/en/ros/ros2_comm.html).

The sw setup is made up by 2 nodes:

- the offboard node (the same in px4\_ros\_com package) to set the offboard node, arming and sending position commands
- the second node simply takes the data coming from the external source and publish on the topic /fmu/vehicle\_visual\_odometry/in

I’ve also set two parameters:

- EKF2\_AID\_MASK: 24 (external position + external yaw)
- EKF2\_HGT\_MODE: 3 (vision)
- CBRK\_GPSFAIL: 240024 (ignoring GPS)

Since the controllor does not pass to offboard mode, but remain in stabilize mode, I’m wondering what I am missing.  
I remember that the ROS implementation there is also a node (set\_origin.py) which sends (through mavros) messages to mavlink, containing the cooridnates of the starting point (MAVLink\_set\_gps\_global\_origin\_message and MAVLink\_set\_home\_position\_message). If this is the problem, there is a way to solve it on ROS2, since apparently there is no topic related to it?

---

<div class="post-metadata">

**Author:** ![Vince94](https://discuss.px4.io/user_avatar/discuss.px4.io/vince94/32/8622_2.png) [@Vince94](https://discuss.px4.io/u/Vince94)\
**Post date:** [January 4, 2022, 9:10pm UTC](https://discuss.px4.io/t/px4-ros2-vio-navigation-in-gps-denied-condition/24861/2 "2022-01-04T21:10:20Z")

</div>

Issue solved, after learning how PX4 works with ROS2

---

<div class="post-metadata">

**Author:** ![gugafelds](https://discuss.px4.io/user_avatar/discuss.px4.io/gugafelds/32/10085_2.png) [@gugafelds](https://discuss.px4.io/u/gugafelds)\
**Post date:** [March 24, 2022, 10:29pm UTC](https://discuss.px4.io/t/px4-ros2-vio-navigation-in-gps-denied-condition/24861/3 "2022-03-24T22:29:56Z")

</div>

Hey, have you managed to fly using only the topic /fmu/vehicle\_visual\_odometry/in?

I just ordered a Pixhawk 5x and will try to build on it and try to fly the drone.

Could you describe approximately how you did it with the ROS2-PX4 bridge?

---

<div class="post-metadata">

**Author:** ![Vince94](https://discuss.px4.io/user_avatar/discuss.px4.io/vince94/32/8622_2.png) [@Vince94](https://discuss.px4.io/u/Vince94)\
**Post date:** [May 16, 2022, 3:18pm UTC](https://discuss.px4.io/t/px4-ros2-vio-navigation-in-gps-denied-condition/24861/4 "2022-05-16T15:18:44Z")

</div>

Hi, yes sure, I’ll try to be as clear as possible.  
Before starting, you need to follow the official procedure [ROS 2 User Guide](https://docs.px4.io/v1.12/en/ros/ros2_comm.html) to correctly set your environment.

Essentially you need these nodes:

- a node that takes the pose data coming from the external source (like the RealSense T265) and passes to the PX4 topic `/fmu/vehicle_visual_odometry/in`, with the specific message type `px4_msgs::msg::VehicleVisualOdometry` which is located in px4\_msgs (you have to take a look over it if you want to know how to fill the message fields)
- a node similar to the example provided by pxf (px4\_offboard inside px4\_ros\_com) which publishes positions (or velocities) commands to the controller; also in this case, I suggest to take a look over the messages definitions if you want to better understand).

Finally you have to set up PX4 parameters in addition of the ones I posted above:

- COM\_RCL\_EXCEPT: 4
- NAV\_RCL\_ACT: 0
- NAV\_DLL\_ACT: 0
- COM\_RC\_IN\_MODE: 4
- COM\_OBL\_ACT: 1 (optional)

I’m not sure these parameters are all required, but it worked for me

---

<div class="post-metadata">

**Author:** ![gugafelds](https://discuss.px4.io/user_avatar/discuss.px4.io/gugafelds/32/10085_2.png) [@gugafelds](https://discuss.px4.io/u/gugafelds)\
**Post date:** [May 19, 2022, 12:50pm UTC](https://discuss.px4.io/t/px4-ros2-vio-navigation-in-gps-denied-condition/24861/5 "2022-05-19T12:50:40Z")

</div>

Nice Vince, thanks for your reply!

Could you share with me your code? I’m trying to implement my Drone with a VICON system.

I have managed to do the Bridge, but I do not know how to send the Pixhawk the positions correctly.

I mean, I would like to know how it must look like this node for passing the message obtained by Vicon to VehicleVisualOdometry topic.

My environment is already set.

---

<div class="post-metadata">

**Author:** ![Luchito8am](https://discuss.px4.io/user_avatar/discuss.px4.io/luchito8am/32/13277_2.png) [@Luchito8am](https://discuss.px4.io/u/Luchito8am)\
**Post date:** [May 22, 2023, 9:52pm UTC](https://discuss.px4.io/t/px4-ros2-vio-navigation-in-gps-denied-condition/24861/6 "2023-05-22T21:52:45Z")

</div>

Hi Vince, I am trying to do the same, but I am new user of ROS2. Can you share the nodes you created to communicate the camera T265 with the Px4? I am trying to read the documentation from realsense and px4, but not making much progress. Maybe you can contribute what you have done here [Searching for Auterion VIO bridge (now private repo) alternative · Issue #21498 · PX4/PX4-Autopilot · GitHub](https://github.com/PX4/PX4-Autopilot/issues/21498). It is an open thread for this problem there

---

<div class="post-metadata">

**Author:** ![Luchito8am](https://discuss.px4.io/user_avatar/discuss.px4.io/luchito8am/32/13277_2.png) [@Luchito8am](https://discuss.px4.io/u/Luchito8am)\
**Post date:** [August 30, 2023, 2:42pm UTC](https://discuss.px4.io/t/px4-ros2-vio-navigation-in-gps-denied-condition/24861/7 "2023-08-30T14:42:03Z")

</div>

I put together a package that I am using and testing now, [Bitbucket](https://bitbucket.org/wvufarolab/cam_to_drone/src/master/)

---

<div class="post-metadata">

**Author:** ![ajay](https://discuss.px4.io/user_avatar/discuss.px4.io/ajay/32/15299_2.png) [@ajay](https://discuss.px4.io/u/ajay)\
**Post date:** [December 20, 2023, 11:30pm UTC](https://discuss.px4.io/t/px4-ros2-vio-navigation-in-gps-denied-condition/24861/8 "2023-12-20T23:30:29Z")

</div>

Hi, is there any working code out there or setup? Been testing the pass few days but could not switch to position holding mode even data is seen `/fmu/vehicle_visual_odometry/in`

---

<div class="post-metadata">

**Author:** ![Matheus\_Rodrigues](https://discuss.px4.io/user_avatar/discuss.px4.io/matheus_rodrigues/32/16374_2.png) [@Matheus\_Rodrigues](https://discuss.px4.io/u/Matheus_Rodrigues)\
**Post date:** [May 6, 2024, 9:31pm UTC](https://discuss.px4.io/t/px4-ros2-vio-navigation-in-gps-denied-condition/24861/9 "2024-05-06T21:31:03Z")

</div>

Hi @ajay, your tests was susccefuly completed? If yes, can you send the code? I am devoloping some code to do that and have some dificults!
