Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Rover/fence.cpp
Views: 1798
#include "Rover.h"12// fence_check - ask fence library to check for breaches and initiate the response3void Rover::fence_check()4{5#if AP_FENCE_ENABLED6uint8_t new_breaches; // the type of fence that has been breached7const uint8_t orig_breaches = fence.get_breaches();89// check for a breach10new_breaches = fence.check();1112// return immediately if motors are not armed13if (!arming.is_armed()) {14return;15}1617// if there is a new breach take action18if (new_breaches) {19// if the user wants some kind of response and motors are armed20if ((FailsafeAction)fence.get_action() != FailsafeAction::None) {21// if within 100m of the fence, it will take the action specified by the FENCE_ACTION parameter22if (fence.get_breach_distance(new_breaches) <= AC_FENCE_GIVE_UP_DISTANCE) {23switch ((FailsafeAction)fence.get_action()) {24case FailsafeAction::None:25break;26case FailsafeAction::SmartRTL:27if (set_mode(mode_smartrtl, ModeReason::FENCE_BREACHED)) {28break;29}30FALLTHROUGH;31case FailsafeAction::RTL:32if (set_mode(mode_rtl, ModeReason::FENCE_BREACHED)) {33break;34}35FALLTHROUGH;36case FailsafeAction::Hold:37set_mode(mode_hold, ModeReason::FENCE_BREACHED);38break;39case FailsafeAction::SmartRTL_Hold:40if (!set_mode(mode_smartrtl, ModeReason::FENCE_BREACHED)) {41set_mode(mode_hold, ModeReason::FENCE_BREACHED);42}43break;44case FailsafeAction::Terminate:45arming.disarm(AP_Arming::Method::FENCEBREACH);46break;47}48} else {49// if more than 100m outside the fence just force to HOLD50set_mode(mode_hold, ModeReason::FENCE_BREACHED);51}52}53LOGGER_WRITE_ERROR(LogErrorSubsystem::FAILSAFE_FENCE, LogErrorCode(new_breaches));5455} else if (orig_breaches) {56// record clearing of breach57LOGGER_WRITE_ERROR(LogErrorSubsystem::FAILSAFE_FENCE,58LogErrorCode::ERROR_RESOLVED);59}60#endif // AP_FENCE_ENABLED61}626364