Ids of pixhawk's modes

Hello.

I have problem with recognizing ids of base_mode and custom_mode in heartbeat messages. Could someone explain me how it is calculated?

I was thinking that it simply references to enum values like MAV_MODE_FLAG or something like that but there doesn’t exist values with these ids. For example base mode equals to 81 exists when pixhawk is only plugged in. And base mode equals to 209 exists when pixhawk is armed.

These values are close to this (increment +1), so my conclude is that modes are calculated by some way.

public enum MAV_MODE : byte
{
PREFLIGHT = 0,
MANUAL_DISARMED = 64,
TEST_DISARMED = 66,
STABILIZE_DISARMED = 80,
GUIDED_DISARMED = 88,
AUTO_DISARMED = 92,
MANUAL_ARMED = 192,
TEST_ARMED = 194,
STABILIZE_ARMED = 208,
GUIDED_ARMED = 216,
AUTO_ARMED = 220
}

Thank you for your answers :wink:

You can see here how it is decoded:

1 Like

Thank you for your replay. I understand how it recognizes when vehicle is armed and when hitl is enabled, but I don’t understand how to_flight_mode_from_custom_mode function works.

How does this switch work? Sorry, but I’m beginner programist in C# and this code is C++. Looks similar but it isn’t the same ;(

Maybe this document will help that defines the enums: