MAVLink Command to Loiter and Descend?

Hi everyone,

I am currently sending MAVLink commands to my drones (both Copter and Plane) and I am looking for a way to do a LOITER and then a descend to a specific altitude.

I’d like the drone to just stay around the same lat/lon of when the commands are sent to it.

I am using C++ and a serial connection to talk to my drone. Right now sending a MAV_CMD_NAV_LOITER_UNLIM does make the drone mode switch to LOITER (both Copter and Plane).

Does anyone know of a standard command I could send to have the drone descend to a specific altitude? The MAV_CMD_NAV_LOITER_UNLIM appears to ignore all parameters. Looking at https://github.com/ardupilot/ardupilot/blob/master/ArduCopter/GCS_Mavlink.cpp, it appears as though all it does is set the mode, and a quick scan through the file, I don’t see an easy command to change altitude.

I can definitely send multiple commands, and can separate which commands are sent to the plane vs copter programmatically, so just looking for any commands that should work.

I’m pretty new to programming my own “ground station” so to speak, and would love any help determining a command I could send to change altitude.

Thanks everyone for their time!

Brian

I am currently sending MAVLink commands to my drones (both Copter and Plane)
and I am looking for a way to do a LOITER and then a descend to a specific
altitude.

I¢d like the drone to just stay around the same lat/lon of when the commands
are sent to it.

AduCopter master just got support for MAV_CMD_NAV_LOITER_TO_ALT

Before that - you’re probably after a waypoint.

Brian

Peter

Thanks for response Peter!

Does Plane already support MAV_CMD_LOITER_TO_ALT? I thought I tested that and it didn’t work…

Brian

Additional question on this:

Does anyone know how to send a waypoint then via a serial command (using C++)?

I created a payload to send by the following:
//Prepare NAV_WAYPOINT payload
mavlink_command_long_t payload_waypoint;
payload_waypoint.command = MAV_CMD_NAV_WAYPOINT;
payload_waypoint.target_system = 0; //All systems
payload_waypoint.target_component = 0; //All components
payload_waypoint.confirmation = 0; //First transmission of command, not a confirmation
payload_waypoint.param1 = 65535; //Hold time at waypoint in decimal seconds (65535 is max)
payload_waypoint.param2 = 0; //Acceptance radius in meters (when plain inside the sphere of this radius, the waypoint is considered reached) (Plane only).
payload_waypoint.param3 = 0; //0 to pass through the WP, if > 0 radius in meters to pass by WP. Positive value for clockwise orbit, negative value for counter-clockwise orbit. Allows trajectory control.
payload_waypoint.param4 = 0; //Desired yaw angle at waypoint target.(rotary wing)
payload_waypoint.param5 = 0; //Target latitude. If zero, the Copter will hold at the current latitude.
payload_waypoint.param6 = 0; //Target longitude. If zero, the Copter will hold at the current longitude.
payload_waypoint.param7 = loiter_altitude_; //Target altitude. If zero, the Copter will hold at the current altitude.

Then obviously encoded it using:
mavlink_message_t message;
mavlink_msg_command_long_encode(system_id_, component_id_, &message, payload);
uint8_t write_buffer[300]; // longer than any possible Mavlink message
uint16_t message_length = mavlink_msg_to_send_buffer(write_buffer, &message);
port_->write(write_buffer, message_length);

But I get a (from my printout to verify) MAVLink Command ID - 16, Result - MAV_RESULT_UNSUPPORTED

I tried the same with MAV_CMD_NAV_LOITER_TO_ALT:
mavlink_command_long_t payload_loiter_to_alt;
payload_loiter_to_alt.command = MAV_CMD_NAV_LOITER_TO_ALT;
payload_loiter_to_alt.target_system = 0; //All systems
payload_loiter_to_alt.target_component = 0; //All components
payload_loiter_to_alt.confirmation = 0; //First transmission of command, not a confirmation
payload_loiter_to_alt.param1 = 1; //Set to heading required to match next waypoint before exit loiter
payload_loiter_to_alt.param2 = 0; //Use default loiter params for UAV (set by operator)
payload_loiter_to_alt.param3 = 0; //Not Used
payload_loiter_to_alt.param4 = 0; //Allow forward moving UAVs to exit from waypoint
payload_loiter_to_alt.param5 = 0; //Use current lat
payload_loiter_to_alt.param6 = 0; //Use current lon
payload_loiter_to_alt.param7 = loiter_altitude_; //Loiter at desired altitude

I get a (from my printout to verify) MAVLink Command ID - 31, Result - MAV_RESULT_UNSUPPORTED.

I am assumming the file GCS_Mavlink.cpp is the file that accepts these commands that I send, is that correct? Any idea how to set a waypoint via code I can send through the serial?

I’ve been trying using a mavlink_set_position_target_global_int_t payload as well. It seems to write but I get no response from the drone.

I’ve tried all these on both fixed_wing and multi-rotors. And just FYI, I’ve been verifying behavior using mission planner and the sim_vehicle.py simulator (and using TCP to simulate my serial connection).

Using release 3.5.7 of Ardupilot.

Any help is appreciated. Thanks again!

Brian