Skip to content

Commit

Permalink
mc_pos_control: fix altitude limitation
Browse files Browse the repository at this point in the history
Before if you were above the maximum altitude you could not command to
go down anymore until the position controller had overshoot to under the
maximum altitude again.
  • Loading branch information
MaEtUgR committed Feb 25, 2019
1 parent 93ef70c commit db0283e
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/modules/mc_pos_control/mc_pos_control_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,22 +486,13 @@ MulticopterPositionControl::limit_altitude(vehicle_local_position_setpoint_s &se
return;
}

float altitude_above_home = -(_states.position(2) - _home_pos.z);
// maximum altitude == minimal z-value (NED)
const float min_z = _home_pos.z + (-_vehicle_land_detected.alt_max);

if (altitude_above_home > _vehicle_land_detected.alt_max) {
// we are above maximum altitude
setpoint.z = -_vehicle_land_detected.alt_max + _home_pos.z;
setpoint.vz = 0.0f;

} else if (setpoint.vz <= 0.0f) {
// we want to fly upwards: check if vehicle does not exceed altitude

float delta_p = _vehicle_land_detected.alt_max - altitude_above_home;

if (fabsf(setpoint.vz) * _dt > delta_p) {
setpoint.z = -_vehicle_land_detected.alt_max + _home_pos.z;
setpoint.vz = 0.0f;
}
if (_states.position(2) < min_z) {
// above maximum altitude, only allow downwards flight == positive vz-setpoints (NED)
setpoint.z = min_z;
setpoint.vz = math::max(setpoint.vz, 0.f);
}
}

Expand Down

0 comments on commit db0283e

Please sign in to comment.