Understanding altitude hold

Hi there, can anyone explain me where the D terme and the I term were programmed in this function void AC_PosControl::rate_to_accel_z()
const Vector3f& curr_vel = _inav.get_velocity();
float p; // used to capture pid values for logging
// reset last velocity target to current target
if (_flags.reset_rate_to_accel_z) {
_vel_last.z = _vel_target.z;

// feed forward desired acceleration calculation
if (_dt > 0.0f) {
if (!_flags.freeze_ff_z) {
_accel_feedforward.z = (_vel_target.z - _vel_last.z) / _dt;
else {
// stop the feed forward being calculated during a known discontinuity
_flags.freeze_ff_z = false;
else {
_accel_feedforward.z = 0.0f;

// store this iteration’s velocities for the next iteration
_vel_last.z = _vel_target.z;

// reset velocity error and filter if this controller has just been engaged
if (_flags.reset_rate_to_accel_z) {
// Reset Filter
_vel_error.z = 0;
_flags.reset_rate_to_accel_z = false;
else {
// calculate rate error and filter with cut off frequency of 2 Hz
_vel_error.z = _vel_error_filter.apply(_vel_target.z - curr_vel.z, _dt);

// calculate p
p = _p_vel_z.kP() * _vel_error.z;

// consolidate and constrain target acceleration
_accel_target.z = _accel_feedforward.z + p;

// set target for accel based throttle controller

the schema show there the P and the I and the D whiche it filtred.

I think it is done in the call to accel_to_throttle


The definition in same source file

I d’ont think that the pid of the function AC_PosControl::rate_to_accel_z() is in the function void AC_PosControl::accel_to_throttle(float accel_target_z). because if you look the schema there a 3 loops.
first loop contain only P
seconde loop contain PID with the D filtred
the last loop contain PID

i want to know if the code are not the same of the schema or me who doesn’t understand

There is no need for PID in the calculation of target acceleration. The PID is used to apply change to throttle to get toward the desired target acceleration

i think you don’t understand the concept of PID. try to learn what’s PID.
in the target acceleration. i see only the P term

Cheeky monkey. I have been working with PID for 30 years :slight_smile:


30 years and you did’t understand a simple loop schema. you did’nt see that there is a 3 loop
1 loop only P
2 loop PID
3 loop PID

@jazon, please be nice.

Good luck finding the answer to your question .