Unstable flight in SITL (Gazebo) with optical flow sensor


I was trying to repeat the simulation with optical flow sensors from this tutorial.
I used the following command:
make posix gazebo_iris_opt_flow
pxh> commander takeoff

However, I faced with very unstable behavior of the drone (video)
I found that a cause of it is optical flow sensor, because when I hide the asphalt in the Gazebo, the drone become stable.
I have checked it on both branches (master and stable) and got the same result.

I guess that orientation of optflow sensor is wrong, however I cannot find SENS_FLOW_ROT parameter which mentioned here

My test environment is Ubuntu 14.04, ROS Jade, Gazebo 6.6

Here the log.

How can I fix it?

Best Regards,

I have found optical flow on actual pixhawk hardware to be really unstable in the latest versions of PX4. I had to downgrade to 1.3.1 before it became stable again.

Try that and let me know if it works any better in SITL!

@LorenzMeier Is it possible to customize flow sensor orientation on LPE?

Hello, you mentioned that PX4FLOW is more stable in 1.3.1. I was trying to use PX4 1.4.1, but the drone is swinging back and forth in real flights. Did you experience the same? Was it better when you downgraded to 1.3.1?
Thank you

Yeah I had tried the current release (as of two weeks ago) build, and the current daily/dev builds and the drone just seemed to go haywire in position mode with optical flow.

But when I downgraded I got decent results

@jake Thank you for your advice!
I have tried to use the release 1.3.1, however, I cannot even to takeoff in Gazebo. Although, the firmware outputs into console a message ‘TAKEOFF DETECTED’, the gazebo model of drone does not move.

Anyway, can anybody confirm that SITL with optical flow sensor works properly now?

the firmware needs a position lock for auto takeoff. but with flow only it will not get it until it is in air. so you need to take off manual and than you can switch to position hold for example.

I just flew LPE on master with optical flow in SITL. Recently the flow backend changed. Pleased delete and reclone all px4 source and submodules and you should be fine. The latest version of LPE will takeoff because I added the land detector to it. When you are using this in real-life realize that there is a hand-off between the land detector and the optical flow. If the optical flow isn’t reading well it will fall out of auto and go into failsafe mode/ either land or manual.

you should see this to know you are using the latest flow code:

pxh> commander takeoff
pxh> INFO  [commander] Taking off
INFO  [tone_alarm] positive
INFO  [commander] home: 47.3977432, 8.5455943, 0.11
INFO  [tone_alarm] arming
INFO  [commander] Takeoff detected
INFO  [local_position_estimator] [lpe] land timeout 
Number of good matches: 1, desired: 30
Number of good matches: 3, desired: 29
Number of good matches: 9, desired: 27
Number of good matches: 4, desired: 19
Number of good matches: 5, desired: 17
Number of good matches: 4, desired: 18
Number of good matches: 1, desired: 18
Number of good matches: 2, desired: 22
Number of good matches: 13, desired: 25
Number of good matches: 5, desired: 14
Number of good matches: 5, desired: 14
Number of good matches: 6, desired: 7
Number of good matches: 19, desired: 23
Number of good matches: 3, desired: 4
INFO  [local_position_estimator] [lpe] flow init: quality 202 std 12

@jgoppert Is px4flow without gps is supported with EKF2 state estimator or it is LPE-only? In my experiments with px4flow + gazebo GPS is required (unlike LPE which can do posctl with flow sensor only) and used to reduce position estimation errors. Is it hard to add px4flow-only navigation to ekf2?

I personally don’t use EKF2 as I find LPE easier to work with. I do think they have gotten it working with just flow, but you have to set the correct parameters.

Hi @jgoppert,

I was under the impression that it is possible to takeoff with optical flow without GPS. However, when i disable GPS by “gpssim stop” command, the drone just couldn’t take off without a GPS lock.

Can you give some advice on this? Does the firmware not support taking off without GPS even with an optical flow sensor? Hence, to achieve POSHOLD for example, one will have to takeoff using SET_ATTITUDE_TARGET messages, and change the mode to POSHOLD? In other words, the optical flow will only work once the drone is in the air?


For other confused users like myself that could be searching for the parameter too, it’s not a parameter that is changed in the PX4Flow itself but in the PX4 Flight Controller