Clarification regarding APM modes


I am confused about the representation of APM modes in the heartbeat and uplink messages. This is what I am doing:
APM<--->MAVProxy<---->A python program using pymavlink.
For setting the APM in AUTO and GUIDED modes, I had used the following encoding in my python program:
AUTO: base_mode: 1, custom_mode: 3
GUIDED: base_mode: 1, custom_mode: 4
I figured them out by using Mission planner and checking the contents that MAVProxy sends to APM and used likewise in my program. Since the base_mode is set to 1, are we using "MAV_MODE_FLAG_CUSTOM_MODE_ENABLED" in "MAV_MODE_FLAG" enum and using custom mode to distinguish the modes for APM? If that is the case, can some one point me where these custom modes for APM are defined.

Currently, I am trying to interpret the modes in python program by looking at the heartbeat message. By printing out the received heartbeats for each of the different modes, I observe that the following values are used:
STABILIZE - base mode: 81, custom mode: 0
AUTO - base mode - 89, custom mode - 3
GUIDED - based mode - 89, custom mode - 4
The values are different for the downlink and this is confusing. I checked message definitions (common.xml and ardupilotmega.xml) and mavlink_types.h to make sense of this, but it does not add up. I can proceed with my program as I am printing the message contents using Mission Planner, but I would like to know the correct reference for these definitions. If some one can point me to that, it will be great.


You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –


  • Even I am stuck with this same problem! But I found the custom mode definitions by looking into ardupilot code definitions

    Here is the list of custom modes:

    // Auto Pilot modes

    // ----------------

    #define STABILIZE 0 // hold level position

    #define ACRO 1 // rate control

    #define ALT_HOLD 2 // AUTO control

    #define AUTO 3 // AUTO control

    #define GUIDED 4 // AUTO control

    #define LOITER 5 // Hold a single location

    #define RTL 6 // AUTO control

    #define CIRCLE 7 // AUTO control

    #define POSITION 8 // AUTO control

    #define LAND 9 // AUTO control

    #define OF_LOITER 10 // Hold a single location using optical flow // sensor

    #define TOY_A 11 // THOR Enum for Toy mode

    #define TOY_M 12 // THOR Enum for Toy mode

    #define NUM_MODES 13

    I am wondering where the base mode 81,89 and sometimes 217 comes from. 

  • 我遇到了同样的问题,请问你解决了吗?是否可以告诉我,谢谢 ( I have the same difficulty,Did you solve your problem?please tell me,thanks you very much!)

    • Hi,

      Please check my reply in this thread (date: March 19). I was able to solve it using custom modes. 



      • Thank you so much,

        It is what I was looking for. Always learning with your help.

        Cheers from Spain

  • Hi,

        I have the same difficulty with the MAV_Mode. Did you solve your problem yet.

    • Hi,

      When setting the UAV mode, APM makes use of only the custom mode (it completely ignores the base mode value). This behaviour does not seem to be in sync with how MAVLink determines the modes to be set, but that is how it is right now. For a mapping of 'custom mode->mode name', please refer this:

      If you are using python, has good 'wrappers' for some of the commonly used functionality. For example, to set AUTO mode, the following command can be used:


      To wait for a certain type of message (ex: heartbeat), the following can be used.


      Hope that helps.


      • Is there a clear example of what command one can do to set guided mode to a lat, long, alt coordinates?

        I can connect no problem:

        from pymavlink import mavutil


        Then I can conn.set_mode_auto() or _loiter()...  anything but Guided...

        The mission planner I've got connected can set it to guided, but I can't figure out what it's doing.

        The closest I've come is the following, and it's not really even doing anything:

        conn.mav.command_long_send(conn.target_system, conn.target_component, mavutil.mavlink.MAVLINK_MSG_ID_MISSION_ITEM,0,mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,2,20,0,100,-35.3632609, 149.16522999999998,584.5499877929688)

        What is the secret to guided mode?

        Thanks, anyone and everyone for the help!

      • Hi,

            I could solve the mode issue after looking at google forums by setting the custom mode. Thank you very much for responding though, I appreciate it. :) :)



This reply was deleted.