FlightTask Smoothing: check dt before dividing

This commit is contained in:
ChristophTobler 2018-08-10 09:47:38 +02:00 committed by Daniel Agar
parent 9a23295a40
commit d3d549b8e6
2 changed files with 11 additions and 2 deletions

View File

@ -197,7 +197,11 @@ void
ManualSmoothingXY::_velocitySlewRate(matrix::Vector2f &vel_sp, const float dt)
{
// Adjust velocity setpoint if demand exceeds acceleration. /
matrix::Vector2f acc = (vel_sp - _vel_sp_prev) / dt;
matrix::Vector2f acc{};
if (dt > FLT_EPSILON) {
acc = (vel_sp - _vel_sp_prev) / dt;
}
if (acc.length() > _acc_state_dependent) {
vel_sp = acc.normalized() * _acc_state_dependent * dt + _vel_sp_prev;

View File

@ -146,7 +146,12 @@ void
ManualSmoothingZ::velocitySlewRate(float &vel_sp, const float dt)
{
// limit vertical acceleration
float acc = (vel_sp - _vel_sp_prev) / dt;
float acc = 0.f;
if (dt > FLT_EPSILON) {
acc = (vel_sp - _vel_sp_prev) / dt;
}
float max_acc = (acc < 0.0f) ? -_acc_state_dependent : _acc_state_dependent;
if (fabsf(acc) > fabsf(max_acc)) {