PX4FLOW spikes on data output

Hi ArduPilot community,

I’m trying to install a px4flow sensor on my quad and I’ve been following the setup guide by ardupilot (http://ardupilot.org/copter/docs/common-px4flow-overview.html)
I uploaded the firmware using QGC and focused the lense without any problems, but when I got to the step of testing the sensor, my measurements are far from the ones shown in the guide.
Here are my OF.flowX and OF.flowY readings:

The output spikes seem random and the spike values are a couple of hundred times higher than what is expected. The spikes however only appear when I really move the sensor. If I don’t move the sensor, there are no spikes, which means that those spikes are a reaction of he sensor and not totally arbitrary. Similar with OF.bodyX and OF.bodyY:

Here, the spikes are in the domains of a couple of thousands, which is insane.

My gyroscopic readings are pretty credible in comparison to that:

I’m running APM Copter V3.4-dev on an Erle Brain 2.
I was using MP 1.3.44 to take the screenshots but I get similar results with QGC or APM Planner.

I also tested the px4flow with an arduino to see if the sensor was broken but the readings were good and it working fine.

If anyone has any ideas how I could maybe fix this, please let me know! I’ve been stuck with this problem for a pretty long time. Thanks!

Here is the full log: 1 10.02.2017 18-20-41.bin (1.1 MB)



Why? You neither using a stable 3.4 version nor a recent development version.


it is pre-installed with the OS of Erle Brain 2, but I will try to update it. Is APM 3.4-dev known to have problems with px4flow?

We do builds for ErleBrain2 boards: http://firmware.ardupilot.org/Copter/stable/erlebrain2-quad/ They should work fine, but please test it first on the ground.

I can’t answer that as 3.4-dev isn’t a known version, it can be anything from May 2015 to October 2016. Even if you give me a specific commit I couldn’t tell, it’s impossible to test every feature for a development version.

I’m getting very similar errors with my erle brain 3. Do you have any updates? That would be really helpful, thanks

Lets start from beginning
You have read this ? http://ardupilot.org/copter/docs/common-px4flow-overview.html
Have you updated the PX4Flow firmware ?
Do you see the Px4Flow on the I2cBus with i2cdetect ?
You enabled the optcal flow with mission planner?
Do you see on the Flight Data screen’s Status tab, non-zero opt_m_x, opt_m_y and an opt_qua values?

@JD-ETH Reading your recent comment:
Hi developers! I am working with APM planner 2.0.25rc, and trying to interface my px4flow to the rapsberry(erle brain) board. After an additional LidarLite v3 sensor is up and running, and calibrating done with usb and QGroundControl, I am getting spiky measurements(10^5) in the apm planner and were not useful. Any ideas? thanks

I suspect that you have power supply problems, how did you connected the Lidar & Px4 Flow?

Look here for a simple I2C hub: How to connect Lidar Lite v3 to Pixhawk PWM?

1 Like

@ppoirier Hi thanks for the quick reply! I was able to detect both sensors on i2c (erle has 2 i2c ports), and reading of rangefinder is fine. In qground control opt flow is giving none zero value with usb connection.

Indeed I don’t have a capacitor as instructed on the official site, since erle personals seems to have made it work without that. Now I will add in this to the i2c connection. Thanks and you quad copter looks nice, exactly what we want to achieve :slight_smile:

May I suggest you disconnect Lidar and test just the Px4 for the moment?

On I2C, You should have reading corresponding to x-y velocities while moving optical flow on a textured background

Hi @JD-ETH, unfortunately, I don’t have any updates that are helpful in solving the Erle Brain problem with PX4Flow. I ended up using a Pixhawk 2.4.8 flight controller instead. The error may have to do with raspberry pi boards, since I found this thread after some digging in the Navio+ forums. If you look at the first screenshot, it is very similar to those I uploaded. The Navio user said he had three successful flights before the crash but I suspect that optical flow wasn’t active in any of those flights.

Please keep your progress updated, I’m also very curious.

Cheers and good luck!

Meanwhile, You can test the PX4Flow on I2C using this Python Script

1 Like

simply connecting px4flow via I2C gives me spiking results. I will start by building a capacitor following the ardupilot documentations. but after @Nafnaf 's information, I doubt that would work.

I am thinking of bypassing I2C port, becuase that seems to be the problem. Erle runs ROS, so I could read non-zero values if I connect the sensor via usb and run: rosrun mavros_extras px4flow.launch. Given that the sonar is able to detect ground and the focus is correct. I am looking for achieving position control, by overriding rc channel using px4flow velocity estimation feedback.

How exactly is px4flow information integrated in ArduPilot LOITER without GPS? Are the lidar distance information used for the flow calculation? or the LOITER would only work when the drone is at desired height in this case? And I assume the flow_xy are used as a velocity feedback control?


In case you missed ir
You can test the PX4Flow on I2C using this Python Script
I just tested on my RPI2 = I works like a charm :slight_smile:

I dont recommend you to try bypassing the actual method, PX4Flow is tightly integrated with the EKF, any other method will transform your done into a psychotic killer wasp :wink:

As far as I know, optical flow information received from PX4Flow is passed to the EKF. With all other available sensor information, the EKF estimates the position, velocity and attitude of the drone. Some controllers then calculate the control inputs for the motors.
Lidar distance information is not used for flow calculation but only to control the altitude of the drone. Distance information used for velocity vector scaling in the optical flow algorithm inside PX4Flow is taken from its sonar sensor.
The optical flow algorithm only works if your drone is at a height inside the sonar’s effective measuring range, which should be between 30 cm and 3.5 m. LOITER mode should not let you fly higher than 3.5 m if optical flow is enabled.


With Lidar Lite V3 you can go up to 40 Meter , The Optical flow can work up to 100 Meter if you change the lens

But won’t you also need to upgrade the sonar as well? Or can you connect the Lidar Lite V3 to the PX4Flow sensor?

As described in the WIKI: http://ardupilot.org/copter/docs/common-px4flow-overview.html,

__Although the sensor has plus a built-in Maxbotix LZ-EZ4 sonar to measure height, this has not been reliable enough over a range of surfaces in testing, so its readings are not used and instead a separate Range Finder such as the LightWare SF10b must also be attached to the vehicl_e.

So processing the range data (Altitude in our case) with a laser based rangefinder allow for more precision, and much higher operation level.

You connect the Lidar on the I2C bus , just like the Px4Flow , they have different address:
PX4Flow is 42 and Lidar Lite is 62.

Here is a close up of my implementation, both devices shares the same I2C bus.
I added Pull-up Resistor and a Capacitor.

And this is a detaill of my DIY HUB:

Well I don’t see a way that it would work without bypassing :frowning:

How do I use the script? I sshed into erle but I don’t seem to have python on board. Or how do you run the python script?

So would it make sense to share one I2C even though there are 2 on board? looks like a lot of work building it up :stuck_out_tongue: