1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

Flight/Actuator Go to failsafe actuator outputs when a command is not received

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@763 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
vassilis 2010-06-14 02:00:16 +00:00 committed by vassilis
parent 0731747d84
commit 106bdca20e
2 changed files with 43 additions and 4 deletions

View File

@ -45,9 +45,9 @@ FLASH_TOOL = OPENOCD
USE_THUMB_MODE = YES
# List of modules to include
#MODULES = Telemetry GPS ManualControl Actuator Altitude Attitude
MODULES = Telemetry GPS ManualControl Actuator Altitude Attitude
#MODULES = Telemetry Example
MODULES = Telemetry MK/MKSerial
#MODULES = Telemetry MK/MKSerial
# MCU name, submodel and board

View File

@ -35,6 +35,7 @@
#define MAX_QUEUE_SIZE 2
#define STACK_SIZE configMINIMAL_STACK_SIZE
#define TASK_PRIORITY (tskIDLE_PRIORITY+4)
#define FAILSAFE_TIMEOUT_MS 100
// Private types
@ -48,6 +49,7 @@ static int32_t mixerFixedWing(const ActuatorSettingsData* settings, const Actuat
static int32_t mixerFixedWingElevon(const ActuatorSettingsData* settings, const ActuatorDesiredData* desired, ActuatorCommandData* cmd);
static int32_t mixerVTOL(const ActuatorSettingsData* settings, const ActuatorDesiredData* desired, ActuatorCommandData* cmd);
static int16_t scaleChannel(float value, int16_t max, int16_t min, int16_t neutral);
static void setFailsafe();
/**
* Module initialization
@ -81,11 +83,18 @@ static void actuatorTask(void* parameters)
ActuatorSettingsGet(&settings);
PIOS_Servo_SetHz(settings.ChannelUpdateFreq[0], settings.ChannelUpdateFreq[1]);
// Go to the neutral (failsafe) values until an ActuatorDesired update is received
setFailsafe();
// Main task loop
while (1)
{
// Wait until the ActuatorDesired object is updated
while ( xQueueReceive(queue, &ev, portMAX_DELAY) != pdTRUE );
// Wait until the ActuatorDesired object is updated, if a timeout then go to failsafe
if ( xQueueReceive(queue, &ev, FAILSAFE_TIMEOUT_MS / portTICK_RATE_MS) != pdTRUE )
{
setFailsafe();
continue;
}
// Read settings
ActuatorSettingsGet(&settings);
@ -236,3 +245,33 @@ static int16_t scaleChannel(float value, int16_t max, int16_t min, int16_t neutr
}
return valueScaled;
}
/**
* Set actuator output to the neutral values (failsafe)
*/
static void setFailsafe()
{
ActuatorSettingsData settings;
ActuatorCommandData cmd;
// Read settings
ActuatorSettingsGet(&settings);
// Reset ActuatorCommand to neutral values
for (int n = 0; n < ACTUATORCOMMAND_CHANNEL_NUMELEM; ++n)
{
cmd.Channel[n] = settings.ChannelNeutral[n];
}
// Set alarm
AlarmsSet(SYSTEMALARMS_ALARM_ACTUATOR, SYSTEMALARMS_ALARM_CRITICAL);
// Update servo outputs
for (int n = 0; n < ACTUATORCOMMAND_CHANNEL_NUMELEM; ++n)
{
PIOS_Servo_Set( n+1, cmd.Channel[n] );
}
// Update output object
ActuatorCommandSet(&cmd);
}