Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NAV] Restrict MC RoC/RoD rate-limiting to the case where we actually accelerate #4245

Merged
merged 2 commits into from
Jan 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/navigation/navigation_multicopter.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ static void updateAltitudeVelocityController_MC(timeDelta_t deltaMicros)

posControl.pids.pos[Z].output_constrained = targetVel;

// limit max vertical acceleration to 1/5G (~200 cm/s/s) if we are increasing velocity.
// limit max vertical acceleration to 1/5G (~200 cm/s/s) if we are increasing RoC or RoD (only if vel is of the same sign)
// if we are decelerating - don't limit (allow better recovery from falling)
if (fabsf(targetVel) > fabsf(posControl.desiredState.vel.z)) {
const bool isSameDirection = (signbit(targetVel) == signbit(posControl.desiredState.vel.z)) && (targetVel != 0) && (posControl.desiredState.vel.z != 0);
if (isSameDirection && (fabsf(targetVel) > fabsf(posControl.desiredState.vel.z))) {
const float maxVelDifference = US2S(deltaMicros) * (GRAVITY_CMSS / 5.0f);
posControl.desiredState.vel.z = constrainf(targetVel, posControl.desiredState.vel.z - maxVelDifference, posControl.desiredState.vel.z + maxVelDifference);
}
Expand Down