dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
geofence_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 "geofence_control.h"
38 #include "transmitter_control.h"
39 
40 #include "flightstatus.h"
41 #include "geofencesettings.h"
42 #include "stabilizationdesired.h"
43 #include "systemalarms.h"
44 #include "systemsettings.h"
45 
48 {
49  return 0;
50 }
51 
54 {
55  return 0;
56 }
57 
59 
61 int32_t geofence_control_select(bool reset_controller)
62 {
63  // This behavior is the same as the current failsafe.
64  if (reset_controller) {
65  FlightStatusArmedOptions armed;
66  FlightStatusArmedGet(&armed);
67  geofence_armed_when_enabled = (armed == FLIGHTSTATUS_ARMED_ARMED);
68  }
69 
70  uint8_t flight_status;
71  FlightStatusFlightModeGet(&flight_status);
72  if (flight_status != FLIGHTSTATUS_FLIGHTMODE_STABILIZED1 || reset_controller) {
73  flight_status = FLIGHTSTATUS_FLIGHTMODE_STABILIZED1;
74  FlightStatusFlightModeSet(&flight_status);
75  }
76 
77  SystemSettingsAirframeTypeOptions airframe_type;
78  SystemSettingsAirframeTypeGet(&airframe_type);
79 
80  // Pick default values that will roughly cause a plane to circle down
81  // and a quad to fall straight down
82  StabilizationDesiredData stabilization_desired;
83  StabilizationDesiredGet(&stabilization_desired);
84  StabilizationDesiredGet(&stabilization_desired);
85  stabilization_desired.Thrust = (airframe_type == SYSTEMSETTINGS_AIRFRAMETYPE_HELICP) ? 0 : -1;
86  stabilization_desired.Roll = 0;
87  stabilization_desired.Pitch = 0;
88  stabilization_desired.Yaw = 0;
89  stabilization_desired.ReprojectionMode = STABILIZATIONDESIRED_REPROJECTIONMODE_NONE;
90 
92  /* disable stabilization so outputs do not move when system was not armed */
93  stabilization_desired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_ROLL] = STABILIZATIONDESIRED_STABILIZATIONMODE_DISABLED;
94  stabilization_desired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_PITCH] = STABILIZATIONDESIRED_STABILIZATIONMODE_DISABLED;
95  stabilization_desired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_YAW] = STABILIZATIONDESIRED_STABILIZATIONMODE_DISABLED;
96  } else {
97  stabilization_desired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_ROLL] = STABILIZATIONDESIRED_STABILIZATIONMODE_FAILSAFE;
98  stabilization_desired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_PITCH] = STABILIZATIONDESIRED_STABILIZATIONMODE_FAILSAFE;
99  stabilization_desired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_YAW] = STABILIZATIONDESIRED_STABILIZATIONMODE_FAILSAFE;
100  }
101 
102  StabilizationDesiredSet(&stabilization_desired);
103 
104  return 0;
105 }
106 
109 {
110  // Check if the module is running
111  if (GeoFenceSettingsHandle()) {
112  uint8_t alarm_status[SYSTEMALARMS_ALARM_NUMELEM];
113  SystemAlarmsAlarmGet(alarm_status);
114 
115  if (alarm_status[SYSTEMALARMS_ALARM_GEOFENCE] == SYSTEMALARMS_ALARM_ERROR ||
116  alarm_status[SYSTEMALARMS_ALARM_GEOFENCE] == SYSTEMALARMS_ALARM_CRITICAL) {
117  return true;
118  }
119  }
120 
121  return false;
122 }
123 
Process transmitter inputs and use as control source.
Geofence controller that is enabled when out of zone.
static bool geofence_armed_when_enabled
int32_t geofence_control_update()
Perform any updates to the geofence controller.
int32_t geofence_control_select(bool reset_controller)
Use geofence control mode.
bool geofence_control_activate()
Query if out of bounds and the geofence controller should take over.
static SystemSettingsAirframeTypeOptions airframe_type
Definition: actuator.c:103
Includes PiOS and core architecture components.
int32_t geofence_control_initialize()
Initialize the geofence controller.