36 #include "flightstatus.h"
38 #include "manualcontrolsettings.h"
39 #include "stabilizationsettings.h"
40 #include "stateestimation.h"
41 #include "systemalarms.h"
42 #include "systemsettings.h"
43 #include "systemident.h"
67 if (SystemIdentHandle()) {
71 if (si.Beta[SYSTEMIDENT_BETA_ROLL] < 6 || si.Tau[SYSTEMIDENT_TAU_ROLL] < 0.001f ||
72 si.Beta[SYSTEMIDENT_BETA_PITCH] < 6 || si.Tau[SYSTEMIDENT_TAU_PITCH] < 0.001f ||
73 si.Beta[SYSTEMIDENT_BETA_YAW] < 6 || si.Tau[SYSTEMIDENT_TAU_YAW] < 0.001f) {
86 SystemAlarmsConfigErrorOptions error_code = SYSTEMALARMS_CONFIGERROR_NONE;
90 if (ManualControlSettingsHandle() == NULL ||
91 SystemSettingsHandle() == NULL) {
92 AlarmsSet(SYSTEMALARMS_ALARM_SYSTEMCONFIGURATION, SYSTEMALARMS_ALARM_CRITICAL);
97 bool multirotor =
true;
99 SystemSettingsAirframeTypeGet(&airframe_type);
100 switch(airframe_type) {
101 case SYSTEMSETTINGS_AIRFRAMETYPE_QUADX:
102 case SYSTEMSETTINGS_AIRFRAMETYPE_QUADP:
103 case SYSTEMSETTINGS_AIRFRAMETYPE_HEXA:
104 case SYSTEMSETTINGS_AIRFRAMETYPE_OCTO:
105 case SYSTEMSETTINGS_AIRFRAMETYPE_HEXAX:
106 case SYSTEMSETTINGS_AIRFRAMETYPE_OCTOV:
107 case SYSTEMSETTINGS_AIRFRAMETYPE_OCTOCOAXP:
108 case SYSTEMSETTINGS_AIRFRAMETYPE_HEXACOAX:
109 case SYSTEMSETTINGS_AIRFRAMETYPE_TRI:
119 uint8_t modes[MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_NUMELEM];
120 ManualControlSettingsFlightModeNumberGet(&num_modes);
121 ManualControlSettingsFlightModePositionGet(modes);
123 for(uint32_t
i = 0;
i < num_modes;
i++) {
125 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_MANUAL:
127 error_code = SYSTEMALARMS_CONFIGERROR_STABILIZATION;
130 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_ACRO:
131 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_ACROPLUS:
132 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_ACRODYNE:
133 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_LEVELING:
134 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_HORIZON:
135 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_AXISLOCK:
136 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_VIRTUALBAR:
137 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_FLIPREVERSED:
138 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_FAILSAFE:
141 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_LQG:
142 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_LQGLEVELING:
144 error_code = SYSTEMALARMS_CONFIGERROR_LQG;
147 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED1:
150 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED2:
153 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED3:
156 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_AUTOTUNE:
158 error_code = SYSTEMALARMS_CONFIGERROR_AUTOTUNE;
161 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_ALTITUDEHOLD:
163 error_code = SYSTEMALARMS_CONFIGERROR_ALTITUDEHOLD;
166 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_POSITIONHOLD:
167 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_RETURNTOHOME:
169 error_code = SYSTEMALARMS_CONFIGERROR_PATHPLANNER;
174 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_PATHPLANNER:
175 case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_TABLETCONTROL:
178 error_code = SYSTEMALARMS_CONFIGERROR_PATHPLANNER;
185 error_code = SYSTEMALARMS_CONFIGERROR_UNDEFINED;
193 error_code = (error_code == SYSTEMALARMS_CONFIGERROR_NONE) ?
check_safe_to_arm() : error_code;
201 DONT_BUILD_IF(MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_NUMELEM != MANUALCONTROLSETTINGS_STABILIZATION2SETTINGS_NUMELEM, StabSettingsNumElem);
202 DONT_BUILD_IF(MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_NUMELEM != MANUALCONTROLSETTINGS_STABILIZATION3SETTINGS_NUMELEM, StabSettingsNumElem2);
212 uint8_t modes[MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_NUMELEM];
218 ManualControlSettingsStabilization1SettingsGet(modes);
219 ManualControlSettingsStabilization1ThrustGet(&thrust_mode);
222 ManualControlSettingsStabilization2SettingsGet(modes);
223 ManualControlSettingsStabilization2ThrustGet(&thrust_mode);
226 ManualControlSettingsStabilization3SettingsGet(modes);
227 ManualControlSettingsStabilization3ThrustGet(&thrust_mode);
230 return SYSTEMALARMS_CONFIGERROR_NONE;
235 (thrust_mode != MANUALCONTROLSETTINGS_STABILIZATION1THRUST_FLIPOVERMODE) &&
236 (thrust_mode != MANUALCONTROLSETTINGS_STABILIZATION1THRUST_FLIPOVERMODETHRUSTREVERSED)) {
238 if ((modes[
i] == MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_DISABLED || modes[
i] == MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_MANUAL))
239 return SYSTEMALARMS_CONFIGERROR_MULTIROTOR;
243 if ((thrust_mode == SHAREDDEFS_THRUSTMODESTABBANK_ALTITUDEWITHSTICKSCALING) &&
245 return SYSTEMALARMS_CONFIGERROR_ALTITUDEHOLD;
252 if ((modes[
i] == MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_SYSTEMIDENT) &&
254 return SYSTEMALARMS_CONFIGERROR_AUTOTUNE;
258 if (modes[
i] == MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_LQG ||
259 modes[
i] == MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_ATTITUDELQG) {
261 return SYSTEMALARMS_CONFIGERROR_LQG;
266 if (modes[MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_ROLL] == MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_POI ||
267 modes[MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_PITCH] == MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_POI)
268 return SYSTEMALARMS_CONFIGERROR_STABILIZATION;
269 if (modes[MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_YAW] == MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_POI) {
270 #if !defined(CAMERASTAB_POI_MODE)
271 return SYSTEMALARMS_CONFIGERROR_STABILIZATION;
281 return SYSTEMALARMS_CONFIGERROR_NONE;
295 FlightStatusData flightStatus;
296 FlightStatusGet(&flightStatus);
299 if (flightStatus.Armed != FLIGHTSTATUS_ARMED_ARMED) {
300 switch (flightStatus.FlightMode) {
301 case FLIGHTSTATUS_FLIGHTMODE_MANUAL:
302 case FLIGHTSTATUS_FLIGHTMODE_ACRO:
303 case FLIGHTSTATUS_FLIGHTMODE_ACROPLUS:
304 case FLIGHTSTATUS_FLIGHTMODE_ACRODYNE:
305 case FLIGHTSTATUS_FLIGHTMODE_LEVELING:
306 case FLIGHTSTATUS_FLIGHTMODE_HORIZON:
307 case FLIGHTSTATUS_FLIGHTMODE_AXISLOCK:
308 case FLIGHTSTATUS_FLIGHTMODE_VIRTUALBAR:
309 case FLIGHTSTATUS_FLIGHTMODE_STABILIZED1:
310 case FLIGHTSTATUS_FLIGHTMODE_STABILIZED2:
311 case FLIGHTSTATUS_FLIGHTMODE_STABILIZED3:
312 case FLIGHTSTATUS_FLIGHTMODE_ALTITUDEHOLD:
313 case FLIGHTSTATUS_FLIGHTMODE_FLIPREVERSED:
315 case FLIGHTSTATUS_FLIGHTMODE_LQG:
316 case FLIGHTSTATUS_FLIGHTMODE_LQGLEVELING:
318 return SYSTEMALARMS_CONFIGERROR_LQG;
322 case FLIGHTSTATUS_FLIGHTMODE_FAILSAFE:
330 return SYSTEMALARMS_CONFIGERROR_UNSAFETOARM;
334 return SYSTEMALARMS_CONFIGERROR_NONE;
352 StateEstimationGet(&stateEstimation);
354 if (stateEstimation.AttitudeFilter == STATEESTIMATION_ATTITUDEFILTER_INSINDOOR)
355 return SYSTEMALARMS_CONFIGERROR_NAVFILTER;
358 if (stateEstimation.NavigationFilter != STATEESTIMATION_NAVIGATIONFILTER_INS &&
359 stateEstimation.NavigationFilter != STATEESTIMATION_NAVIGATIONFILTER_RAW)
360 return SYSTEMALARMS_CONFIGERROR_NAVFILTER;
362 return SYSTEMALARMS_CONFIGERROR_NONE;
372 const float MAXIMUM_SAFE_FRACTIONAL_RATE = 0.85;
376 StabilizationSettingsManualRateGet(rates);
377 if (rates[0] > max_safe_rate || rates[1] > max_safe_rate || rates[2] > max_safe_rate)
378 return SYSTEMALARMS_CONFIGERROR_STABILIZATION;
380 StabilizationSettingsMaximumRateGet(rates);
381 if (rates[0] > max_safe_rate || rates[1] > max_safe_rate || rates[2] > max_safe_rate)
382 return SYSTEMALARMS_CONFIGERROR_STABILIZATION;
384 return SYSTEMALARMS_CONFIGERROR_NONE;
394 SystemAlarmsAlarmOptions severity;
396 static bool sticky =
false;
401 switch (error_code) {
402 case SYSTEMALARMS_CONFIGERROR_NONE:
403 severity = SYSTEMALARMS_ALARM_OK;
406 error_code = SYSTEMALARMS_CONFIGERROR_UNDEFINED;
409 case SYSTEMALARMS_CONFIGERROR_DUPLICATEPORTCFG:
412 case SYSTEMALARMS_CONFIGERROR_AUTOTUNE:
413 case SYSTEMALARMS_CONFIGERROR_ALTITUDEHOLD:
414 case SYSTEMALARMS_CONFIGERROR_MULTIROTOR:
415 case SYSTEMALARMS_CONFIGERROR_NAVFILTER:
416 case SYSTEMALARMS_CONFIGERROR_PATHPLANNER:
417 case SYSTEMALARMS_CONFIGERROR_POSITIONHOLD:
418 case SYSTEMALARMS_CONFIGERROR_STABILIZATION:
419 case SYSTEMALARMS_CONFIGERROR_UNDEFINED:
420 case SYSTEMALARMS_CONFIGERROR_UNSAFETOARM:
421 case SYSTEMALARMS_CONFIGERROR_LQG:
422 severity = SYSTEMALARMS_ALARM_ERROR;
427 SystemAlarmsConfigErrorOptions current_error_code;
428 SystemAlarmsConfigErrorGet((uint8_t *) ¤t_error_code);
429 if (current_error_code != error_code) {
430 SystemAlarmsConfigErrorSet((uint8_t *) &error_code);
434 AlarmsSet(SYSTEMALARMS_ALARM_SYSTEMCONFIGURATION, (uint8_t) severity);
bool TaskMonitorQueryRunning(TaskInfoRunningElem task)
int32_t PIOS_SENSORS_GetMaxGyro()
Get the maximum gyro rate in deg/s.
DONT_BUILD_IF(MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_NUMELEM!=MANUALCONTROLSETTINGS_STABILIZATION2SETTINGS_NUMELEM, StabSettingsNumElem)
bool PIOS_Modules_IsEnabled(enum pios_modules module)
static int32_t check_safe_autonomous()
Check the system is safe for autonomous flight.
static StateEstimationData stateEstimation
static int32_t check_stabilization_settings(int index, bool multirotor)
Check a stabilization mode switch position for safety.
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
void set_config_error(SystemAlarmsConfigErrorOptions error_code)
Utilities to validate a flight configuration.
static int32_t check_stabilization_rates()
Check a stabilization mode switch position for safety.
bool PIOS_SENSORS_IsRegistered(enum pios_sensor_type type)
Checks if a sensor type is registered with the PIOS_SENSORS interface.
int32_t configuration_check()
bool lqg_sysident_check()
static int32_t check_safe_to_arm()
Check it is safe to arm in this position.
static SystemSettingsAirframeTypeOptions airframe_type
Includes PiOS and core architecture components.
Generic interface for sensors.