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/ArduSub/fence.cpp
Views: 1798
#include "Sub.h"12// Code to integrate AC_Fence library with main ArduSub code34#if AP_FENCE_ENABLED56// fence_check - ask fence library to check for breaches and initiate the response7// called at 1hz8void Sub::fence_check()9{10// ignore any fence activity when not armed11if (!motors.armed()) {12return;13}1415const uint8_t orig_breaches = fence.get_breaches();1617// check for new breaches; new_breaches is bitmask of fence types breached18const uint8_t new_breaches = sub.fence.check();1920// if there is a new breach take action21if (new_breaches) {2223// if the user wants some kind of response and motors are armed24if (fence.get_action() != AC_FENCE_ACTION_REPORT_ONLY) {25//26// // disarm immediately if we think we are on the ground or in a manual flight mode with zero throttle27// // don't disarm if the high-altitude fence has been broken because it's likely the user has pulled their throttle to zero to bring it down28// if (ap.land_complete || (mode_has_manual_throttle(control_mode) && ap.throttle_zero && !failsafe.manual_control && ((fence.get_breaches() & AC_FENCE_TYPE_ALT_MAX)== 0))){29// init_disarm_motors();30// }else{31// // if we are within 100m of the fence, RTL32// if (fence.get_breach_distance(new_breaches) <= AC_FENCE_GIVE_UP_DISTANCE) {33// if (!set_mode(RTL, MODE_REASON_FENCE_BREACH)) {34// set_mode(LAND, MODE_REASON_FENCE_BREACH);35// }36// }else{37// // if more than 100m outside the fence just force a land38// set_mode(LAND, MODE_REASON_FENCE_BREACH);39// }40// }41}4243LOGGER_WRITE_ERROR(LogErrorSubsystem::FAILSAFE_FENCE, LogErrorCode(new_breaches));44} else if (orig_breaches) {45// record clearing of breach46LOGGER_WRITE_ERROR(LogErrorSubsystem::FAILSAFE_FENCE, LogErrorCode::ERROR_RESOLVED);47}48}4950#endif515253