Optical flow + GPS in EK3 fusion

Hello,

I would like to setup my quad to fly outdoors and use the gps + optical flow for loiter mode. |
Is there a way I could setup to fuse the optical flow & gps such that:

  1. It fuses optical flow & gps for position hold, when closer to the ground optical flow has more weight, when higher than the range finder distance, gps contributes more.
  2. The rangefinder + baro are used for height estimation, once beyond the rangefinder’s limit, only the baro is used.

This is so that when in loiter, horizontal movements when closer to the ground are minimal.
I am aware of the LUA script, however, my FC does not contain a sd card (only an external flash).

I do not intend on flying indoors.
I believe EK3_SRC_OPTIONS needs to be set to 1?
Could someone guide me with the settings for the EK3_SRC settings itself?

Currently, my quad is set to switch between the optical flow & GPS based on a tx switch as mentioned in the docs

My understanding of the docs is, when EK3_SRC_OPTIONS=1, it fuses all data in the one source i.e. EK3_SRC1_*

EK3_SRC1_* & EK3_SRC_2_* are not fused.

1. Is the above understanding correct?

2.If yes, would the below settings be correct?

EK3_SRC_OPTIONS=1 (Fuse All Velocities)

EK3_SRC1_POSXY=3 (GPS)

EK3_SRC1_VELXY=5 (Optical flow)

EK3_SRC1_POSZ=1 (Baro)

EK3_SRC1_VELZ=3 (GPS)

EK3_SRC1_YAW=1 (Compass)

EK3_RNG_USE_HGT=80%

With this, I assume optical flow will be fused in to reduce the minor horizontal variations that my GPS module lacks precision for.

I’ve used the Baro as the main source for Altitude, however, EK3_RNG_USE_HGT will be used as the primary source, when within range for the sensor, once out of range, the fallback is the primary sensor.

3)Also, if the EK3 source select switch is set & fusing was enabled, would it override to allow me to manually switch sources?

Thank you.

Hi @Melroy_Cordeiro,

Making the source switch automatic will require a lua script but this should be possible even if the autopilot doesn’t have an SD card because AP supports embedding scripts into the flight code firmware. This requires compiling the code yourself though so it’s a bit difficult.

I think we have an open issue on the custom build server to-do list to allow users to include scripts in the build but I don’t think anyone is actively working on that yet.

Re the source settings, if the best setup should be what’s in the source-gps-optflow.lua with a couple of exceptions bolded below

For higher flying:

  • EK3_SRC1_POSXY = 3 (GPS)
  • EK3_SRC1_VELXY = 3 (GPS)
  • EK3_SRC1_VELZ = 3 (GPS)
  • EK3_SRC1_POSZ = 1 (Baro)
  • EK3_SRC1_YAW = 1 (Compass)

For lower flying

  • EK3_SRC2_POSXY = 3 (GPS)
  • EK3_SRC2_VELXY = 5 (OpticalFlow)
  • EK3_SRC1_VELZ = 3 (GPS)
  • EK3_SRC2_POSZ = 1 (Baro)
  • EK3_SRC2_YAW = 1 (Compass)

.. and t EK3_SRC_OPTIONS = 0 (Do not fuse all velocities) because it’s best not to fuse optical flow velocities when the vehicle is at high altitude, it will actually make things worse