Is PX4Flow output raw data accurate?

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?

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

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.

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.

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

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 and EKF2 will compensate for the XY flow generated by a yaw rotation of the drone.

What I want to do is provide the PID system a more accurate x y velocity, so it seems how 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.

Thanks for replying.