Optical Flow 'working' & issues

It’s been over a year since I worked on this project, I wish I could be of more help. From what I remember, making sure that everything booted right was the biggest issue.

Check what’s happening on the serial ports maybe.

Sorry for the non-answer!

Thanks, I should probably have mentioned that if it had it working with the serial port connected and then I disconnect it then it stops working, even if I don’t reboot it and the USB cable is still connected to the computer. So I don’t think it’s specifically and boot or power issue.

not had any experience with optical flow but it sounds although its working sometimes at least,

It sounds like your just not being allowed to switch modes. Have you switched off the GPS arming check? You may be able to arm in loiter but not switch to loiter.

Does altitude hold mode work with the sonar? This would confirm the sonar is working correctly, you need both the sonar and flow for loiter.

I assume you mean the pixhawk is connected on USB rather than the Px4flow, all sounds very odd.

A log would defiantly be use full, although I am no expert. It would help to switch on disarmed logging,

I don’t think the sonar is supported any more for optical flow is it? I think you need a proper rangefinder (ie lidar)

Thanks both,

yes I’ve disabled the GPS arming check - and I don’t get any arming error messages when it’s plugged in and connected to MP. Yes AltHold mode works fine so I know the sonar is working and the I2C bus is working which has both sensors connected.

Yes the Pixhawk is connected with USB.

According to the documentation the PX4flow is supported with sonar, just not the sonar it comes with. Unless that’s only for some specific previous version of firmware.

I’ll try to work out how I can upload the log.

Not sure if this is still correct, but I think it is:

On this page:

Although the sensor may be supplied with 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. It is recommended to purchase a PX4Flow device without the sonar. Instead a separate Range Finder such as the LightWare SF10b should also be attached to the vehicle.


It’s great to see you here. I was actually thinking of pinging you about trying to get AP working with opendog. We have recently added support for balance bots which is clearly still very different but a walking robot would be a lot of fun.

Back to optical flow… altitude hold will work just using the barometer of course so althold working isn’t necessarily a good test of whether the range finder is working. Still, if the range finder has been attached and enabled then if it’s not working you’ll likely see a “Bad Lidar health” on the ground station’s HUD (aka the globe part that shows the vehicle’s attitude).

re sharing logs, maybe put it in dropbox or google drive and provide a link here and we can have a look.

@rmackay could you please confirm if the sonar is supported or not with optical flow?


We don’t support the sonar that is attached to the px4flow sensor directly so a separate sonar must be used.

By the way, we think that one of these other optical flow sensors may also work because the same sensor is on the 2018/2019 skyrocket drones. We just haven’t had anyone test if they work yet.

I’ve also been thinking we should add support for using the OpenMV camera as an optical flow sensor. I have this on my to-do list but it could be a while before I get to it.

1 Like

Thanks for clarifying!

Hello Randy,
I have curiosity on those sensors. Would I2C connection of those sensors work like px4flow ? I understand that optical range might be short without optics.

Hi Hattori-san,

I think those sensors mostly use an SPI connection so it will only be possible with a board that has an exposed SPI port like the Pixhawk1.

Nice to see you here and thank you for reply. I found SPI connection on Pixhawk1. I will get some and give a try.

1 Like

Thanks everyone!

I did a new test today and generated some clean logs which are here:


The first one was a clean power on with USB plugged in first, then the drone battery which has a 5v/12v distro board to power everything. It armed ok but then it wouldn’t switch modes to loiter. I launched and connected MP and then it allowed me to arm and switch modes. I tried flying with the USB cable attached, but it’s pretty tricky to tell what’s going on.

On the second test I did the same and then pulled the USB cable before attempting flying which I think worked. It looks like it was trying to hold altitude and position before crashing into the wall - I was doing this indoors because the ground is wet outside and I don’t want to mess around with my laptop on the ground to get it running. The drone can probably see its own shadow under it though which won’t help with position hold, and the altitude hold definitely needs tuning, but it seems to be trying to hold it. I’d rather be doing this outside really with lots of space so I can tune it.

I originally did get ‘bad lidar health’ when setting the drone up, but it goes away if you pick the drone up a bit. I’ve set the minimum range finder distance to 5cm, although it’s closer to the ground than that, so for now I’ve just disabled the re-flight check. But does this mean it’ll never use the range finder, or is it fine once it’s in the air?. I could always put longer legs on the drone if I need to get the range finder higher up to start with…

I have been flying OF indoor iwith a 450 since a few years now.
Here is what you need to do:

  • Make sure you have a good texteured non reflective surface , I am flying over rug

  • Feed the PX4FLOW and Rangefinder on a dedicated UBEC with good filtering

  • Set EK3 in order to set EKF HOME

  • Connect to Mission Planner and right click to set home & EKF Home

  • You should see the vehicle appears

  • Take the quad on you hand and walk it around the room , it will show the displacement on the screen and altitude must be correct.
    (I used to walk a square or a 8 pattern and this must be showned on screen)
    -Then you can takeoff alt-hold and switch to loiter, once you confirmed working you can takeoff loiter or guided


txs for all this, one thing - I wonder if it’s really necessary to use the EK3 though. EKF2 should work fine I think.

Unless something changed, you could not set EKF origin in GPS denied with EK2

Thanks for this, so I followed the steps, but my drone doesn’t draw the pattern how I move it. I still haven’t resolved why it won’t change modes when it’s disconnected but I’ll try a different power supply.

So it looks like I need to do the calibration as per: http://ardupilot.org/copter/docs/common-px4flow-overview.html#calibrating-the-sensor

Is there a guide on downloading and plotting the logs - are these just the normal logs like the ones I uploaded, which files do I need and how do I plot them?


So I worked out how to review the logs. Something weird is going on though:

First attempt was as per the optical flow setup, but the scaling looks very weird. This is with the flow X and Y scalers set to 0:

So I modified the FLOW_FYSCALER only to 100, and then I get the following, which looks like it’s getting there. But I don’t know why both X and Y axis have changed scale since FLOW_FXSCALER is still 0.

So then I changed the Y scaler to 200, and I get this. Again I don’t know why both axis have changed scale since FLOW_FXSCALER is still 0. Plus there’s some other weird Gyro stuff going on and the results just look random.

In all the tests I get: “Test: OpticalFlow = FAIL - FAIL: insufficient roll data pointsa” in the auto analysis, but I can definitely see opt_m_X and opt_m_y being non-zero and changing values as I move the drone around. I’m powering the flight controller and PX4FLOW from mt PC’s USB port during all the tests.