Set Flight Modes with Mavlink?

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!

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

Join diydrones

Email me when people reply –

Replies

  • Developer

    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

  • Developer
    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
  • 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.  

    Help?

This reply was deleted.

Activity

DIY Robocars via Twitter
Practice virtual race this Saturday; the real thing will be on Oct 3 https://www.meetup.com/DIYRobocars/
Wednesday
DIY Robocars via Twitter
Wednesday
Derrick Davies liked lisa TDrones's profile
Wednesday
DIY Robocars via Twitter
Monday
DIY Robocars via Twitter
RT @SahikaGenc: AWS DeepRacer & Hot Wheels Track https://youtu.be/4H0Ei07RdR4 via @YouTube
Sep 14
DIY Robocars via Twitter
Sep 8
DIY Robocars via Twitter
RT @davsca1: We are releasing the code of our Fisher Information Field, the first dedicated map for perception-aware planning that is >10x…
Sep 8
DIY Robocars via Twitter
RT @SmallpixelCar: How this works: 1)object detection to find cones in single camera image, 30 frames/sec on @NVIDIAEmbedded Xavier. 2)comp…
Sep 8
DIY Robocars via Twitter
RT @SmallpixelCar: Use two color cones to guide the robocar. No map needed, on onsite training needed. Just place the cones and it will fol…
Sep 7
DIY Robocars via Twitter
Sep 7
DIY Robocars via Twitter
RT @roboton_io: Great to see http://roboton.io running at 60fps on the cheapest #chromebook we could find! #edtech #robotics #educat…
Sep 3
DIY Robocars via Twitter
RT @openmvcam: Crazy in-depth article about using the OpenMV Cam for Astrophotography: https://github.com/frank26080115/OpemMV-Astrophotography-Gear https://t.co/BPoK9QDEwS
Sep 3
DIY Robocars via Twitter
RT @openmvcam: Hi folks, it's finally here! Our first draft of our Arduino Interface Library is out! It works over SoftwareSerial, Hardware…
Sep 3
DIY Robocars via Twitter
RT @chr1sa: Please let them have an open API. This would be perfect for @DIYRobocars races https://twitter.com/NintendoAmerica/status/1301513099707658246
Sep 3
DIY Robocars via Twitter
RT @SmallpixelCar: Lanenet pretty much used all my GPU power on @NVIDIAEmbedded Xavier since I optimized with tensorRT. I need to run anoth…
Sep 3
DIY Robocars via Twitter
RT @LyftLevel5: Our @kaggle competition on Motion Prediction for Autonomous Vehicles is now live! Experiment with the largest-ever self-dri…
Aug 24
More…