I am trying to figure out how to send commands through a serial connection to my IRIS+ to change the flight mode.

I changed the modes with the transmitter and captured the values for 'Base_Mode' and 'Custom_Mode' as reported by the Heartbeat packet.  I was seeing things like:

AltHold (quad disarmed): Base_Mode=81 , Custom_Mode=2

Loiter (quad disarmed): Base_Mode=89 , Custom_Mode=5

Auto (quad disarmed): Base_Mode=89 , Custom_Mode=3

RTL (quad disarmed): Base_Mode=89 , Custom_Mode=6

AltHold (quad armed): Base_Mode=209 , Custom_Mode=2

Loiter (quad armed): Base_Mode=217 , Custom_Mode=5

Auto (quad armed): Base_Mode=217 , Custom_Mode=3

RTL (quad armed): Base_Mode=217 , Custom_Mode=6

First, any idea what these Base_Mode values mean? 

Second, how can i formulate a command to send to the quad to change the mode between AltHold/Loiter/Auto/Etc.?

I am using a C# application, so any code samples would be great.  Thanks!

Views: 4028

Reply to This

Replies to This Discussion

To be more specific, i can successfully ARM/DISARM the quad with the following:

MAVLink.mavlink_command_long_t req = new MAVLink.mavlink_command_long_t();

req.target_system = 1;
req.target_component = 1;

req.command = (ushort)MAVLink.MAV_CMD.COMPONENT_ARM_DISARM;

req.param1 = armed ? 0 : 1;
armed = !armed;

byte[] packet = mavlink.GenerateMAVLinkPacket(MAVLink.MAVLINK_MSG_ID.COMMAND_LONG, req);

serialPort1.Write(packet, 0, packet.Length);

Now i thought to change flight modes like this, but it doesnt seem to be working:

MAVLink.mavlink_set_mode_t req2 = new MAVLink.mavlink_set_mode_t();
req2.target_system = 1;
//req2.base_mode = 16; //BASE MODE = ????? 
req2.custom_mode = 5; //Loiter Mode

byte[] packet = mavlink.GenerateMAVLinkPacket(MAVLink.MAVLINK_MSG_ID.SET_MODE, req2);

serialPort1.Write(packet, 0, packet.Length);

Do i need to set the .base_mode parameter as well?  I dont know what the value should be for that, and as noted above, it seems like they change as i manually change modes with the transmitter switch and output the values on screen.  


Values for custom modes are listed here https://github.com/diydrones/ardupilot/blob/master/ArduCopter/defin...

In c++ you can set the mode as so mavlink_msg_set_mode_pack(GCS_SYSTEM_ID, GCS_COMPONENT_ID, &msg, TARGET_SYSTEM_ID1, 1, customMode); just use 1 for the base mode it's ignored by the APM anyway
You can see the mav_mode values here which make up the. Base_mode https://pixhawk.ethz.ch/mavlink/#MAV_MODE_FLAG

I'd suggest you implement saving a .tlog file in your C# app, then use mavlogdump.py to compare your tlog with one from a working GCS implementation. That should allow you to answer almost any question on how to implement functionality that is in an existing GCS

Reply to Discussion


© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service