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/ArduCopter/failsafe.cpp
Views: 1798
#include "Copter.h"12//3// failsafe support4// Andrew Tridgell, December 20115//6// our failsafe strategy is to detect main loop lockup and disarm the motors7//89static bool failsafe_enabled;10static uint16_t failsafe_last_ticks;11static uint32_t failsafe_last_timestamp;12static bool in_failsafe;1314//15// failsafe_enable - enable failsafe16//17void Copter::failsafe_enable()18{19failsafe_enabled = true;20failsafe_last_timestamp = micros();21}2223//24// failsafe_disable - used when we know we are going to delay the mainloop significantly25//26void Copter::failsafe_disable()27{28failsafe_enabled = false;29}3031//32// failsafe_check - this function is called from the core timer interrupt at 1kHz.33//34void Copter::failsafe_check()35{36uint32_t tnow = AP_HAL::micros();3738const uint16_t ticks = scheduler.ticks();39if (ticks != failsafe_last_ticks) {40// the main loop is running, all is OK41failsafe_last_ticks = ticks;42failsafe_last_timestamp = tnow;43if (in_failsafe) {44in_failsafe = false;45LOGGER_WRITE_ERROR(LogErrorSubsystem::CPU, LogErrorCode::FAILSAFE_RESOLVED);46}47return;48}4950if (!in_failsafe && failsafe_enabled && tnow - failsafe_last_timestamp > 2000000) {51// motors are running but we have gone 2 second since the52// main loop ran. That means we're in trouble and should53// disarm the motors->54in_failsafe = true;55// reduce motors to minimum (we do not immediately disarm because we want to log the failure)56if (motors->armed()) {57motors->output_min();58}5960LOGGER_WRITE_ERROR(LogErrorSubsystem::CPU, LogErrorCode::FAILSAFE_OCCURRED);61}6263if (failsafe_enabled && in_failsafe && tnow - failsafe_last_timestamp > 1000000) {64// disarm motors every second65failsafe_last_timestamp = tnow;66if(motors->armed()) {67motors->armed(false);68motors->output();69}70}71}727374#if AP_COPTER_ADVANCED_FAILSAFE_ENABLED75/*76check for AFS failsafe check77*/78void Copter::afs_fs_check(void)79{80// perform AFS failsafe checks81g2.afs.check(last_radio_update_ms);82}83#endif848586