Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
led_safety_status.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Pranay Sinha <psinha@transition-robotics.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
29 #include "led.h"
30 #include "generated/airframe.h"
31 #include "subsystems/electrical.h"
33 #include "autopilot.h"
35 #include "autopilot_rc_helpers.h"
36 
38 
39 #ifndef SAFETY_WARNING_LED
40 #error You must define SAFETY_WARNING_LED to use this module!
41 #else
42 
43 void led_safety_status_init(void)
44 {
45  LED_ON(SAFETY_WARNING_LED);
47 }
48 
50 {
52  RunXTimesEvery(0, 60, 5, 7, {LED_TOGGLE(SAFETY_WARNING_LED);});
53  RunXTimesEvery(130, 130, 10, 6, {LED_TOGGLE(SAFETY_WARNING_LED);});
54  } else if (!(autopilot_mode == MODE_MANUAL) && !autopilot_motors_on) {
55  RunXTimesEvery(20, 240, 40, 1, {LED_ON(SAFETY_WARNING_LED);});
56  RunXTimesEvery(0, 240, 40, 1, {LED_OFF(SAFETY_WARNING_LED);});
57  } else if (!THROTTLE_STICK_DOWN() && !autopilot_motors_on) {
58  RunXTimesEvery(20, 240, 40, 2, {LED_ON(SAFETY_WARNING_LED);});
59  RunXTimesEvery(0, 240, 40, 2, {LED_OFF(SAFETY_WARNING_LED);});
60  } else if (!ROLL_STICK_CENTERED() && !autopilot_motors_on) {
61  RunXTimesEvery(20, 240, 40, 3, {LED_ON(SAFETY_WARNING_LED);});
62  RunXTimesEvery(0, 240, 40, 3, {LED_OFF(SAFETY_WARNING_LED);});
63  } else if (!PITCH_STICK_CENTERED() && !autopilot_motors_on) {
64  RunXTimesEvery(20, 240, 40, 4, {LED_ON(SAFETY_WARNING_LED);});
65  RunXTimesEvery(0, 240, 40, 4, {LED_OFF(SAFETY_WARNING_LED);});
66  } else if (!YAW_STICK_CENTERED() && !autopilot_motors_on) {
67  RunXTimesEvery(20, 240, 40, 5, {LED_ON(SAFETY_WARNING_LED);});
68  RunXTimesEvery(0, 240, 40, 5, {LED_OFF(SAFETY_WARNING_LED);});
69  }
70 #ifdef MIN_BAT_LEVEL
71  else if (electrical.vsupply < (MIN_BAT_LEVEL * 10)) {
72  RunOnceEvery(20, {LED_TOGGLE(SAFETY_WARNING_LED);});
73  } else if (electrical.vsupply < ((MIN_BAT_LEVEL + 0.5) * 10)) {
74  RunXTimesEvery(0, 300, 10, 10, {LED_TOGGLE(SAFETY_WARNING_LED);});
75  }
76 #endif
77  else {
78  LED_ON(SAFETY_WARNING_LED);
79  }
80 }
81 #endif
#define RC_LOST
Definition: radio_control.h:49
Interface to align the AHRS via low-passed measurements at startup.
uint8_t autopilot_mode
Definition: autopilot.c:69
#define ROLL_STICK_CENTERED()
uint8_t status
Definition: radio_control.h:53
#define LED_OFF(i)
Definition: led_hw.h:50
#define MIN_BAT_LEVEL
Definition: electrical.c:58
bool autopilot_motors_on
Definition: autopilot.c:76
#define THROTTLE_STICK_DOWN()
#define PITCH_STICK_CENTERED()
Interface for electrical status: supply voltage, current, battery status, etc.
struct RadioControl radio_control
Definition: radio_control.c:30
void led_safety_status_periodic(void)
Periodic function that makes the leds blink in the right pattern for each situation.
#define LED_TOGGLE(i)
Definition: led_hw.h:51
#define RC_REALLY_LOST
Definition: radio_control.h:50
Some helper functions to check RC sticks.
void led_safety_status_init(void)
Initialises periodic loop; place more init functions here if expanding driver.
uint16_t vsupply
supply voltage in decivolts
Definition: electrical.h:48
#define YAW_STICK_CENTERED()
arch independent LED (Light Emitting Diodes) API
#define LED_ON(i)
Definition: led_hw.h:49
Simple module to blink LEDs when battery voltage drops below a certain level, radio control is lost o...
struct Electrical electrical
Definition: electrical.c:65
#define MODE_MANUAL
Default RC mode.
Definition: autopilot.h:82