# Optical FLow uxrce ros2 pixhawk 6c - Set Position

**URL:** <https://discuss.px4.io/t/optical-flow-uxrce-ros2-pixhawk-6c-set-position/37404>\
**Category:** PX4 Autopilot\
**Created:** [March 21, 2024, 10:18am UTC](https://discuss.px4.io/t/optical-flow-uxrce-ros2-pixhawk-6c-set-position/37404 "2024-03-21T10:18:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Heins2100](https://discuss.px4.io/user_avatar/discuss.px4.io/heins2100/32/15966_2.png) [@Heins2100](https://discuss.px4.io/u/Heins2100)\
**Post date:** [March 21, 2024, 10:18am UTC](https://discuss.px4.io/t/optical-flow-uxrce-ros2-pixhawk-6c-set-position/37404/1 "2024-03-21T10:18:25Z")

</div>

Hello community, I’m trying to fly the drone by using only optical flow with ROS 2, UXRCE DDS architecture, and uORB Topics. I’m following the instructions provided in the PX4 documentation:

\ ***UXRCE DDS architecture:**  
[https://docs.px4.io/main/en/middleware/uxrce\_dds.html](https://docs.px4.io/main/en/middleware/uxrce_dds.html)  
\ ***uORB topics:**  
[https://github.com/PX4/PX4-Autopilot/blob/710286da722beae72a488af52b6c1e603f68eea7/src/modules/uxrce\_dds\_client/dds\_topics.yaml](https://github.com/PX4/PX4-Autopilot/blob/main/src/modules/uxrce_dds_client/dds_topics.yaml)

I’m using the VL53L1X rangefinder to measure the distance from the drone to the ground, along with a Raspberry Pi camera. Both are connected to the Jetson Orin.

My node receives data from the VL53L1X rangefinder and images from the camera. With this information, the node calculates the optical flow quality, flow\_x, and flow\_y in radians.

After calculating the flow, I publish the data using the `SensorOpticalFlow` message type (UORB message)  
([SensorOpticalFlow (UORB message) | PX4 Guide (main)](https://docs.px4.io/main/en/msg_docs/SensorOpticalFlow.html)).

 ![publish_msg](https://discuss.px4.io/uploads/default/original/2X/d/ddd17e44b082b759880f98d13569439d8de1b1ec.png)

I publish the message on this topic:

```auto
  - topic: /fmu/in/sensor_optical_flow
    type: px4_msgs::msg::SensorOpticalFlow

```

This message type requires the distance from the rangefinder (local\_distance).

Then I set the parameters in the pixhawk by ground control:  
 ![Screenshot from 2024-03-21 19-14-35](https://discuss.px4.io/uploads/default/original/2X/b/b1986f8787cda7a87757fab71ce8da7fd4498422.png)

After that:

- I successfully run the UXRCE DDS agent on the onboard computer.

- I successfully start the UXRCE DDS client on the Pixhawk.  
 ![Screenshot from 2024-03-21 18-55-18](https://discuss.px4.io/uploads/default/original/2X/3/35eac91f84d7681296cb66e846870d77c69147b2.png)

- I execute my node, and then in the Mavlink Inspector, I can see the optical flow data (although I’m not sure why I cannot see the `sensor_id` and `time_delta_distance_us` ).  
 ![Screenshot from 2024-03-21 18-56-25](https://discuss.px4.io/uploads/default/original/2X/4/46090a350e6d2a5ba34d510d8a13e4121e9f1fc9.png)

The distance changes correctly in `OPTICAL_FLOW_RAD` when I move the drone in the z-axis. However, when I check the ODOMETRY & LOCAL\_POSITION\_NED, the value in the z-axis is different.  
 ![Screenshot from 2024-03-21 19-09-59](https://discuss.px4.io/uploads/default/original/2X/d/dc80f892fa665088fcbbe42f3434ba72b7def698.png)

My question :

- How should I set up the Pixhawk to fly using optical flow?
- Do I need to publish only the value of the rangefinder to another node?
- What is the purpose of publishing the distance into the topic `/fmu/in/sensor_optical_flow` with this structure type: `px4_msgs::msg::SensorOpticalFlow`?

Thank you in advance.
