Paparazzi UAS  v6.0_unstable-53-gfe8bbd3-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
autopilot_arming_yaw.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 The Paparazzi Team
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 #ifndef AUTOPILOT_ARMING_YAW_H
30 #define AUTOPILOT_ARMING_YAW_H
31 
33 #include "autopilot_firmware.h"
34 #include "autopilot.h"
35 #include "mcu_periph/sys_time.h"
36 
41 #ifndef MOTOR_ARMING_DELAY
42 #define MOTOR_ARMING_DELAY 40
43 #endif
44 
45 // Allow re-arming from motors_on after RC kill within 10 seconds
46 #define MOTOR_RE_ARM_TIME 10.0
47 
60 };
61 
65 
66 
67 static inline void autopilot_arming_init(void)
68 {
71  motor_kill_time = 0;
72 }
73 
76 static inline void autopilot_arming_set(bool motors_on)
77 {
78  if (motors_on) {
83  } else {
85  }
86 }
87 
88 #define YAW_MUST_BE_CENTERED true
89 #define YAW_MUST_BE_PUSHED false
90 
96 static inline bool autopilot_arming_check_valid(bool yaw_must_be_centered)
97 {
98  if (!THROTTLE_STICK_DOWN()) {
100  } else if (!PITCH_STICK_CENTERED()) {
102  } else if (!ROLL_STICK_CENTERED()) {
104  } else {
105  if (yaw_must_be_centered && !YAW_STICK_CENTERED()) {
107  } else if (!yaw_must_be_centered && YAW_STICK_CENTERED()) {
109  } else {
110  return true; // all checks valid
111  }
112  }
113  return false; // one of the checks failed
114 }
115 
122 static inline void autopilot_arming_check_motors_on(void)
123 {
124  /* only allow switching motor if not in KILL mode */
125  if (autopilot_get_mode() != AP_MODE_KILL) {
126 
128  case STATUS_INITIALISE_RC: // Wait until RC is initialised (it being centered is a good pointer to this)
131  }
132  break;
133  case STATUS_MOTORS_RC_KILLED: // Motors were killed by kill mode
134  // If the vehicle was killed accidentally, allow rapid re-arm
137  } else {
139  autopilot.motors_on = false;
140  }
141  break;
142  case STATUS_MOTORS_AUTOMATICALLY_OFF: // Motors were disarmed externally
143  //(possibly due to crash)
144  //wait extra delay before enabling the normal arming state machine
145  autopilot.motors_on = false;
149  }
150  break;
155  } else {
157  }
158  break;
159  case STATUS_MOTORS_OFF:
160  autopilot.motors_on = false;
163  if (autopilot_arming_check_valid(YAW_MUST_BE_PUSHED)) { // stick pushed
165  }
166  break;
168  autopilot.motors_on = false;
172  } else if (!autopilot_arming_check_valid(YAW_MUST_BE_PUSHED)) { // stick released too soon
174  } else {
176  }
177  break;
178  case STATUS_START_MOTORS:
179  autopilot.motors_on = true;
181  autopilot_set_in_flight(false); // stop fc from starting control (integration and yaw) till arm process is complete
182  if (YAW_STICK_CENTERED()) { // wait until stick released
184  }
185  break;
186  case STATUS_MOTORS_ON:
188  autopilot.motors_on = true;
190  if (THROTTLE_STICK_DOWN() && YAW_STICK_PUSHED()) { // stick pushed
192  }
193  break;
195  autopilot.motors_on = true;
197  if (autopilot_motors_on_counter == 0) {
199  } else if (!(THROTTLE_STICK_DOWN() && YAW_STICK_PUSHED())) { // stick released too soon
201  } else {
203  }
204  break;
205  case STATUS_STOP_MOTORS:
206  autopilot.motors_on = false;
208  if (autopilot_arming_check_valid(YAW_MUST_BE_CENTERED)) { // wait till release disarm stick before allowing to re-arm
210  }
211  break;
212  default:
213  break;
214  }
215  } else {
217  if (kill_switch_is_on()) {
218  autopilot.motors_on = false;
219  }
220  }
221 }
222 
223 #endif /* AUTOPILOT_ARMING_YAW_H */
#define THROTTLE_STICK_DOWN()
#define YAW_MUST_BE_PUSHED
#define AP_ARMING_STATUS_ARMED
uint32_t autopilot_motors_on_counter
static void autopilot_arming_set(bool motors_on)
Update the status of the check_motors state machine.
#define YAW_MUST_BE_CENTERED
#define AP_MODE_KILL
Static autopilot modes.
Arming procedure for rotorcraft, common definitions.
float motor_kill_time
static bool kill_switch_is_on(void)
#define AP_ARMING_STATUS_ROLL_NOT_CENTERED
#define MOTOR_RE_ARM_TIME
enum arming_state autopilot_check_motor_status
static float get_sys_time_float(void)
Get the time in seconds since startup.
Definition: sys_time.h:129
#define MOTOR_ARMING_DELAY
Delay until motors are armed/disarmed.
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:50
#define AP_ARMING_STATUS_YAW_CENTERED
Architecture independent timing functions.
#define AP_ARMING_STATUS_THROTTLE_NOT_DOWN
#define AP_ARMING_STATUS_WAITING
#define ROLL_STICK_CENTERED()
static void autopilot_arming_check_motors_on(void)
State machine to check if motors should be turned ON or OFF.
uint8_t arming_status
arming status
Definition: autopilot.h:67
#define YAW_STICK_CENTERED()
#define AP_ARMING_STATUS_PITCH_NOT_CENTERED
Core autopilot interface common to all firmwares.
#define PITCH_STICK_CENTERED()
bool motors_on
motor status
Definition: autopilot.h:68
#define AP_ARMING_STATUS_KILLED
#define YAW_STICK_PUSHED()
void autopilot_set_in_flight(bool in_flight)
set in_flight flag
Definition: autopilot.c:247
#define AP_ARMING_STATUS_YAW_NOT_CENTERED
#define AP_ARMING_STATUS_DISARMING
static void autopilot_arming_init(void)
Rotorcraft specific autopilot interface and initialization.
static bool autopilot_arming_check_valid(bool yaw_must_be_centered)
Checks all arm requirements and returns true if OK and false otherwise.
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition: autopilot.c:184
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78