AC_Fence: Add common auto enable and auto disable

This commit is contained in:
James O'Shannessy 2021-01-14 10:35:48 +11:00 committed by Peter Barker
parent 2a9affe517
commit b6d29d746b
2 changed files with 42 additions and 0 deletions

View File

@ -160,6 +160,42 @@ void AC_Fence::disable_floor()
clear_breach(AC_FENCE_TYPE_ALT_MIN);
}
/*
called when an auto-takeoff is complete
*/
void AC_Fence::auto_enable_fence_after_takeoff(void)
{
switch(auto_enabled()) {
case AC_Fence::AutoEnable::ALWAYS_ENABLED:
case AC_Fence::AutoEnable::ENABLE_DISABLE_FLOOR_ONLY:
enable(true);
break;
default:
// fence does not auto-enable in other takeoff conditions
break;
}
}
/*
called when performing an auto landing
*/
void AC_Fence::auto_disable_fence_for_landing(void)
{
switch (auto_enabled()) {
case AC_Fence::AutoEnable::ALWAYS_ENABLED:
enable(false);
gcs().send_text(MAV_SEVERITY_NOTICE, "Fence disabled (auto disable)");
break;
case AC_Fence::AutoEnable::ENABLE_DISABLE_FLOOR_ONLY:
disable_floor();
gcs().send_text(MAV_SEVERITY_NOTICE, "Fence floor disabled (auto disable)");
break;
default:
// fence does not auto-disable in other landing conditions
break;
}
}
bool AC_Fence::present() const
{
const auto enabled_fences = _enabled_fences.get();

View File

@ -74,6 +74,12 @@ public:
/// disable_floor - allows fence floor to be enabled/disabled. Note this does not update the eeprom saved value
void disable_floor();
/// auto_enable_fence_on_takeoff - auto enables the fence. Called after takeoff conditions met
void auto_enable_fence_after_takeoff();
/// auto_disable_fence_for_landing - auto disables respective fence. Called prior to landing.
void auto_disable_fence_for_landing();
/// enabled - returns true if fence is enabled
bool enabled() const { return _enabled; }