Help? MAV_CMD_NAV_LOITER_UNLIM losing altitude in guided mode

Hi all,

I’m using a companion computer to fly in guided mode, which on the whole is working well.

However, I’m slightly puzzled by the behaviour of MAV_CMD_NAV_LOITER_UNLIM. I’m attempting to use this command to hold position until appropriately interrupted. The command is being issued with 0.0f values for latitude, longitude and altitude as suggested by the documentation, i.e. the copter should hold its position and altitude.

So, the copter does hold its latitude / longitude, but also descends as if it was performing a land. Specifying the current altitude value makes no difference, the copter still behaves the same way.

Am I missing something? Is there something else I need to do to make this work?

Many thanks!

Max

I just noticed this post, it appears to describe the same behaviour.

From what you described that is exactly what we observed. We decided to switch to guided mode and then use SET_POSITION_TARGET_GLOBAL_INT.

@Mustafa_Gokce there are now two instances of this behavior recorded. Who in the dev team can we have to look at this as a potential bug?

1 Like

Hi Mustafa,

I’ve included a link to a SITL log that hopefully demonstrates the potential issue. It’s a short mission that consists of the components listed at the end of this post.

https://drive.google.com/file/d/1DyCAn8nAW4_JLB-y94rpwHkf1EZhY97p/view?usp=share_link

I also set up a load of telemetry streams, for brevity these have been omitted. They are used to control the scheduling of the guided commands etc. For example, the loiter is interrupted by the land command after 5 seconds.

Hopefully you’ll be able to see that as soon as the loiter is issued, the altitude starts to decrease before it is interrupted by the land command.

Let me know if there is anything else you need.

Many thanks!

Max

Request Guided Mode – MAV_CMD_DO_SET_MODE set to COPTER_MODE_GUIDED

Takeoff – MAV_CMD_NAV_TAKEOFF, to an altitude of 20.0m

Null Waypoint – MAV_CMD_DO_REPOSITION with the lat/lng/alt parameters set to the same values as the takeoff. This is the work around for #21080 (speed change after takeoff)

Speed Change – MAV_CMD_DO_CHANGE_SPEED, set to 8.0m/s

Waypoint – MAV_CMD_DO_REPOSITION, flies ~40m West from the takeoff point

Loiter – MAV_CMD_NAV_LOITER_UNLIM, the lat/lng/alt are all set to 0.0, this is being used to create a “delay”, i.e. in this example it is interrupted after 5s by issuing the land command

Land – MAV_CMD_NAV_LAND

First of all, nothing is wrong with the firmware (w.r.t. that log).
You shouldn’t be able to send MAV_CMD_NAV_LOITER_UNLIM to the vehicle in GUIDED mode.
You can’t use every AUTO mode command in GUIDED mode.
In that log, there isn’t MAV_CMD_NAV_LOITER_UNLIM issued but there is a mode changing to LOITER mode.
The LOITER mode requires an RC controller, if the throttle is below 50% vehicle descends, if the throttle is above 50% the vehicle ascends.
During the flight, the throttle left at zero so this is why the vehicle start to descend (in LOITER mode).
There is no state machine like AUTO mode in GUIDED mode.
You need to send the command one by one, and the vehicle executes that command ASAP if it can.

Hi Mustafa,

That was quick!

I’m definitely sending a MAV_CMD_NAV_LOITER_UNLIM in guided mode and it is being ACKed. I had noticed the LOITER mode change, which I assumed was triggered by the MAV_CMD_NAV_LOITER_UNLIM command and was expected.

The documentation does state that this particular loiter command (i.e. the “UNLIM” version) can be issued in guide mode. I did try others and as expected they were NACKed.

I did wonder about whether the throttle setting was to blame, makes sense.

Question, if the throttle is at or above 50% and the loiter altitude is set to 0.0, is the loiter then expected to hold its altitude? When I get a chance I’ll test this.

I think like Henk I’ll abandon the use of loiter (the mode change is also a minor complicating aspect) and implement my halt / delay functionality using velocity control.

Many thanks!

Max

If you want to pause/resume the flight, you can take a look at this PR I was working on:

Maybe it will help to accomplish what you’re trying to do.

1 Like

I think your feeback regarding the controller is the trick. I am not aware of that being in the documentation. It makes sense, but is not obvious.

1 Like

It’s interesting, as when an external computer is being used to control ArduPilot you may well want / need to have a safety pilot keeping an eye on things, but not always…

It’s certainly a challenge to make a flight controller agnostic mission executive, but then life is supposed to be fun!

Actually there are some safety related precautions.
There is a parameter called guid_timeout.
This parameter make sure that you’re updating target vehicle state at a reasonable frequency.
Other that that, you can always create a fence to also limit target position.
If you want to limit target vehicle state, change guided timeout, and if you want to limit the entire flight, enable/disable fence.
There are other limits on automatic flight related with vehicle state like speeds accelerations angles etc.
Take a look at them.

Good to know, thanks!