mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
AC_Avoidance: take into account minimum altitude fence when calculating climb rate
This commit is contained in:
parent
95b39f64e3
commit
8287d4f2d0
@ -379,30 +379,54 @@ void AC_Avoid::adjust_velocity_z(float kP, float accel_cmss, float& climb_rate_c
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not adjust climb_rate if level or descending
|
// do not adjust climb_rate if level
|
||||||
if (climb_rate_cms <= 0.0f) {
|
if (is_zero(climb_rate_cms)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AP_AHRS &_ahrs = AP::ahrs();
|
||||||
// limit acceleration
|
// limit acceleration
|
||||||
const float accel_cmss_limited = MIN(accel_cmss, AC_AVOID_ACCEL_CMSS_MAX);
|
const float accel_cmss_limited = MIN(accel_cmss, AC_AVOID_ACCEL_CMSS_MAX);
|
||||||
|
|
||||||
|
// if descending, adjust for minimum altitude as necessary
|
||||||
|
if (climb_rate_cms < 0.0f) {
|
||||||
|
#if AP_FENCE_ENABLED
|
||||||
|
// calculate distance below fence
|
||||||
|
AC_Fence *fence = AP::fence();
|
||||||
|
if ((_enabled & AC_AVOID_STOP_AT_FENCE) > 0 && fence
|
||||||
|
&& (fence->get_enabled_fences() & AC_FENCE_TYPE_ALT_MIN) > 0) {
|
||||||
|
// calculate distance from vehicle to safe altitude
|
||||||
|
float veh_alt;
|
||||||
|
_ahrs.get_relative_position_D_home(veh_alt);
|
||||||
|
// fence.get_safe_alt_min() is UP, veh_alt is DOWN:
|
||||||
|
const float alt_min = -(fence->get_safe_alt_min() + veh_alt);
|
||||||
|
|
||||||
|
if (alt_min <= 0.0f) {
|
||||||
|
climb_rate_cms = MAX(climb_rate_cms, 0.0f);
|
||||||
|
// also calculate backup speed that will get us back to safe altitude
|
||||||
|
backup_speed = get_max_speed(kP, accel_cmss_limited, -alt_min*100.0f, dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool limit_alt = false;
|
bool limit_alt = false;
|
||||||
float alt_diff = 0.0f; // distance from altitude limit to vehicle in metres (positive means vehicle is below limit)
|
float alt_diff = 0.0f; // distance from altitude limit to vehicle in metres (positive means vehicle is below limit)
|
||||||
|
|
||||||
const AP_AHRS &_ahrs = AP::ahrs();
|
|
||||||
|
|
||||||
#if AP_FENCE_ENABLED
|
#if AP_FENCE_ENABLED
|
||||||
// calculate distance below fence
|
// calculate distance below fence
|
||||||
AC_Fence *fence = AP::fence();
|
AC_Fence *fence = AP::fence();
|
||||||
if ((_enabled & AC_AVOID_STOP_AT_FENCE) > 0 && fence && (fence->get_enabled_fences() & AC_FENCE_TYPE_ALT_MAX) > 0) {
|
if ((_enabled & AC_AVOID_STOP_AT_FENCE) > 0 && fence) {
|
||||||
// calculate distance from vehicle to safe altitude
|
// calculate distance from vehicle to safe altitude
|
||||||
float veh_alt;
|
float veh_alt;
|
||||||
_ahrs.get_relative_position_D_home(veh_alt);
|
_ahrs.get_relative_position_D_home(veh_alt);
|
||||||
// _fence.get_safe_alt_max() is UP, veh_alt is DOWN:
|
if ((fence->get_enabled_fences() & AC_FENCE_TYPE_ALT_MAX) > 0) {
|
||||||
|
// fence.get_safe_alt_max() is UP, veh_alt is DOWN:
|
||||||
alt_diff = fence->get_safe_alt_max() + veh_alt;
|
alt_diff = fence->get_safe_alt_max() + veh_alt;
|
||||||
limit_alt = true;
|
limit_alt = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// calculate distance to (e.g.) optical flow altitude limit
|
// calculate distance to (e.g.) optical flow altitude limit
|
||||||
|
Loading…
Reference in New Issue
Block a user