# Is PX4Flow output raw data accurate?

**URL:** <https://discuss.px4.io/t/is-px4flow-output-raw-data-accurate/28070>\
**Category:** PX4 Autopilot\
**Created:** [June 28, 2022, 7:46am UTC](https://discuss.px4.io/t/is-px4flow-output-raw-data-accurate/28070 "2022-06-28T07:46:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![U7777777](https://discuss.px4.io/letter_avatar_proxy/v4/letter/u/f0a364/32.png) [@U7777777](https://discuss.px4.io/u/U7777777)\
**Post date:** [June 28, 2022, 7:46am UTC](https://discuss.px4.io/t/is-px4flow-output-raw-data-accurate/28070/1 "2022-06-28T07:46:27Z")

</div>

Hi there, I’m doing a project to make **drone hovering indoors.** I use my own FPGA board and write the flight controller code refering to pixhawk opensource.So far, I can fly the FPGA drone manually and the drone can hold its altitude by using ultrasonic, but the drone still drift left and right.

So I use px4flow to measure the vx(flow\_x) and vy(flow\_y) of the drone. I hope I can use px4flow to achieve hovering, but the raw output of flow\_x and flow\_y read from px4flow seens unstayble. The value changes a lot if vibrating the sensor. I wonders how pixhwak flight controller deals with the px4flow raw output value?

Are there any suggestions or reference opensource code?

---

<div class="post-metadata">

**Author:** ![bresch](https://discuss.px4.io/user_avatar/discuss.px4.io/bresch/32/2343_2.png) [@bresch](https://discuss.px4.io/u/bresch)\
**Post date:** [June 29, 2022, 1:32pm UTC](https://discuss.px4.io/t/is-px4flow-output-raw-data-accurate/28070/2 "2022-06-29T13:32:36Z")

</div>

Hi, what we do in PX4 is to remove the optical flow generated by the angular velocity of the drone (using gyro data) and then fuse the result into an Extended Kalman filter (named EKF2 in PX4) as an aiding source to get a velocity estimate.  
Do you already have an EKF onboard to estimate the attitude of the drone?  
If you just have a complementary filter to estimate the attitude of your drone, you can then just make another simple complementary filter using the accelerometers and the optical flow (scaled by the range finder) to get a smoother velocity estimate in body frame.

Not sure if this is what you already have, but before trying to implement the complementary or Kalman filter, you can already check the “raw” body velocity using just the optical flow and the range finder using those steps: [PX4-Autopilot/VehicleOpticalFlow.cpp at 55563eba49f87624d7b73356ea3d421fee7ec081 · PX4/PX4-Autopilot · GitHub](https://github.com/PX4/PX4-Autopilot/blob/55563eba49f87624d7b73356ea3d421fee7ec081/src/modules/sensors/vehicle_optical_flow/VehicleOpticalFlow.cpp#L290-L296)

---

<div class="post-metadata">

**Author:** ![U7777777](https://discuss.px4.io/letter_avatar_proxy/v4/letter/u/f0a364/32.png) [@U7777777](https://discuss.px4.io/u/U7777777)\
**Post date:** [August 2, 2022, 12:06pm UTC](https://discuss.px4.io/t/is-px4flow-output-raw-data-accurate/28070/3 "2022-08-02T12:06:39Z")

</div>

Sorry for the late reply. I didn’t notice the notifications.

So PX4 only takes the pixel\_movement calculated by px4flow,and scaled it by another rangefinder to transform the pixel\_movement into velocity in real word.Later, PX4 feed the velocity in EKF2 to get a better predicted velocity, and the velocity value is then feed into the PID system to let the drone hover. For example, if the velocity is positive, the PID system would tell the drone to fly back. Is that correct?

What if the drone rotate around the z axis (yaw drift). Assume the pitch and roll angle is zero. From my understanding of px4flow, the optical\_value would change since the picture px4flow takes is also rotating. Does the gyro compensation in PX4 also takes yaw rotation into consideration or it only takes pitch and roll compensation?

Thanks for your replies, It helps a lot.

---

<div class="post-metadata">

**Author:** ![AlexKlimaj](https://discuss.px4.io/user_avatar/discuss.px4.io/alexklimaj/32/14479_2.png) [@AlexKlimaj](https://discuss.px4.io/u/AlexKlimaj)\
**Post date:** [August 2, 2022, 11:20pm UTC](https://discuss.px4.io/t/is-px4flow-output-raw-data-accurate/28070/4 "2022-08-02T23:20:23Z")

</div>

I can’t speak for the PX4Flow specifically, but we just overhauled the optical flow data pipeline in PX4 and yaw is compensated for with the gyro.

> <https://github.com/PX4/PX4-Autopilot/blob/main/src/modules/sensors/vehicle_optical_flow/VehicleOpticalFlow.cpp>

I will also shamelessly plug my ARK Flow as a superior sensor for optical flow and distance.

> **[ARK Flow – ARK Electronics](https://arkelectron.com/product/ark-flow/)**

---

<div class="post-metadata">

**Author:** ![bresch](https://discuss.px4.io/user_avatar/discuss.px4.io/bresch/32/2343_2.png) [@bresch](https://discuss.px4.io/u/bresch)\
**Post date:** [August 3, 2022, 3:12pm UTC](https://discuss.px4.io/t/is-px4flow-output-raw-data-accurate/28070/5 "2022-08-03T15:12:03Z")

</div>

> [@U7777777](#):
>
> What if the drone rotate around the z axis (yaw drift). Assume the pitch and roll angle is zero. From my understanding of px4flow, the optical\_value would change since the picture px4flow takes is also rotating. Does the gyro compensation in PX4 also takes yaw rotation into consideration or it only takes pitch and roll compensation?

If the sensor is centered, there is no compensation to do for a yaw rate because the xy flow is null. If the sensor isn’t on the Z axis of the body frame you can specify [EKF2\_OF\_POS\_X/Y/Z](https://docs.px4.io/main/en/advanced_config/parameter_reference.html#EKF2_OF_POS_X) and EKF2 will compensate for the XY flow generated by a yaw rotation of the drone.

---

<div class="post-metadata">

**Author:** ![U7777777](https://discuss.px4.io/letter_avatar_proxy/v4/letter/u/f0a364/32.png) [@U7777777](https://discuss.px4.io/u/U7777777)\
**Post date:** [August 3, 2022, 4:01pm UTC](https://discuss.px4.io/t/is-px4flow-output-raw-data-accurate/28070/6 "2022-08-03T16:01:07Z")

</div>

What I want to do is provide the PID system a more accurate x y velocity, so it seems ho **w EKF2 compensate** for raw optical flow read from PX4Flow is important for me.

Does this file https://github.com/PX4/PX4-Autopilot/blob/55563eba49f87624d7b73356ea3d421fee7ec081/src/modules/sensors/vehicle\_optical\_flow/VehicleOpticalFlow.cpp#L290-L296 you mentioned before contains all the information of compensate flow generated by the rotation?

The overall system in my mind is like the block diagram below.

 ![image](https://discuss.px4.io/uploads/default/original/2X/c/cc0b22e9200329adeb14c6dd867e4a8c89de9c3f.png)

Thanks for replying.
