CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/ArduSub/fence.cpp
Views: 1798
1
#include "Sub.h"
2
3
// Code to integrate AC_Fence library with main ArduSub code
4
5
#if AP_FENCE_ENABLED
6
7
// fence_check - ask fence library to check for breaches and initiate the response
8
// called at 1hz
9
void Sub::fence_check()
10
{
11
// ignore any fence activity when not armed
12
if (!motors.armed()) {
13
return;
14
}
15
16
const uint8_t orig_breaches = fence.get_breaches();
17
18
// check for new breaches; new_breaches is bitmask of fence types breached
19
const uint8_t new_breaches = sub.fence.check();
20
21
// if there is a new breach take action
22
if (new_breaches) {
23
24
// if the user wants some kind of response and motors are armed
25
if (fence.get_action() != AC_FENCE_ACTION_REPORT_ONLY) {
26
//
27
// // disarm immediately if we think we are on the ground or in a manual flight mode with zero throttle
28
// // 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 down
29
// 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))){
30
// init_disarm_motors();
31
// }else{
32
// // if we are within 100m of the fence, RTL
33
// if (fence.get_breach_distance(new_breaches) <= AC_FENCE_GIVE_UP_DISTANCE) {
34
// if (!set_mode(RTL, MODE_REASON_FENCE_BREACH)) {
35
// set_mode(LAND, MODE_REASON_FENCE_BREACH);
36
// }
37
// }else{
38
// // if more than 100m outside the fence just force a land
39
// set_mode(LAND, MODE_REASON_FENCE_BREACH);
40
// }
41
// }
42
}
43
44
LOGGER_WRITE_ERROR(LogErrorSubsystem::FAILSAFE_FENCE, LogErrorCode(new_breaches));
45
} else if (orig_breaches) {
46
// record clearing of breach
47
LOGGER_WRITE_ERROR(LogErrorSubsystem::FAILSAFE_FENCE, LogErrorCode::ERROR_RESOLVED);
48
}
49
}
50
51
#endif
52
53