-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
safety_warnings.c
85 lines (79 loc) · 3.01 KB
/
safety_warnings.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* $Id: $
*
* Copyright (C) 2012 Pranay Sinha <psinha@transition-robotics.com>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "led.h"
#include "generated/airframe.h"
#include "subsystems/electrical.h"
#include "subsystems/radio_control.h"
#include "autopilot.h"
#include "subsystems/ahrs/ahrs_aligner.h"
#include "autopilot_rc_helpers.h"
#include "safety_warnings.h"
/*
* simple module to blink LEDs when battery voltage drops below a certain
* level, as well as when AHRS is not aligned or when takeoff safety conditions
* are not met.
*/
/* initialises periodic loop; place more init functions here if expanding driver */
void safety_warnings_init(void) {
LED_ON(SAFETY_WARNING_LED);
safety_warnings_periodic();
}
void safety_warnings_periodic(void) {
#ifdef SAFETY_WARNING_LED
if (radio_control.status == RC_LOST || radio_control.status == RC_REALLY_LOST){
RunXTimesEvery(0, 60, 5, 7, {LED_TOGGLE(SAFETY_WARNING_LED);});
RunXTimesEvery(130, 130, 10, 6, {LED_TOGGLE(SAFETY_WARNING_LED);});
}
else if (!(autopilot_mode == MODE_MANUAL) && !autopilot_motors_on){
RunXTimesEvery(20, 240, 40, 1, {LED_ON(SAFETY_WARNING_LED);});
RunXTimesEvery(0, 240, 40, 1, {LED_OFF(SAFETY_WARNING_LED);});
}
else if (!THROTTLE_STICK_DOWN() && !autopilot_motors_on){
RunXTimesEvery(20, 240, 40, 2, {LED_ON(SAFETY_WARNING_LED);});
RunXTimesEvery(0, 240, 40, 2, {LED_OFF(SAFETY_WARNING_LED);});
}
else if (!ROLL_STICK_CENTERED() && !autopilot_motors_on){
RunXTimesEvery(20, 240, 40, 3, {LED_ON(SAFETY_WARNING_LED);});
RunXTimesEvery(0, 240, 40, 3, {LED_OFF(SAFETY_WARNING_LED);});
}
else if (!PITCH_STICK_CENTERED() && !autopilot_motors_on){
RunXTimesEvery(20, 240, 40, 4, {LED_ON(SAFETY_WARNING_LED);});
RunXTimesEvery(0, 240, 40, 4, {LED_OFF(SAFETY_WARNING_LED);});
}
else if (!YAW_STICK_CENTERED() && !autopilot_motors_on){
RunXTimesEvery(20, 240, 40, 5, {LED_ON(SAFETY_WARNING_LED);});
RunXTimesEvery(0, 240, 40, 5, {LED_OFF(SAFETY_WARNING_LED);});
}
#ifdef MIN_BAT_LEVEL
else if (electrical.vsupply < (MIN_BAT_LEVEL * 10)){
RunOnceEvery(20, {LED_TOGGLE(SAFETY_WARNING_LED);});
}
else if (electrical.vsupply < ((MIN_BAT_LEVEL + 0.5) * 10)){
RunXTimesEvery(0, 300, 10, 10, {LED_TOGGLE(SAFETY_WARNING_LED);});
}
#endif
else {
LED_ON(SAFETY_WARNING_LED);
}
#endif
}