Paparazzi UAS  v5.15_devel-230-gc96ce27
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 
32 #include "autopilot_rc_helpers.h"
33 #include "autopilot_firmware.h"
34 #include "autopilot.h"
35 
40 #ifndef MOTOR_ARMING_DELAY
41 #define MOTOR_ARMING_DELAY 40
42 #endif
43 
55 };
56 
59 
60 
61 static inline void autopilot_arming_init(void)
62 {
65 }
66 
67 
70 static inline void autopilot_arming_set(bool motors_on)
71 {
72  if (motors_on) {
74  } else {
76  }
77 }
78 
79 #define YAW_MUST_BE_CENTERED true
80 #define YAW_MUST_BE_PUSHED false
81 
87 static inline bool autopilot_arming_check_valid(bool yaw_must_be_centered)
88 {
89  if (!THROTTLE_STICK_DOWN()) {
91  } else if (!PITCH_STICK_CENTERED()) {
93  } else if (!ROLL_STICK_CENTERED()) {
95  } else {
96  if (yaw_must_be_centered && !YAW_STICK_CENTERED()) {
98  } else if (!yaw_must_be_centered && YAW_STICK_CENTERED()) {
100  } else {
101  return true; // all checks valid
102  }
103  }
104  return false; // one of the checks failed
105 }
106 
113 static inline void autopilot_arming_check_motors_on(void)
114 {
115  /* only allow switching motor if not in KILL mode */
116  if (autopilot_get_mode() != AP_MODE_KILL) {
117 
119  case STATUS_INITIALISE_RC: // Wait until RC is initialised (it being centered is a good pointer to this)
122  }
123  break;
124  case STATUS_MOTORS_AUTOMATICALLY_OFF: // Motors were disarmed externally
125  //(possibly due to crash)
126  //wait extra delay before enabling the normal arming state machine
127  autopilot.motors_on = false;
131  }
132  break;
137  } else {
139  }
140  break;
141  case STATUS_MOTORS_OFF:
142  autopilot.motors_on = false;
145  if (autopilot_arming_check_valid(YAW_MUST_BE_PUSHED)) { // stick pushed
147  }
148  break;
150  autopilot.motors_on = false;
154  } else if (!autopilot_arming_check_valid(YAW_MUST_BE_PUSHED)) { // stick released too soon
156  } else {
158  }
159  break;
160  case STATUS_START_MOTORS:
161  autopilot.motors_on = true;
163  autopilot_set_in_flight(false); // stop fc from starting control (integration and yaw) till arm process is complete
164  if (YAW_STICK_CENTERED()) { // wait until stick released
166  }
167  break;
168  case STATUS_MOTORS_ON:
170  autopilot.motors_on = true;
172  if (THROTTLE_STICK_DOWN() && YAW_STICK_PUSHED()) { // stick pushed
174  }
175  break;
177  autopilot.motors_on = true;
179  if (autopilot_motors_on_counter == 0) {
181  } else if (!(THROTTLE_STICK_DOWN() && YAW_STICK_PUSHED())) { // stick released too soon
183  } else {
185  }
186  break;
187  case STATUS_STOP_MOTORS:
188  autopilot.motors_on = false;
190  if (autopilot_arming_check_valid(YAW_MUST_BE_CENTERED)) { // wait till release disarm stick before allowing to re-arm
192  }
193  break;
194  default:
195  break;
196  }
197  } else {
199  }
200 }
201 
202 #endif /* AUTOPILOT_ARMING_YAW_H */
#define THROTTLE_STICK_DOWN()
#define AP_ARMING_STATUS_PITCH_NOT_CENTERED
#define YAW_MUST_BE_PUSHED
uint32_t autopilot_motors_on_counter
static void autopilot_arming_set(bool motors_on)
Update the status of the check_motors state machine.
#define AP_ARMING_STATUS_YAW_CENTERED
#define YAW_MUST_BE_CENTERED
#define AP_MODE_KILL
Static autopilot modes.
#define AP_ARMING_STATUS_DISARMING
enum arming_state autopilot_check_motor_status
#define MOTOR_ARMING_DELAY
Delay until motors are armed/disarmed.
#define AP_ARMING_STATUS_THROTTLE_NOT_DOWN
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:50
#define AP_ARMING_STATUS_WAITING
Some helper functions to check RC sticks.
unsigned long uint32_t
Definition: types.h:18
#define AP_ARMING_STATUS_ARMED
#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()
Core autopilot interface common to all firmwares.
#define PITCH_STICK_CENTERED()
bool motors_on
motor status
Definition: autopilot.h:68
#define AP_ARMING_STATUS_YAW_NOT_CENTERED
#define YAW_STICK_PUSHED()
#define AP_ARMING_STATUS_ROLL_NOT_CENTERED
void autopilot_set_in_flight(bool in_flight)
set in_flight flag
Definition: autopilot.c:247
#define AP_ARMING_STATUS_KILLED
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