2012-10-25 19:43:56 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @addtogroup OpenPilot System OpenPilot System
|
|
|
|
* @{
|
|
|
|
* @addtogroup OpenPilot Libraries OpenPilot System Libraries
|
|
|
|
* @{
|
|
|
|
* @file sanitycheck.c
|
2016-06-04 21:02:36 +02:00
|
|
|
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
|
|
|
|
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
2012-10-25 19:43:56 +02:00
|
|
|
* @brief Utilities to validate a flight configuration
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2013-04-01 16:41:12 +02:00
|
|
|
#include <openpilot.h>
|
2012-10-25 21:41:59 +02:00
|
|
|
#include <pios_board_info.h>
|
2013-04-01 16:41:12 +02:00
|
|
|
|
|
|
|
// Private includes
|
|
|
|
#include "inc/sanitycheck.h"
|
|
|
|
|
|
|
|
// UAVOs
|
|
|
|
#include <manualcontrolsettings.h>
|
2014-02-09 19:33:29 +01:00
|
|
|
#include <flightmodesettings.h>
|
2013-04-01 16:41:12 +02:00
|
|
|
#include <systemsettings.h>
|
2015-01-08 03:20:47 +01:00
|
|
|
#include <stabilizationsettings.h>
|
2014-01-12 21:37:40 +01:00
|
|
|
#include <systemalarms.h>
|
2014-06-01 12:17:42 +02:00
|
|
|
#include <revosettings.h>
|
2014-06-18 21:29:55 +02:00
|
|
|
#include <positionstate.h>
|
2013-05-02 23:31:14 +02:00
|
|
|
#include <taskinfo.h>
|
2012-10-25 21:41:59 +02:00
|
|
|
|
2014-06-01 20:28:38 +02:00
|
|
|
// a number of useful macros
|
2015-03-09 12:31:40 +01:00
|
|
|
#define ADDSEVERITY(check) severity = (severity != SYSTEMALARMS_ALARM_OK ? severity : ((check) ? SYSTEMALARMS_ALARM_OK : SYSTEMALARMS_ALARM_CRITICAL))
|
2015-03-09 11:31:42 +01:00
|
|
|
#define ADDEXTENDEDALARMSTATUS(error_code, error_substatus) if ((severity != SYSTEMALARMS_ALARM_OK) && (alarmstatus == SYSTEMALARMS_EXTENDEDALARMSTATUS_NONE)) { alarmstatus = (error_code); alarmsubstatus = (error_substatus); }
|
2014-06-01 20:28:38 +02:00
|
|
|
|
2015-02-05 01:39:58 +01:00
|
|
|
// private types
|
|
|
|
typedef struct SANITYCHECK_CustomHookInstance {
|
|
|
|
SANITYCHECK_CustomHook_function *hook;
|
|
|
|
struct SANITYCHECK_CustomHookInstance *next;
|
|
|
|
bool enabled;
|
|
|
|
} SANITYCHECK_CustomHookInstance;
|
2014-06-01 20:28:38 +02:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
// ! Check a stabilization mode switch position for safety
|
2015-01-08 03:20:47 +01:00
|
|
|
static bool check_stabilization_settings(int index, bool multirotor, bool coptercontrol, bool gpsassisted);
|
2012-10-25 19:43:56 +02:00
|
|
|
|
2015-02-05 01:39:58 +01:00
|
|
|
SANITYCHECK_CustomHookInstance *hooks = 0;
|
|
|
|
|
2012-10-25 19:43:56 +02:00
|
|
|
/**
|
|
|
|
* Run a preflight check over the hardware configuration
|
|
|
|
* and currently active modules
|
|
|
|
*/
|
|
|
|
int32_t configuration_check()
|
|
|
|
{
|
2013-04-03 19:26:25 +02:00
|
|
|
int32_t severity = SYSTEMALARMS_ALARM_OK;
|
2013-04-20 01:10:40 +02:00
|
|
|
SystemAlarmsExtendedAlarmStatusOptions alarmstatus = SYSTEMALARMS_EXTENDEDALARMSTATUS_NONE;
|
2013-04-03 19:26:25 +02:00
|
|
|
uint8_t alarmsubstatus = 0;
|
|
|
|
// Get board type
|
2013-05-19 16:37:30 +02:00
|
|
|
const struct pios_board_info *bdinfo = &pios_board_info_blob;
|
|
|
|
bool coptercontrol = bdinfo->board_type == 0x04;
|
2013-04-03 19:26:25 +02:00
|
|
|
|
2014-06-01 12:17:42 +02:00
|
|
|
// Classify navigation capability
|
|
|
|
#ifdef REVOLUTION
|
|
|
|
RevoSettingsInitialize();
|
2015-04-11 22:43:04 +02:00
|
|
|
RevoSettingsFusionAlgorithmOptions revoFusion;
|
2014-06-01 12:17:42 +02:00
|
|
|
RevoSettingsFusionAlgorithmGet(&revoFusion);
|
|
|
|
bool navCapableFusion;
|
|
|
|
switch (revoFusion) {
|
|
|
|
case REVOSETTINGS_FUSIONALGORITHM_COMPLEMENTARYMAGGPSOUTDOOR:
|
2014-10-21 00:49:00 +02:00
|
|
|
case REVOSETTINGS_FUSIONALGORITHM_GPSNAVIGATIONINS13:
|
2016-07-23 15:10:30 +02:00
|
|
|
case REVOSETTINGS_FUSIONALGORITHM_GPSNAVIGATIONINS13CF:
|
2014-06-01 12:17:42 +02:00
|
|
|
navCapableFusion = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
navCapableFusion = false;
|
2014-06-18 21:29:55 +02:00
|
|
|
// check for hitl. hitl allows to feed position and velocity state via
|
|
|
|
// telemetry, this makes nav possible even with an unsuited algorithm
|
|
|
|
if (PositionStateHandle()) {
|
|
|
|
if (PositionStateReadOnly()) {
|
|
|
|
navCapableFusion = true;
|
|
|
|
}
|
|
|
|
}
|
2014-06-01 12:17:42 +02:00
|
|
|
}
|
2016-07-23 15:10:30 +02:00
|
|
|
#else /* ifdef REVOLUTION */
|
2014-06-01 12:17:42 +02:00
|
|
|
const bool navCapableFusion = false;
|
2014-06-18 21:29:55 +02:00
|
|
|
#endif /* ifdef REVOLUTION */
|
2014-06-01 12:17:42 +02:00
|
|
|
|
|
|
|
|
2013-04-03 19:26:25 +02:00
|
|
|
// Classify airframe type
|
2014-06-29 17:22:41 +02:00
|
|
|
bool multirotor = (GetCurrentFrameType() == FRAME_TYPE_MULTIROTOR);
|
2013-05-19 16:37:30 +02:00
|
|
|
|
2013-04-03 19:26:25 +02:00
|
|
|
|
|
|
|
// For each available flight mode position sanity check the available
|
|
|
|
// modes
|
|
|
|
uint8_t num_modes;
|
2015-04-11 22:43:04 +02:00
|
|
|
FlightModeSettingsFlightModePositionOptions modes[FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_NUMELEM];
|
|
|
|
StabilizationSettingsFlightModeAssistMapOptions FlightModeAssistMap[STABILIZATIONSETTINGS_FLIGHTMODEASSISTMAP_NUMELEM];
|
2013-04-03 19:26:25 +02:00
|
|
|
ManualControlSettingsFlightModeNumberGet(&num_modes);
|
2015-01-08 03:20:47 +01:00
|
|
|
StabilizationSettingsFlightModeAssistMapGet(FlightModeAssistMap);
|
2014-02-09 19:33:29 +01:00
|
|
|
FlightModeSettingsFlightModePositionGet(modes);
|
2013-04-03 19:26:25 +02:00
|
|
|
|
2013-04-20 20:25:22 +02:00
|
|
|
for (uint32_t i = 0; i < num_modes; i++) {
|
2015-01-08 03:20:47 +01:00
|
|
|
uint8_t gps_assisted = FlightModeAssistMap[i];
|
|
|
|
if (gps_assisted) {
|
|
|
|
ADDSEVERITY(!coptercontrol);
|
|
|
|
ADDSEVERITY(multirotor);
|
|
|
|
ADDSEVERITY(navCapableFusion);
|
|
|
|
}
|
|
|
|
|
2015-03-20 11:42:20 +01:00
|
|
|
switch ((FlightModeSettingsFlightModePositionOptions)modes[i]) {
|
2014-02-09 19:33:29 +01:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_MANUAL:
|
2015-01-08 03:20:47 +01:00
|
|
|
ADDSEVERITY(!gps_assisted);
|
2014-06-01 20:28:38 +02:00
|
|
|
ADDSEVERITY(!multirotor);
|
2013-05-19 16:37:30 +02:00
|
|
|
break;
|
2014-02-09 19:33:29 +01:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_STABILIZED1:
|
2015-01-08 03:20:47 +01:00
|
|
|
ADDSEVERITY(check_stabilization_settings(1, multirotor, coptercontrol, gps_assisted));
|
2013-05-19 16:37:30 +02:00
|
|
|
break;
|
2014-02-09 19:33:29 +01:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_STABILIZED2:
|
2015-01-08 03:20:47 +01:00
|
|
|
ADDSEVERITY(check_stabilization_settings(2, multirotor, coptercontrol, gps_assisted));
|
2013-05-19 16:37:30 +02:00
|
|
|
break;
|
2014-02-09 19:33:29 +01:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_STABILIZED3:
|
2015-01-08 03:20:47 +01:00
|
|
|
ADDSEVERITY(check_stabilization_settings(3, multirotor, coptercontrol, gps_assisted));
|
2013-05-19 16:37:30 +02:00
|
|
|
break;
|
2014-05-04 11:19:58 +02:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_STABILIZED4:
|
2015-01-08 03:20:47 +01:00
|
|
|
ADDSEVERITY(check_stabilization_settings(4, multirotor, coptercontrol, gps_assisted));
|
2014-05-04 11:19:58 +02:00
|
|
|
break;
|
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_STABILIZED5:
|
2015-01-08 03:20:47 +01:00
|
|
|
ADDSEVERITY(check_stabilization_settings(5, multirotor, coptercontrol, gps_assisted));
|
2014-05-04 11:19:58 +02:00
|
|
|
break;
|
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_STABILIZED6:
|
2015-01-08 03:20:47 +01:00
|
|
|
ADDSEVERITY(check_stabilization_settings(6, multirotor, coptercontrol, gps_assisted));
|
2014-05-04 11:19:58 +02:00
|
|
|
break;
|
2014-06-01 20:28:38 +02:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_PATHPLANNER:
|
|
|
|
{
|
2015-01-08 03:20:47 +01:00
|
|
|
ADDSEVERITY(!gps_assisted);
|
2014-06-01 20:28:38 +02:00
|
|
|
}
|
2014-02-09 19:33:29 +01:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_POSITIONHOLD:
|
2015-05-22 09:34:43 +02:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_VELOCITYROAM:
|
2015-03-20 11:42:20 +01:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_LAND:
|
2015-04-12 13:39:31 +02:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_AUTOTAKEOFF:
|
2015-01-08 03:20:47 +01:00
|
|
|
ADDSEVERITY(!coptercontrol);
|
|
|
|
ADDSEVERITY(navCapableFusion);
|
|
|
|
break;
|
|
|
|
|
2014-11-08 14:04:00 +01:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_COURSELOCK:
|
2014-11-08 16:01:59 +01:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_HOMELEASH:
|
2014-11-08 12:56:17 +01:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_ABSOLUTEPOSITION:
|
2014-02-09 19:33:29 +01:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_POI:
|
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_RETURNTOBASE:
|
2014-06-04 10:23:37 +02:00
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_AUTOCRUISE:
|
2015-01-08 03:20:47 +01:00
|
|
|
ADDSEVERITY(!gps_assisted);
|
2014-06-01 20:28:38 +02:00
|
|
|
ADDSEVERITY(!coptercontrol);
|
|
|
|
ADDSEVERITY(navCapableFusion);
|
2013-05-19 16:37:30 +02:00
|
|
|
break;
|
2016-02-28 09:48:13 +01:00
|
|
|
#if !defined(PIOS_EXCLUDE_ADVANCED_FEATURES)
|
|
|
|
case FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_AUTOTUNE:
|
|
|
|
ADDSEVERITY(!gps_assisted);
|
2016-05-14 06:03:26 +02:00
|
|
|
// it would be fun to try autotune on a fixed wing
|
|
|
|
// but that should only be attempted by devs at first
|
|
|
|
ADDSEVERITY(multirotor);
|
2016-02-28 09:48:13 +01:00
|
|
|
break;
|
|
|
|
#endif /* !defined(PIOS_EXCLUDE_ADVANCED_FEATURES) */
|
2013-05-19 16:37:30 +02:00
|
|
|
default:
|
|
|
|
// Uncovered modes are automatically an error
|
2014-06-01 20:28:38 +02:00
|
|
|
ADDSEVERITY(false);
|
2013-04-03 19:26:25 +02:00
|
|
|
}
|
|
|
|
// mark the first encountered erroneous setting in status and substatus
|
2013-04-20 01:10:40 +02:00
|
|
|
if ((severity != SYSTEMALARMS_ALARM_OK) && (alarmstatus == SYSTEMALARMS_EXTENDEDALARMSTATUS_NONE)) {
|
2013-05-19 16:37:30 +02:00
|
|
|
alarmstatus = SYSTEMALARMS_EXTENDEDALARMSTATUS_FLIGHTMODE;
|
2013-04-03 19:26:25 +02:00
|
|
|
alarmsubstatus = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-09 11:31:42 +01:00
|
|
|
|
|
|
|
// Check throttle/collective channel range for valid configuration of input for critical control
|
|
|
|
SystemSettingsThrustControlOptions thrustType;
|
|
|
|
SystemSettingsThrustControlGet(&thrustType);
|
|
|
|
ManualControlSettingsChannelMinData channelMin;
|
|
|
|
ManualControlSettingsChannelMaxData channelMax;
|
|
|
|
ManualControlSettingsChannelMinGet(&channelMin);
|
|
|
|
ManualControlSettingsChannelMaxGet(&channelMax);
|
|
|
|
switch (thrustType) {
|
2015-03-09 12:31:40 +01:00
|
|
|
case SYSTEMSETTINGS_THRUSTCONTROL_THROTTLE:
|
|
|
|
ADDSEVERITY(fabsf(channelMax.Throttle - channelMin.Throttle) > 300.0f);
|
|
|
|
ADDEXTENDEDALARMSTATUS(SYSTEMALARMS_EXTENDEDALARMSTATUS_BADTHROTTLEORCOLLECTIVEINPUTRANGE, 0);
|
|
|
|
break;
|
|
|
|
case SYSTEMSETTINGS_THRUSTCONTROL_COLLECTIVE:
|
|
|
|
ADDSEVERITY(fabsf(channelMax.Collective - channelMin.Collective) > 300.0f);
|
|
|
|
ADDEXTENDEDALARMSTATUS(SYSTEMALARMS_EXTENDEDALARMSTATUS_BADTHROTTLEORCOLLECTIVEINPUTRANGE, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2015-03-09 11:31:42 +01:00
|
|
|
}
|
|
|
|
|
2015-02-05 01:39:58 +01:00
|
|
|
// query sanity check hooks
|
2015-02-09 00:50:22 +01:00
|
|
|
if (severity < SYSTEMALARMS_ALARM_CRITICAL) {
|
2015-02-05 01:39:58 +01:00
|
|
|
SANITYCHECK_CustomHookInstance *instance = NULL;
|
|
|
|
LL_FOREACH(hooks, instance) {
|
|
|
|
if (instance->enabled) {
|
|
|
|
alarmstatus = instance->hook();
|
|
|
|
if (alarmstatus != SYSTEMALARMS_EXTENDEDALARMSTATUS_NONE) {
|
2015-02-09 00:50:22 +01:00
|
|
|
severity = SYSTEMALARMS_ALARM_CRITICAL;
|
2015-02-05 01:39:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-11 22:43:04 +02:00
|
|
|
FlightModeSettingsDisableSanityChecksOptions checks_disabled;
|
2015-02-09 00:50:22 +01:00
|
|
|
FlightModeSettingsDisableSanityChecksGet(&checks_disabled);
|
|
|
|
if (checks_disabled == FLIGHTMODESETTINGS_DISABLESANITYCHECKS_TRUE) {
|
|
|
|
severity = SYSTEMALARMS_ALARM_WARNING;
|
|
|
|
}
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
if (severity != SYSTEMALARMS_ALARM_OK) {
|
2013-04-03 19:26:25 +02:00
|
|
|
ExtendedAlarmsSet(SYSTEMALARMS_ALARM_SYSTEMCONFIGURATION, severity, alarmstatus, alarmsubstatus);
|
2013-05-19 16:37:30 +02:00
|
|
|
} else {
|
2013-04-03 19:26:25 +02:00
|
|
|
AlarmsClear(SYSTEMALARMS_ALARM_SYSTEMCONFIGURATION);
|
2013-05-19 16:37:30 +02:00
|
|
|
}
|
2013-04-03 19:26:25 +02:00
|
|
|
|
|
|
|
return 0;
|
2012-10-25 21:41:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-04 21:02:36 +02:00
|
|
|
* Checks the stabilization settings for a particular mode and makes
|
2012-10-25 21:41:59 +02:00
|
|
|
* sure it is appropriate for the airframe
|
|
|
|
* @param[in] index Which stabilization mode to check
|
2014-06-01 20:28:38 +02:00
|
|
|
* @returns true or false
|
2012-10-25 21:41:59 +02:00
|
|
|
*/
|
2015-01-08 03:20:47 +01:00
|
|
|
static bool check_stabilization_settings(int index, bool multirotor, bool coptercontrol, bool gpsassisted)
|
2012-10-25 21:41:59 +02:00
|
|
|
{
|
2014-02-09 19:33:29 +01:00
|
|
|
uint8_t modes[FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_NUMELEM];
|
2013-04-03 19:26:25 +02:00
|
|
|
|
|
|
|
// Get the different axis modes for this switch position
|
2013-04-20 20:25:22 +02:00
|
|
|
switch (index) {
|
2013-05-19 16:37:30 +02:00
|
|
|
case 1:
|
2015-05-02 16:46:35 +02:00
|
|
|
FlightModeSettingsStabilization1SettingsArrayGet((FlightModeSettingsStabilization1SettingsOptions *)modes);
|
2013-05-19 16:37:30 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2015-05-02 16:46:35 +02:00
|
|
|
FlightModeSettingsStabilization2SettingsArrayGet((FlightModeSettingsStabilization2SettingsOptions *)modes);
|
2013-05-19 16:37:30 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2015-05-02 16:46:35 +02:00
|
|
|
FlightModeSettingsStabilization3SettingsArrayGet((FlightModeSettingsStabilization3SettingsOptions *)modes);
|
2013-05-19 16:37:30 +02:00
|
|
|
break;
|
2014-05-04 11:19:58 +02:00
|
|
|
case 4:
|
2015-05-02 16:46:35 +02:00
|
|
|
FlightModeSettingsStabilization4SettingsArrayGet((FlightModeSettingsStabilization4SettingsOptions *)modes);
|
2014-05-04 11:19:58 +02:00
|
|
|
break;
|
|
|
|
case 5:
|
2015-05-02 16:46:35 +02:00
|
|
|
FlightModeSettingsStabilization5SettingsArrayGet((FlightModeSettingsStabilization5SettingsOptions *)modes);
|
2014-05-04 11:19:58 +02:00
|
|
|
break;
|
|
|
|
case 6:
|
2015-05-02 16:46:35 +02:00
|
|
|
FlightModeSettingsStabilization6SettingsArrayGet((FlightModeSettingsStabilization6SettingsOptions *)modes);
|
2014-05-04 11:19:58 +02:00
|
|
|
break;
|
2013-05-19 16:37:30 +02:00
|
|
|
default:
|
2014-06-01 20:28:38 +02:00
|
|
|
return false;
|
2013-04-03 19:26:25 +02:00
|
|
|
}
|
|
|
|
|
2014-04-26 15:14:40 +02:00
|
|
|
// For multirotors verify that roll/pitch/yaw are not set to "none"
|
|
|
|
// (why not? might be fun to test ones reactions ;) if you dare, set your frame to "custom"!
|
2013-04-03 19:26:25 +02:00
|
|
|
if (multirotor) {
|
2014-04-26 15:14:40 +02:00
|
|
|
for (uint32_t i = 0; i < FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_THRUST; i++) {
|
2014-04-26 20:33:25 +02:00
|
|
|
if (modes[i] == FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_MANUAL) {
|
2014-06-01 20:28:38 +02:00
|
|
|
return false;
|
2013-05-19 16:37:30 +02:00
|
|
|
}
|
2013-04-03 19:26:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-08 03:20:47 +01:00
|
|
|
if (gpsassisted) {
|
|
|
|
// For multirotors verify that roll/pitch are either attitude or rattitude
|
|
|
|
for (uint32_t i = 0; i < FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_YAW; i++) {
|
|
|
|
if (!(modes[i] == FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_ATTITUDE ||
|
|
|
|
modes[i] == FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_RATTITUDE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-26 15:14:40 +02:00
|
|
|
// coptercontrol cannot do altitude holding
|
|
|
|
if (coptercontrol) {
|
2014-04-26 20:33:25 +02:00
|
|
|
if (modes[FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_THRUST] == FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_ALTITUDEHOLD
|
2014-06-03 18:42:54 +02:00
|
|
|
|| modes[FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_THRUST] == FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_ALTITUDEVARIO
|
2014-04-26 15:14:40 +02:00
|
|
|
) {
|
2014-06-01 20:28:38 +02:00
|
|
|
return false;
|
2014-04-26 15:14:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check that thrust modes are only set to thrust axis
|
|
|
|
for (uint32_t i = 0; i < FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_THRUST; i++) {
|
2014-04-26 20:33:25 +02:00
|
|
|
if (modes[i] == FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_ALTITUDEHOLD
|
2014-06-03 18:42:54 +02:00
|
|
|
|| modes[i] == FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_ALTITUDEVARIO
|
2014-04-26 15:14:40 +02:00
|
|
|
) {
|
2014-06-01 20:28:38 +02:00
|
|
|
return false;
|
2014-04-26 15:14:40 +02:00
|
|
|
}
|
|
|
|
}
|
2014-04-26 20:33:25 +02:00
|
|
|
if (!(modes[FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_THRUST] == FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_MANUAL
|
|
|
|
|| modes[FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_THRUST] == FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_ALTITUDEHOLD
|
2014-06-03 18:42:54 +02:00
|
|
|
|| modes[FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_THRUST] == FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_ALTITUDEVARIO
|
2014-04-29 15:51:56 +02:00
|
|
|
|| modes[FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_THRUST] == FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_CRUISECONTROL
|
2014-04-26 15:14:40 +02:00
|
|
|
)) {
|
2014-06-01 20:28:38 +02:00
|
|
|
return false;
|
2014-04-26 15:14:40 +02:00
|
|
|
}
|
|
|
|
|
2016-06-04 21:02:36 +02:00
|
|
|
// if cruise control, ensure Acro+ is not set
|
2015-01-07 03:26:12 +01:00
|
|
|
if (modes[FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_THRUST] == FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_CRUISECONTROL) {
|
2015-02-18 22:27:10 +01:00
|
|
|
for (uint32_t i = 0; i < FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_YAW; i++) {
|
2016-06-04 21:02:36 +02:00
|
|
|
// Do not allow Acro+, attitude estimation is not safe.
|
|
|
|
if (modes[i] == FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_ACRO) {
|
2015-02-18 22:27:10 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-01-07 03:26:12 +01:00
|
|
|
}
|
|
|
|
|
2013-04-03 19:26:25 +02:00
|
|
|
// Warning: This assumes that certain conditions in the XML file are met. That
|
2014-04-26 20:33:25 +02:00
|
|
|
// FLIGHTMODESETTINGS_STABILIZATION1SETTINGS_MANUAL has the same numeric value for each channel
|
|
|
|
// and is the same for STABILIZATIONDESIRED_STABILIZATIONMODE_MANUAL
|
|
|
|
// (this is checked at compile time by static constraint manualcontrol.h)
|
2013-04-03 19:26:25 +02:00
|
|
|
|
2015-02-05 01:39:58 +01:00
|
|
|
|
2014-06-01 20:28:38 +02:00
|
|
|
return true;
|
2013-02-03 14:57:54 +01:00
|
|
|
}
|
2014-06-29 17:22:41 +02:00
|
|
|
|
|
|
|
FrameType_t GetCurrentFrameType()
|
|
|
|
{
|
2015-04-11 22:43:04 +02:00
|
|
|
SystemSettingsAirframeTypeOptions airframe_type;
|
2014-06-29 17:22:41 +02:00
|
|
|
|
|
|
|
SystemSettingsAirframeTypeGet(&airframe_type);
|
|
|
|
switch ((SystemSettingsAirframeTypeOptions)airframe_type) {
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_QUADX:
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_QUADP:
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_HEXA:
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_OCTO:
|
2014-07-13 13:58:18 +02:00
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_OCTOX:
|
2014-06-29 17:22:41 +02:00
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_HEXAX:
|
2014-07-10 06:01:28 +02:00
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_HEXAH:
|
2014-06-29 17:22:41 +02:00
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_OCTOV:
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_OCTOCOAXP:
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_HEXACOAX:
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_TRI:
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_OCTOCOAXX:
|
|
|
|
return FRAME_TYPE_MULTIROTOR;
|
|
|
|
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_FIXEDWING:
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_FIXEDWINGELEVON:
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_FIXEDWINGVTAIL:
|
|
|
|
return FRAME_TYPE_FIXED_WING;
|
|
|
|
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_HELICP:
|
|
|
|
return FRAME_TYPE_HELI;
|
|
|
|
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_GROUNDVEHICLECAR:
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIAL:
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_GROUNDVEHICLEMOTORCYCLE:
|
2016-12-19 14:23:06 +01:00
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_GROUNDVEHICLEBOAT:
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIALBOAT:
|
2014-06-29 17:22:41 +02:00
|
|
|
return FRAME_TYPE_GROUND;
|
|
|
|
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_VTOL:
|
|
|
|
case SYSTEMSETTINGS_AIRFRAMETYPE_CUSTOM:
|
|
|
|
return FRAME_TYPE_CUSTOM;
|
|
|
|
}
|
|
|
|
// anyway it should not reach here
|
|
|
|
return FRAME_TYPE_CUSTOM;
|
|
|
|
}
|
2015-02-05 01:39:58 +01:00
|
|
|
|
|
|
|
void SANITYCHECK_AttachHook(SANITYCHECK_CustomHook_function *hook)
|
|
|
|
{
|
|
|
|
PIOS_Assert(hook);
|
2015-02-05 15:42:58 +01:00
|
|
|
SANITYCHECK_CustomHookInstance *instance = NULL;
|
|
|
|
|
|
|
|
// Check whether there is an existing instance and enable it
|
|
|
|
LL_FOREACH(hooks, instance) {
|
|
|
|
if (instance->hook == hook) {
|
|
|
|
instance->enabled = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No existing instance found, attach this new one
|
|
|
|
instance = (SANITYCHECK_CustomHookInstance *)pios_malloc(sizeof(SANITYCHECK_CustomHookInstance));
|
2015-02-05 01:39:58 +01:00
|
|
|
PIOS_Assert(instance);
|
|
|
|
instance->hook = hook;
|
|
|
|
instance->next = NULL;
|
|
|
|
instance->enabled = true;
|
|
|
|
LL_APPEND(hooks, instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SANITYCHECK_DetachHook(SANITYCHECK_CustomHook_function *hook)
|
|
|
|
{
|
|
|
|
if (!hooks) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SANITYCHECK_CustomHookInstance *instance = NULL;
|
|
|
|
LL_FOREACH(hooks, instance) {
|
|
|
|
if (instance->hook == hook) {
|
|
|
|
instance->enabled = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|