Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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 */
autopilot_set_in_flight
void autopilot_set_in_flight(bool in_flight)
set in_flight flag
Definition: autopilot.c:247
autopilot_arming_set
static void autopilot_arming_set(bool motors_on)
Update the status of the check_motors state machine.
Definition: autopilot_arming_yaw.h:76
YAW_MUST_BE_PUSHED
#define YAW_MUST_BE_PUSHED
Definition: autopilot_arming_yaw.h:89
autopilot_arming_init
static void autopilot_arming_init(void)
Definition: autopilot_arming_yaw.h:67
autopilot_motors_on_counter
uint32_t autopilot_motors_on_counter
Definition: autopilot_arming_yaw.h:62
STATUS_MOTORS_ON
@ STATUS_MOTORS_ON
Definition: autopilot_arming_yaw.h:57
get_sys_time_float
static float get_sys_time_float(void)
Get the time in seconds since startup.
Definition: sys_time.h:129
AP_ARMING_STATUS_WAITING
#define AP_ARMING_STATUS_WAITING
Definition: autopilot_arming_common.h:34
arming_state
arming_state
Definition: autopilot_arming_switch.h:38
uint32_t
unsigned long uint32_t
Definition: types.h:18
STATUS_STOP_MOTORS
@ STATUS_STOP_MOTORS
Definition: autopilot_arming_yaw.h:59
STATUS_MOTORS_OFF
@ STATUS_MOTORS_OFF
Definition: autopilot_arming_yaw.h:54
THROTTLE_STICK_DOWN
#define THROTTLE_STICK_DOWN()
Definition: autopilot_rc_helpers.h:40
AP_ARMING_STATUS_THROTTLE_NOT_DOWN
#define AP_ARMING_STATUS_THROTTLE_NOT_DOWN
Definition: autopilot_arming_common.h:43
AP_MODE_KILL
#define AP_MODE_KILL
Static autopilot modes.
Definition: autopilot_static.h:35
STATUS_MOTORS_AUTOMATICALLY_OFF
@ STATUS_MOTORS_AUTOMATICALLY_OFF
Definition: autopilot_arming_yaw.h:52
MOTOR_RE_ARM_TIME
#define MOTOR_RE_ARM_TIME
Definition: autopilot_arming_yaw.h:46
YAW_STICK_CENTERED
#define YAW_STICK_CENTERED()
Definition: autopilot_rc_helpers.h:45
pprz_autopilot::motors_on
bool motors_on
motor status
Definition: autopilot.h:68
YAW_MUST_BE_CENTERED
#define YAW_MUST_BE_CENTERED
Definition: autopilot_arming_yaw.h:88
autopilot
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:50
AP_ARMING_STATUS_YAW_NOT_CENTERED
#define AP_ARMING_STATUS_YAW_NOT_CENTERED
Definition: autopilot_arming_common.h:47
AP_ARMING_STATUS_KILLED
#define AP_ARMING_STATUS_KILLED
Definition: autopilot_arming_common.h:38
sys_time.h
Architecture independent timing functions.
autopilot.h
autopilot_firmware.h
AP_ARMING_STATUS_PITCH_NOT_CENTERED
#define AP_ARMING_STATUS_PITCH_NOT_CENTERED
Definition: autopilot_arming_common.h:45
AP_ARMING_STATUS_DISARMING
#define AP_ARMING_STATUS_DISARMING
Definition: autopilot_arming_common.h:37
STATUS_M_ON_STICK_PUSHED
@ STATUS_M_ON_STICK_PUSHED
Definition: autopilot_arming_yaw.h:58
autopilot_arming_check_motors_on
static void autopilot_arming_check_motors_on(void)
State machine to check if motors should be turned ON or OFF.
Definition: autopilot_arming_yaw.h:122
YAW_STICK_PUSHED
#define YAW_STICK_PUSHED()
Definition: autopilot_rc_helpers.h:42
AP_ARMING_STATUS_YAW_CENTERED
#define AP_ARMING_STATUS_YAW_CENTERED
Definition: autopilot_arming_common.h:39
AP_ARMING_STATUS_ARMED
#define AP_ARMING_STATUS_ARMED
Definition: autopilot_arming_common.h:36
kill_switch_is_on
static bool kill_switch_is_on(void)
Definition: autopilot_rc_helpers.h:97
autopilot_arming_check_valid
static bool autopilot_arming_check_valid(bool yaw_must_be_centered)
Checks all arm requirements and returns true if OK and false otherwise.
Definition: autopilot_arming_yaw.h:96
PITCH_STICK_CENTERED
#define PITCH_STICK_CENTERED()
Definition: autopilot_rc_helpers.h:48
STATUS_INITIALISE_RC
@ STATUS_INITIALISE_RC
Definition: autopilot_arming_yaw.h:50
MOTOR_ARMING_DELAY
#define MOTOR_ARMING_DELAY
Delay until motors are armed/disarmed.
Definition: autopilot_arming_yaw.h:42
STATUS_START_MOTORS
@ STATUS_START_MOTORS
Definition: autopilot_arming_yaw.h:56
ROLL_STICK_CENTERED
#define ROLL_STICK_CENTERED()
Definition: autopilot_rc_helpers.h:51
autopilot_check_motor_status
enum arming_state autopilot_check_motor_status
Definition: autopilot_arming_yaw.h:63
AP_ARMING_STATUS_ROLL_NOT_CENTERED
#define AP_ARMING_STATUS_ROLL_NOT_CENTERED
Definition: autopilot_arming_common.h:46
autopilot_get_mode
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition: autopilot.c:184
autopilot_arming_common.h
STATUS_M_OFF_STICK_PUSHED
@ STATUS_M_OFF_STICK_PUSHED
Definition: autopilot_arming_yaw.h:55
STATUS_MOTORS_RC_KILLED
@ STATUS_MOTORS_RC_KILLED
Definition: autopilot_arming_yaw.h:51
STATUS_MOTORS_AUTOMATICALLY_OFF_SAFETY_WAIT
@ STATUS_MOTORS_AUTOMATICALLY_OFF_SAFETY_WAIT
Definition: autopilot_arming_yaw.h:53
pprz_autopilot::arming_status
uint8_t arming_status
arming status
Definition: autopilot.h:67
motor_kill_time
float motor_kill_time
Definition: autopilot_arming_yaw.h:64