mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
Actuator: Fixed uninitialised variables
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1857 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
1931c75a4c
commit
11cf24a312
@ -56,6 +56,11 @@
|
||||
static xQueueHandle queue;
|
||||
static xTaskHandle taskHandle;
|
||||
|
||||
static float lastResult[MAX_MIX_ACTUATORS]={0,0,0,0,0,0,0,0};
|
||||
static float lastFilteredResult[MAX_MIX_ACTUATORS]={0,0,0,0,0,0,0,0};
|
||||
static float filterAccumulator[MAX_MIX_ACTUATORS]={0,0,0,0,0,0,0,0};
|
||||
|
||||
|
||||
// Private functions
|
||||
static void actuatorTask(void* parameters);
|
||||
static int16_t scaleChannel(float value, int16_t max, int16_t min, int16_t neutral);
|
||||
@ -134,12 +139,12 @@ static void actuatorTask(void* parameters)
|
||||
lastSysTime = xTaskGetTickCount();
|
||||
while (1)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Check how long since last update
|
||||
thisSysTime = xTaskGetTickCount();
|
||||
@ -188,6 +193,8 @@ static void actuatorTask(void* parameters)
|
||||
mixers[ct].type == MIXERSETTINGS_MIXER0TYPE_MOTOR)
|
||||
{
|
||||
command.Channel[ct] = settings.ChannelMin[ct]; //force zero throttle
|
||||
filterAccumulator[ct] = 0;
|
||||
lastResult[ct] = 0;
|
||||
}else
|
||||
{
|
||||
command.Channel[ct] = scaleChannel(status[ct],
|
||||
@ -221,16 +228,13 @@ static void actuatorTask(void* parameters)
|
||||
float ProcessMixer(const int index, const float curve1, const float curve2,
|
||||
MixerSettingsData* mixerSettings, ActuatorDesiredData* desired, const float period)
|
||||
{
|
||||
static float lastResult[MAX_MIX_ACTUATORS]={0,0,0,0,0,0,0,0};
|
||||
static float lastFilteredResult[MAX_MIX_ACTUATORS]={0,0,0,0,0,0,0,0};
|
||||
static float filterAccumulator[MAX_MIX_ACTUATORS]={0,0,0,0,0,0,0,0};
|
||||
Mixer_t * mixers = (Mixer_t *)&mixerSettings->Mixer0Type; //pointer to array of mixers in UAVObjects
|
||||
Mixer_t * mixer = &mixers[index];
|
||||
float result = (mixer->matrix[MIXERSETTINGS_MIXER0VECTOR_THROTTLECURVE1] / 128.0f * curve1) +
|
||||
(mixer->matrix[MIXERSETTINGS_MIXER0VECTOR_THROTTLECURVE2] / 128.0f * curve2) +
|
||||
(mixer->matrix[MIXERSETTINGS_MIXER0VECTOR_ROLL] / 128.0f * desired->Roll) +
|
||||
(mixer->matrix[MIXERSETTINGS_MIXER0VECTOR_PITCH] / 128.0f * desired->Pitch) +
|
||||
(mixer->matrix[MIXERSETTINGS_MIXER0VECTOR_YAW] / 128.0f * desired->Yaw);
|
||||
float result = ((mixer->matrix[MIXERSETTINGS_MIXER0VECTOR_THROTTLECURVE1] / 128.0f) * curve1) +
|
||||
((mixer->matrix[MIXERSETTINGS_MIXER0VECTOR_THROTTLECURVE2] / 128.0f) * curve2) +
|
||||
((mixer->matrix[MIXERSETTINGS_MIXER0VECTOR_ROLL] / 128.0f) * desired->Roll) +
|
||||
((mixer->matrix[MIXERSETTINGS_MIXER0VECTOR_PITCH] / 128.0f) * desired->Pitch) +
|
||||
((mixer->matrix[MIXERSETTINGS_MIXER0VECTOR_YAW] / 128.0f) * desired->Yaw);
|
||||
if(mixer->type == MIXERSETTINGS_MIXER0TYPE_MOTOR)
|
||||
{
|
||||
if(result < 0) //idle throttle
|
||||
@ -243,22 +247,25 @@ float ProcessMixer(const int index, const float curve1, const float curve2,
|
||||
accumulator += (result - lastResult[index]) * mixerSettings->FeedForward;
|
||||
lastResult[index] = result;
|
||||
result += accumulator;
|
||||
if(accumulator > 0)
|
||||
if(period !=0)
|
||||
{
|
||||
float filter = mixerSettings->AccelTime / period;
|
||||
if(filter <1)
|
||||
if(accumulator > 0)
|
||||
{
|
||||
filter = 1;
|
||||
}
|
||||
accumulator -= accumulator / filter;
|
||||
}else
|
||||
{
|
||||
float filter = mixerSettings->DecelTime / period;
|
||||
if(filter <1)
|
||||
float filter = mixerSettings->AccelTime / period;
|
||||
if(filter <1)
|
||||
{
|
||||
filter = 1;
|
||||
}
|
||||
accumulator -= accumulator / filter;
|
||||
}else
|
||||
{
|
||||
filter = 1;
|
||||
float filter = mixerSettings->DecelTime / period;
|
||||
if(filter <1)
|
||||
{
|
||||
filter = 1;
|
||||
}
|
||||
accumulator -= accumulator / filter;
|
||||
}
|
||||
accumulator -= accumulator / filter;
|
||||
}
|
||||
filterAccumulator[index] = accumulator;
|
||||
result += accumulator;
|
||||
|
Loading…
x
Reference in New Issue
Block a user