Altitude smooth mode doesn't work

Hi all,

Somehow the z velocity setpoint isn’t smoothed in Altitude mode, although I have choose Smooth position control option for MPC_POS_MODE and set the max ACC up/down to 2m/s/s.

I feel that Altitude smooth flight task is overriden by normal Altitude flight task.
Here is the log, I kept the drone at fixed altitude and test the setpoint only.

Please let me know your ideas.

Hi @ttdat235, first question that I tried to answer: Did you change the code because I can’t find the hash from your log on the official PX4 repo. And if so did you change anything about the position controller or flight tasks?

The altitude velocity setpoints in the log you provided look indeed unsmoothed. 3m/s change in a small fraction of a second:

This should not be possible since this part limits the acceleration of the setpoint situation dependent:

I did some simulation tests on current master to check. With the defaults of 10m/s^2 MPC_ACC_UP_MAX & MPC_ACC_UP_MAX:

and with 1m/s^2:

It all worked as expected.
Now I’ll check your configuration and how long it should take to accelerate.

In your log MPC_POS_MODE is set to the default value 1 and smoothing should be enabled.
Furthermore you have the defaults:


that correctly map full stick up to 3m/s
and you have the non-defaults constraining acceleration more:


If I use these settings on SITL master and do stick bang up down I get the expected smoothed result:

You have non-default values:


which only breaks things in vertical direction when you’re breaking and not when you’re accelerating. Why would you set JERK_MAX to zero?

I’m sorry but you need to provide more information about the version you use and what you changed. To rule out things I can encourage you to try latest master and resetting the involved parameters to defaults to check if it’s a configuration issue.

@MaEtUgR thanks for your kind replies.
I figured out the problem. I’m using the previous firmware version which doesn’t have the case ManualAltitudeSmooth in mc_pos_control.cpp, so it will definitely choose ManualAltitude only.
This is the code from the latest stable version

I added this code to the position controller and everything is done.

ok, I’m happy to hear that you found out. I can encourage you to use the latest version instead of just copying this part because then you’re on the latest version and debugging gets easier in case you have other problems. Fly safe and have fun.