Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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_PORT,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 }
BTN_ESTOP_PIN
#define BTN_ESTOP_PIN
Definition: opa_ftd_1.0.h:66
uint16_t
unsigned short uint16_t
Definition: types.h:16
BTN_ON_PIN
#define BTN_ON_PIN
Definition: opa_ftd_1.0.h:74
intermcu.h
Rotorcraft Inter-MCU interface.
opa_controller_fbw.h
AP_PWR_PIN
#define AP_PWR_PIN
Definition: opa_ftd_1.0.h:44
BTN_ESTOP
#define BTN_ESTOP
Definition: opa_ftd_1.0.h:65
LED_OFF
#define LED_OFF(i)
Definition: led_hw.h:52
MAIN_PWR_OFF
#define MAIN_PWR_OFF
Definition: opa_ftd_1.0.h:52
MCU_PWR
#define MCU_PWR
Definition: opa_ftd_1.0.h:37
autopilot_motors_on
bool autopilot_motors_on
Definition: intermcu_fbw.c:64
INTERMCU_CLR_CMD_STATUS
#define INTERMCU_CLR_CMD_STATUS(_bit)
Definition: intermcu.h:66
MCU_PWR_OFF
#define MCU_PWR_OFF
Definition: opa_ftd_1.0.h:40
gpio_setup_output
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
LED_ON
#define LED_ON(i)
Definition: led_hw.h:51
RADIO_CONTROL_POWER_OFF
#define RADIO_CONTROL_POWER_OFF
Definition: opa_ftd_1.0.h:152
OFF_TIMER
#define OFF_TIMER
Definition: opa_controller_fbw.c:32
opa_controller_init
void opa_controller_init(void)
Definition: opa_controller_fbw.c:41
BAL_PWR_ON
#define BAL_PWR_ON
Definition: opa_ftd_1.0.h:57
MAIN_PWR
#define MAIN_PWR
Definition: opa_ftd_1.0.h:49
gpio_setup_input
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
opa_controller_disarm
bool opa_controller_disarm
Definition: opa_controller_fbw.c:38
BAL_PWR_OFF
#define BAL_PWR_OFF
Definition: opa_ftd_1.0.h:58
BAL_PWR
#define BAL_PWR
Definition: opa_ftd_1.0.h:55
BTN_ON
#define BTN_ON
Definition: opa_ftd_1.0.h:73
BAL_PWR_PIN
#define BAL_PWR_PIN
Definition: opa_ftd_1.0.h:56
BTN_ARMING
#define BTN_ARMING
Definition: opa_ftd_1.0.h:69
opa_controller_periodic
void opa_controller_periodic(void)
Definition: opa_controller_fbw.c:65
MAIN_PWR_PIN
#define MAIN_PWR_PIN
Definition: opa_ftd_1.0.h:50
led.h
arch independent LED (Light Emitting Diodes) API
AP_PWR_OFF
#define AP_PWR_OFF
Definition: opa_ftd_1.0.h:46
INTERMCU_GET_CMD_STATUS
#define INTERMCU_GET_CMD_STATUS(_bit)
Definition: intermcu.h:67
gpio_get
static uint8_t gpio_get(ioportid_t port, uint16_t pin)
Get level of a gpio.
Definition: gpio_arch.h:88
RADIO_CONTROL_POWER_PIN
#define RADIO_CONTROL_POWER_PIN
Definition: opa_ftd_1.0.h:150
MAIN_PWR_ON
#define MAIN_PWR_ON
Definition: opa_ftd_1.0.h:51
gpio.h
arming_led
static bool arming_led
Definition: opa_controller_fbw.c:36
MCU_PWR_PIN
#define MCU_PWR_PIN
Definition: opa_ftd_1.0.h:38
AP_PWR_ON
#define AP_PWR_ON
Definition: opa_ftd_1.0.h:45
RADIO_CONTROL_POWER_PORT
#define RADIO_CONTROL_POWER_PORT
Definition: opa_ftd_1.0.h:149
MIN_ARMING_TRIG
#define MIN_ARMING_TRIG
Definition: opa_controller_fbw.c:33
AP_PWR
#define AP_PWR
Definition: opa_ftd_1.0.h:43
BTN_ARMING_PIN
#define BTN_ARMING_PIN
Definition: opa_ftd_1.0.h:70
INTERMCU_CMD_DISARM
@ INTERMCU_CMD_DISARM
Whether or not to dis-arm the FBW.
Definition: intermcu.h:59