dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
failsafe_control.c
Go to the documentation of this file.
1 
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  *
30  * Additional note on redistribution: The copyright and license notices above
31  * must be maintained in each individual source file that is a derivative work
32  * of this source file; otherwise redistribution is prohibited.
33  */
34 
35 #include "openpilot.h"
36 #include "control.h"
37 #include "failsafe_control.h"
38 #include "transmitter_control.h"
39 
40 #include "flightstatus.h"
41 #include "stabilizationdesired.h"
42 #include "systemsettings.h"
43 
46 {
47  return 0;
48 }
49 
52 {
53  return 0;
54 }
55 
56 static bool armed_when_enabled;
61 int32_t failsafe_control_select(bool reset_controller)
62 {
63  if (reset_controller) {
64  FlightStatusArmedOptions armed;
65  FlightStatusArmedGet(&armed);
66  armed_when_enabled = (armed == FLIGHTSTATUS_ARMED_ARMED);
67  }
68 
69  uint8_t flight_status;
70  FlightStatusFlightModeGet(&flight_status);
71  if (flight_status != FLIGHTSTATUS_FLIGHTMODE_FAILSAFE || reset_controller) {
72  flight_status = FLIGHTSTATUS_FLIGHTMODE_FAILSAFE;
73  FlightStatusFlightModeSet(&flight_status);
74  }
75 
76  SystemSettingsAirframeTypeOptions airframe_type;
77  SystemSettingsAirframeTypeGet(&airframe_type);
78 
79  StabilizationDesiredData stabilization_desired = {};
80  stabilization_desired.Thrust = 0;
81  stabilization_desired.Roll = 0;
82  stabilization_desired.Pitch = 0;
83  stabilization_desired.Yaw = 0;
84 
85  stabilization_desired.ReprojectionMode = STABILIZATIONDESIRED_REPROJECTIONMODE_NONE;
86  stabilization_desired.ThrustMode = STABILIZATIONDESIRED_THRUSTMODE_DIRECT;
87 
88  if (!armed_when_enabled) {
89  /* disable stabilization so outputs do not move when system was not armed */
90  stabilization_desired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_ROLL] = STABILIZATIONDESIRED_STABILIZATIONMODE_DISABLED;
91  stabilization_desired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_PITCH] = STABILIZATIONDESIRED_STABILIZATIONMODE_DISABLED;
92  stabilization_desired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_YAW] = STABILIZATIONDESIRED_STABILIZATIONMODE_DISABLED;
93  } else {
94  stabilization_desired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_ROLL] = STABILIZATIONDESIRED_STABILIZATIONMODE_FAILSAFE;
95  stabilization_desired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_PITCH] = STABILIZATIONDESIRED_STABILIZATIONMODE_FAILSAFE;
96  stabilization_desired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_YAW] = STABILIZATIONDESIRED_STABILIZATIONMODE_FAILSAFE;
97  }
98 
99  StabilizationDesiredSet(&stabilization_desired);
100 
101  return 0;
102 }
103 
Process transmitter inputs and use as control source.
int32_t failsafe_control_select(bool reset_controller)
Use failsafe mode.
int32_t failsafe_control_update()
Perform any updates to the failsafe controller.
Failsafe controller when transmitter control is lost.
static SystemSettingsAirframeTypeOptions airframe_type
Definition: actuator.c:103
Includes PiOS and core architecture components.
int32_t failsafe_control_initialize()
Initialize the failsafe controller.
static bool armed_when_enabled