|
|
|
@ -6,6 +6,11 @@
@@ -6,6 +6,11 @@
|
|
|
|
|
*/ |
|
|
|
|
static void failsafe_on_event() |
|
|
|
|
{ |
|
|
|
|
// if motors are not armed there is nothing to do |
|
|
|
|
if( !motors.armed() ) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// This is how to handle a failsafe. |
|
|
|
|
switch(control_mode) { |
|
|
|
|
case STABILIZE: |
|
|
|
@ -27,6 +32,7 @@ static void failsafe_on_event()
@@ -27,6 +32,7 @@ static void failsafe_on_event()
|
|
|
|
|
case AUTO: |
|
|
|
|
// throttle_fs_action is 1 do RTL, everything else means continue with the mission |
|
|
|
|
if (g.throttle_fs_action == THROTTLE_FAILSAFE_ACTION_ALWAYS_RTL) { |
|
|
|
|
// To-Do: check distance from home before initiating RTL |
|
|
|
|
set_mode(RTL); |
|
|
|
|
} |
|
|
|
|
// if throttle_fs_action is 2 (i.e. THROTTLE_FAILSAFE_ACTION_CONTINUE_MISSION) no need to do anything |
|
|
|
@ -35,6 +41,7 @@ static void failsafe_on_event()
@@ -35,6 +41,7 @@ static void failsafe_on_event()
|
|
|
|
|
if(ap.home_is_set == true) { |
|
|
|
|
// same as above ^ |
|
|
|
|
// do_rtl sets the altitude to the current altitude by default |
|
|
|
|
// To-Do: check distance from home before initiating RTL |
|
|
|
|
set_mode(RTL); |
|
|
|
|
}else{ |
|
|
|
|
// We have no GPS so we will crash land in alt hold mode |
|
|
|
@ -58,19 +65,39 @@ static void failsafe_off_event()
@@ -58,19 +65,39 @@ static void failsafe_off_event()
|
|
|
|
|
|
|
|
|
|
static void low_battery_event(void) |
|
|
|
|
{ |
|
|
|
|
static uint32_t last_low_battery_message; |
|
|
|
|
uint32_t tnow = millis(); |
|
|
|
|
if (((uint32_t)(tnow - last_low_battery_message)) > 5000) { |
|
|
|
|
// only send this message at 5s intervals at most or we may |
|
|
|
|
// flood the link |
|
|
|
|
gcs_send_text_P(SEVERITY_LOW,PSTR("Low Battery!")); |
|
|
|
|
last_low_battery_message = tnow; |
|
|
|
|
// warn the ground station |
|
|
|
|
gcs_send_text_P(SEVERITY_LOW,PSTR("Low Battery!")); |
|
|
|
|
|
|
|
|
|
// failsafe check |
|
|
|
|
if (g.battery_fs_enabled && !ap.low_battery && motors.armed()) { |
|
|
|
|
switch(control_mode) { |
|
|
|
|
case STABILIZE: |
|
|
|
|
case ACRO: |
|
|
|
|
// if throttle is zero disarm motors |
|
|
|
|
if (g.rc_3.control_in == 0) { |
|
|
|
|
init_disarm_motors(); |
|
|
|
|
}else{ |
|
|
|
|
set_mode(LAND); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case AUTO: |
|
|
|
|
// To-Do: check distance to home before initiating RTL? |
|
|
|
|
set_mode(RTL); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
set_mode(LAND); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// set the low battery flag |
|
|
|
|
set_low_battery(true); |
|
|
|
|
// if we are in Auto mode, come home |
|
|
|
|
if(control_mode >= AUTO) |
|
|
|
|
set_mode(RTL); |
|
|
|
|
|
|
|
|
|
#if COPTER_LEDS == ENABLED |
|
|
|
|
if ( bitRead(g.copter_leds_mode, 3) ) { // Only Activate if a battery is connected to avoid alarm on USB only |
|
|
|
|
piezo_on(); |
|
|
|
|
} |
|
|
|
|
#endif // COPTER_LEDS |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|