LOITER_UNLIM command issues

Hi,

I am currently running Copter 3.5.7, and attempting to send a MAV_CMD_NAV_LOITER_UNLIM (using C++). I initially had it sending as a mavlink_command_long_t with the following parameters:
command = MAV_CMD_NAV_LOITER_UNLIM
target_system = 0
target_component = 0
confirmation = 0
param1 = 0
param2 = 0
param3 = 0
param4 = 0
param5 = <my current latitude (adjusted by multiplying by 1e7)>
param6 = <my current longitude (adjusted by multiplying by 1e7)>
param7 = <my desired altitude (in meters)>

The craft will switch to LOITER mode, but will not go to the desired altitude. Not sure what I am doing wrong. Going through the arudpilot source code, I saw the altitude is set by the z parameter of the packet. So I thought maybe I was sending the wrong command type. So I switched it to a mavlink_command_int_t. But then responded with a COMMAND_UNSUPPORTED. Doing some more digging it appears that the LOITER_UNLIM command is indeed a command_long. So any ideas what I am doing wrong to get it go to my desired altitude as well switch to LOITER?

Thanks in advance for any help.

I am currently running Copter 3.5.7, and attempting to send a MAV_CMD_NAV_LOITER_UNLIM (using C++). I initially had it sending as a mavlink_command_long_t
with the following parameters:
command = MAV_CMD_NAV_LOITER_UNLIM
target_system = 0
target_component = 0
confirmation = 0
param1 = 0
param2 = 0
param3 = 0
param4 = 0
param5 = <my current latitude (adjusted by multiplying by 1e7)>
param6 = <my current longitude (adjusted by multiplying by 1e7)>
param7 = <my desired altitude (in meters)>

The craft will switch to LOITER mode, but will not go to the desired altitude. Not sure what I am doing wrong. Going through the arudpilot source code, I
saw the altitude is set by the z parameter of the packet. So I thought maybe I was sending the wrong command type. So I switched it to a

Where are you seeing that code?

mavlink_command_int_t. But then responded with a COMMAND_UNSUPPORTED. Doing some more digging it appears that the LOITER_UNLIM command is indeed a
command_long. So any ideas what I am doing wrong to get it go to my desired altitude as well switch to LOITER?

To my eye we don’t currently use any of the parameters from the
command-long
(https://github.com/ardupilot/ardupilot/blob/master/ArduCopter/GCS_Mavlink.cpp#L704)

You might be interested in my loiter-to-alt PR:

Peter

Thanks for the response Peter!

To answer your first question. I was following the code in this path: https://github.com/ArduPilot/ardupilot/blob/Copter-3.5/ArduPlane/commands_logic.cpp, in the do_loiter_unlimted(cmd). But maybe thats not the right path?

So if the GCS_Mavlink.cpp is the correct one to follow when sending a command, it appears the MAV_CMD_LOITER_TO_ALT is also not supported? Since its not in the GCS_Mavlink.cpp file of ArudPlane?

Would love to use the CMD_LOITER_TO_ALT, just not sure it would work then. Any other recommendations on commands I could use to perform a LOITER and descend?

Thanks again!!