Cannot takeoff with optical flow enabled in SITL

Hi, I am performing a SITL simulation for Arducopter in GPS denied environments. I have setup Gazebo with SITL.

I am using optical flow sensor along with rangefinder in substitue of GPS. I have disabled GPS Pre-Arm checks and I am able to arm the throttle but the copter does not takeoff giving an error msg shown below.


These are the parameters that I have set.
AHRS_EKF_TYPE = 3 (Enable EKF version 3, 2 is set by default)​
EK2_ENABLE = 0 (Disable EKF2)​
EK3_ENABLE=1 (Enable EKF3)​
GPS_TYPE = 0 (Disable GPS)​

For adding a Rangefinder set the following parameters:​

EK3_ALT_SOURCE=1 (Use Rangefinder as altitude source for EKF)​

Adding Virtual Optical flow sensor:​


I want to know whether I have mis-configured something? It does not take off in Loiter or Stabilize mode.

1 Like

Ref. this post Ardupilot needs a position reference, even if you will only use relative motion commands. You can test if that is the issue by right clicking in the mavproxy map and click set origin.

Edit: You should be able to take of in stabilized mode without this, so it might be a different issue.

Hi Henrik,

I saw that discussion earlier but it doesn’t seem to help my case.

If I try to set an origin it gives me an error that APM: EKF3 refusing set origin.

I cannot takeoff in any mode.

I am sorry, then I don’t know.

Perhaps you already have tried it, but now might next step be to revert to default settings and see if that works. (Unless you already have tried it.)

Hope someone else can help you.

Hi Henrik,

The copter is not visible on the map when I turn off the GPS. PFA Screenshot.

Like you said, EKF might need the position reference but it is not allowing me to set origin or home.

What can be the issue here?


I don’t know what the issue is. I have not seen the message APM: EKF3 refusing to set origin before.

Are you using your own optical flow implementation? I see you set FLOW_TYPE=5 while the docs set FLOW_TYPE=10. I don’t know if this is a problem or not, but it is a divergence from the setup I used.

I think the TAKEOFF command requires position(I.e. GUIDED mode). Does it work to take off in STABILIZED mode using the simulated rc controls? (Eg. rc 3 1800)

1 Like

Hi Henrik,

Yes, I can takeoff using rc commands in STABILIZE mode. But in guided mode I cannot takeoff using the takeoff command.

What do you mean exactly that it requires a position.

I try the takeoff command like takeoff 10 (10m altitude)

By “requires position” I mean that ardupilot needs a position estimate to fly this flight mode. Typically it gets the position estimate from GNSS, but it can also get it from an optical flow sensor and an initial origin.

Since you can fly in STABILIZED mode, I guess that your issue is with this position estimate.

Did you try to set FLOW_TYPE=10?

Perhaps worth to try to fly with the simulated GPS active. If that does work, we don’t know much more, but if it does not work we can further try to isolate the issue.

Hey, I did try with FLOW_TYPE=10. And I can fly using GPS. But without GPS is where the issue is.

How can we give it position? It doesn’t let me set origin or home.

You can right click on the map to get the option

It always gives me error EKF3 refusing set origin

Look at the screenshots above.

Try disable EKF3
Just use EKF2


Thanks for your reply.

My problem was that EK3_GPS_TYPE was 0 and not 3.

I was able to set origin and takeoff.

But, now all I see for OPTICAL_FLOW.flow_x and OPTICAL_FLOW.flow_y values as 0.

P.S: I am not using Mission Planner.