Setting Modes with Arduino and Pixhawk2/ArduRover?

Need help on using Arduino to send Mavlink messages to Pixhawk2 rover.
I can arm and disarm with the following code and get the return value - MAV_RESULT_ACCEPTED; And the rover arms and disarms ok.

//header info
int sysid = 255;
int compid = 0;
mavlink_message_t msg;
uint8_t buf[MAVLINK_MAX_PACKET_LEN];
uint16_t len;

//<Message #76 COMMAND_LONG - using the mavlink_msg_command_long_pack() function
uint8_t target_system=1;// - not really sure why this has to be at a valu of 1
uint8_t target_component=0;
uint16_t CMD_LONG_command=0;
uint8_t CMD_LONG_confirmation=0;
float CMD_LONG_param1=0;
float CMD_LONG_param2=0;
float CMD_LONG_param3=0;
float CMD_LONG_param4=0;
float CMD_LONG_param5=0;
float CMD_LONG_param6=0;
float CMD_LONG_param7=0;

CMD_LONG_param1 = MAV_MODE_MANUAL_ARMED;// ENUM MODE
CMD_LONG_command=MAV_CMD_DO_SET_MODE;//this is the type of command i.e. SET MODE
// Pack the message
//uint16_t mavlink_msg_command_long_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,uint8_t target_system, uint8_t target_component, uint16_t command, uint8_t confirmation, float param1, float param2, float param3, float param4, float param5, float param6, float param7)
mavlink_msg_command_long_pack(sysid,compid,&msg,target_system,target_component,CMD_LONG_command,CMD_LONG_confirmation,CMD_LONG_param1,CMD_LONG_param2,CMD_LONG_param3,CMD_LONG_param4,CMD_LONG_param5,CMD_LONG_param6,CMD_LONG_param7);
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
// Send the message (.write sends as bytes)
Serial3.write(buf, len);

When I use the same code with CMD_LONG_param1 = MAV_MODE_AUTO_ARMED etc;// ENUM MODE but try to set mode to /Guided , Auto or other MODES etc. I get MAV_RESULT result = MAV_RESULT_UNSUPPORTED; I can Arm/Disarm, Set Mode to AUTO etc. with Mission planner w/o problems.

Can someone help me with this. Thanks.

John,

Maybe the mode number is being put in the wrong field? the mode number should go into the custom_mode field of the command-long. So that’s param2 apparently. We have a rough plan to try and add better documentation on how ardupilot consumes all these messages, hopefully that will happen later this year although I can’t make any promises just yet.

Thank, I have tried that too. Must be something in addition to that suggestion. I was not sure about when I could confirm the system Id, traget_component, target_system or componet id for pixhawk?

John,

Ah, so the target system-id for the message should be set to “1” normally, to be more specific it should be the same as the SYSID_THISMAV parameter of the vehicle.

The target component id can be left at zero meaning send to all components on the vehicle, and there’s probably just one anyway.