Arduino Mavlink Library – Changing flight modes

Problem: Cannot change flight controller to auto on startup without GPS or EKF lock

The Pixhawk 1 flight controller running the latest 4.0 release of Ardurover is unable to enter auto mode despite setting the parameter ‘initial_mode’ to 10. The problem seems to stem from the autopilot trying to switch to the specified initial_mode setting before a GPS fix has stabilized on boot. For initial driving modes which require a valid and stable GPS lock, a “flight mode change failed” warning will display in the status window and the driving mode will be set to manual instead of auto.

This problem is further compounded when despite having a 3DGPS lock (GPS fix of 3) and a satellite count as high as 10, if the Extended Kalman Filter has not stabilized, the setting of auto mode will still be prohibited.

Dead-end workarounds:

  • The Arduino Mavlink 1 library does not include any EKF specific status modules (mavlink_ekf_status_report_t) so monitoring EKF status using mavlink commands did not seem to be an option.
  • Monitoring # of satellites GPS has acquired – Sat count as high as 10 have been observed with EKF still not ready.
  • GPS Fix of 3 or 4 – It seems EKF stabilization corresponds to a GPS fix of 4, however I cannot be certain that EKF cannot be normalized with a GPS fix of 3.

Workaround: Send flight/driving mode change command till successful, then stop messaging (used in conjunction with a heartbeat monitor function)

For the time being I skipped any Ardupilot/Pixhawk configuration and instead focused changing the driving/flight mode using the Arduino companion computer with Mavlink commands.

Below is my implementation using the Arduino Mavlink protocol:

I call the function below while checking whether or not I also have a GPS lock that is greater than or equal to 3, and if the mode has changed successfully, start the motor. It is used in conjunction with a heartbeat monitor function which determines if the mode has successfully changed to 10 (auto), otherwise keep running the function below every few seconds. This ensures the auto mode is set before commencing its journey.

The function below will send a mode change Mavlink message to the Pixhawk: