Paparazzi UAS  v5.15_devel-164-g81d4ceb
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"
34 #include "autopilot_rc_helpers.h"
35 
37 
38 #ifndef SAFETY_WARNING_LED
39 #error You must define SAFETY_WARNING_LED to use this module!
40 #else
41 
42 void led_safety_status_init(void)
43 {
44  LED_ON(SAFETY_WARNING_LED);
46 }
47 
49 {
51  RunXTimesEvery(0, 60, 5, 7, {LED_TOGGLE(SAFETY_WARNING_LED);});
52  RunXTimesEvery(130, 130, 10, 6, {LED_TOGGLE(SAFETY_WARNING_LED);});
53  } else if (!(autopilot_get_mode() == MODE_MANUAL) && !autopilot_get_motors_on()) {
54  RunXTimesEvery(20, 240, 40, 1, {LED_ON(SAFETY_WARNING_LED);});
55  RunXTimesEvery(0, 240, 40, 1, {LED_OFF(SAFETY_WARNING_LED);});
56  } else if (!THROTTLE_STICK_DOWN() && !autopilot_get_motors_on()) {
57  RunXTimesEvery(20, 240, 40, 2, {LED_ON(SAFETY_WARNING_LED);});
58  RunXTimesEvery(0, 240, 40, 2, {LED_OFF(SAFETY_WARNING_LED);});
59  } else if (!ROLL_STICK_CENTERED() && !autopilot_get_motors_on()) {
60  RunXTimesEvery(20, 240, 40, 3, {LED_ON(SAFETY_WARNING_LED);});
61  RunXTimesEvery(0, 240, 40, 3, {LED_OFF(SAFETY_WARNING_LED);});
62  } else if (!PITCH_STICK_CENTERED() && !autopilot_get_motors_on()) {
63  RunXTimesEvery(20, 240, 40, 4, {LED_ON(SAFETY_WARNING_LED);});
64  RunXTimesEvery(0, 240, 40, 4, {LED_OFF(SAFETY_WARNING_LED);});
65  } else if (!YAW_STICK_CENTERED() && !autopilot_get_motors_on()) {
66  RunXTimesEvery(20, 240, 40, 5, {LED_ON(SAFETY_WARNING_LED);});
67  RunXTimesEvery(0, 240, 40, 5, {LED_OFF(SAFETY_WARNING_LED);});
68  }
69 #ifdef LOW_BAT_LEVEL
70  else if (electrical.vsupply < LOW_BAT_LEVEL) {
71  RunOnceEvery(20, {LED_TOGGLE(SAFETY_WARNING_LED);});
72  } else if (electrical.vsupply < (LOW_BAT_LEVEL + 0.5)) {
73  RunXTimesEvery(0, 300, 10, 10, {LED_TOGGLE(SAFETY_WARNING_LED);});
74  }
75 #endif
76  else {
77  LED_ON(SAFETY_WARNING_LED);
78  }
79 }
80 #endif
#define THROTTLE_STICK_DOWN()
#define RC_LOST
Definition: radio_control.h:57
bool autopilot_get_motors_on(void)
get motors status
Definition: autopilot.c:212
uint8_t status
Definition: radio_control.h:64
#define LED_OFF(i)
Definition: led_hw.h:52
#define LOW_BAT_LEVEL
low battery level in Volts (for 3S LiPo)
Definition: electrical.h:36
float vsupply
supply voltage in V
Definition: electrical.h:45
#define MODE_MANUAL
Default RC mode.
Interface for electrical status: supply voltage, current, battery status, etc.
struct RadioControl radio_control
Definition: radio_control.c:30
#define ROLL_STICK_CENTERED()
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:53
#define RC_REALLY_LOST
Definition: radio_control.h:58
#define YAW_STICK_CENTERED()
Core autopilot interface common to all firmwares.
void led_safety_status_init(void)
Initialises periodic loop; place more init functions here if expanding driver.
#define PITCH_STICK_CENTERED()
arch independent LED (Light Emitting Diodes) API
#define LED_ON(i)
Definition: led_hw.h:51
Simple module to blink LEDs when battery voltage drops below a certain level, radio control is lost o...
struct Electrical electrical
Definition: electrical.c:66
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition: autopilot.c:184