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
opa_controller_fbw.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) Freek van Tienen <freek.v.tienen@gmail.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, see
18  * <http://www.gnu.org/licenses/>.
19  */
27 #include "subsystems/intermcu.h"
28 #include "generated/airframe.h"
29 #include "mcu_periph/gpio.h"
30 #include "led.h"
31 
32 #define OFF_TIMER 5*1 // FIXME: make nicer
33 #define MIN_ARMING_TRIG 1*1 //FIXME: make nicer
34 
35 /* Whether the autopilot arming LED is on */
36 static bool arming_led = false;
37 extern bool autopilot_motors_on;
38 bool opa_controller_disarm = false;
39 
40 
41 void opa_controller_init(void) {
42  /* Setup E-Stop, Arming and On/Off button as input */
46 
47  /* Enable Autopilot power */
50 
51  /* Enable Main power (25V) */
54 
55  /* Enable Balancer power */
58 
59 #if defined ARMING_LED
60  /* Disable the arming LED */
61  LED_OFF(ARMING_LED);
62 #endif
63 }
64 
66  static uint16_t off_cnt = 0;
67  static uint16_t arming_cnt = 0;
68 
69  /* Check E-Stop and power off Main power if pressed */
76  arming_led = false;
77  return;
78  }
79 
80  /* AP soft disarm */
84  arming_led = false;
86  }
87 
88  /* Check On/Off button and disable if pressed for 3 seconds */
89  if(gpio_get(BTN_ON, BTN_ON_PIN)) {
90  if(off_cnt >= OFF_TIMER) {
93  arming_led = false;
94  } else {
95  off_cnt++;
96  }
97  }
98  else {
99  off_cnt = 0;
100  }
101 
102  /* Check Arming button and set LED */
104  if (arming_cnt >= MIN_ARMING_TRIG) {
105  arming_led = true;
108  //AP_PWR_ON(AP_PWR, AP_PWR_PIN);
109  //RADIO_CONTROL_POWER_ON(RADIO_CONTROL_POWER,RADIO_CONTROL_POWER_PIN);
110  } else {
111  arming_cnt++;
112  }
113  }
114  else {
115  arming_cnt = 0;
116  }
117 
118 #if defined ARMING_LED
119  /* Update Arming LED */
120  if (arming_led) {
121  LED_OFF(ARMING_LED);
122  } else {
123  LED_ON(ARMING_LED);
124  }
125  // autopilot_motors_on;
126 #endif
127 }
unsigned short uint16_t
Definition: types.h:16
#define MCU_PWR_OFF
Definition: opa_ftd_1.0.h:40
#define MAIN_PWR_ON
Definition: opa_ftd_1.0.h:51
#define RADIO_CONTROL_POWER_OFF
Definition: opa_ftd_1.0.h:152
#define RADIO_CONTROL_POWER
Definition: opa_ftd_1.0.h:149
#define MCU_PWR
Definition: opa_ftd_1.0.h:37
#define MAIN_PWR_OFF
Definition: opa_ftd_1.0.h:52
#define LED_OFF(i)
Definition: led_hw.h:50
Some architecture independent helper functions for GPIOs.
bool autopilot_motors_on
Definition: autopilot.c:76
#define MAIN_PWR
Definition: opa_ftd_1.0.h:49
#define BAL_PWR
Definition: opa_ftd_1.0.h:55
#define BTN_ARMING_PIN
Definition: opa_ftd_1.0.h:70
#define MCU_PWR_PIN
Definition: opa_ftd_1.0.h:38
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
Definition: gpio_arch.c:33
static bool arming_led
#define OFF_TIMER
#define RADIO_CONTROL_POWER_PIN
Definition: opa_ftd_1.0.h:150
#define BTN_ON
Definition: opa_ftd_1.0.h:73
#define BTN_ARMING
Definition: opa_ftd_1.0.h:69
#define MIN_ARMING_TRIG
#define BAL_PWR_ON
Definition: opa_ftd_1.0.h:57
void opa_controller_periodic(void)
Rotorcraft Inter-MCU interface.
#define INTERMCU_GET_CMD_STATUS(_bit)
Definition: intermcu.h:65
#define BTN_ESTOP_PIN
Definition: opa_ftd_1.0.h:66
void opa_controller_init(void)
#define BAL_PWR_OFF
Definition: opa_ftd_1.0.h:58
#define INTERMCU_CLR_CMD_STATUS(_bit)
Definition: intermcu.h:64
static uint8_t gpio_get(ioportid_t port, uint16_t pin)
Get level of a gpio.
Definition: gpio_arch.h:83
#define AP_PWR
Definition: opa_ftd_1.0.h:43
#define AP_PWR_OFF
Definition: opa_ftd_1.0.h:46
arch independent LED (Light Emitting Diodes) API
#define LED_ON(i)
Definition: led_hw.h:49
#define AP_PWR_PIN
Definition: opa_ftd_1.0.h:44
bool opa_controller_disarm
#define AP_PWR_ON
Definition: opa_ftd_1.0.h:45
void gpio_setup_input(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs.
Definition: gpio_arch.c:40
Whether or not to dis-arm the FBW.
Definition: intermcu.h:59
#define BTN_ON_PIN
Definition: opa_ftd_1.0.h:74
#define BAL_PWR_PIN
Definition: opa_ftd_1.0.h:56
#define BTN_ESTOP
Definition: opa_ftd_1.0.h:65
#define MAIN_PWR_PIN
Definition: opa_ftd_1.0.h:50