2011-06-15 18:18:29 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @addtogroup OpenPilotModules OpenPilot Modules
|
|
|
|
* @{
|
|
|
|
* @addtogroup CameraStab Camera Stabilization Module
|
|
|
|
* @brief Camera stabilization module
|
|
|
|
* Updates accessory outputs with values appropriate for camera stabilization
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file camerastab.c
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @brief Stabilize camera against the roll pitch and yaw of aircraft
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output object: Accessory
|
|
|
|
*
|
|
|
|
* This module will periodically calculate the output values for stabilizing the camera
|
|
|
|
*
|
|
|
|
* UAVObjects are automatically generated by the UAVObjectGenerator from
|
|
|
|
* the object definition XML file.
|
|
|
|
*
|
|
|
|
* Modules have no API, all communication to other modules is done through UAVObjects.
|
|
|
|
* However modules may use the API exposed by shared libraries.
|
|
|
|
* See the OpenPilot wiki for more details.
|
|
|
|
* http://www.openpilot.org/OpenPilot_Application_Architecture
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "openpilot.h"
|
|
|
|
|
|
|
|
#include "accessorydesired.h"
|
2013-05-18 19:36:45 +02:00
|
|
|
#include "attitudestate.h"
|
2017-12-03 17:59:51 +01:00
|
|
|
#include "mixersettings.h"
|
|
|
|
#include "actuatorcommand.h"
|
2011-06-23 07:46:41 +02:00
|
|
|
#include "camerastabsettings.h"
|
2011-08-10 03:43:48 +02:00
|
|
|
#include "cameradesired.h"
|
2011-11-11 11:39:57 +01:00
|
|
|
#include "hwsettings.h"
|
2011-06-15 18:18:29 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Configuration
|
|
|
|
//
|
2013-05-18 14:17:26 +02:00
|
|
|
#define SAMPLE_PERIOD_MS 10
|
2011-06-15 18:18:29 +02:00
|
|
|
|
|
|
|
// Private types
|
|
|
|
|
|
|
|
// Private variables
|
2017-12-03 17:59:51 +01:00
|
|
|
static bool gimbalOutputEnabled = false;
|
|
|
|
|
2011-12-16 21:27:13 +01:00
|
|
|
static struct CameraStab_data {
|
2013-05-18 14:17:26 +02:00
|
|
|
portTickType lastSysTime;
|
|
|
|
float inputs[CAMERASTABSETTINGS_INPUT_NUMELEM];
|
2012-11-17 15:18:37 +01:00
|
|
|
|
|
|
|
#ifdef USE_GIMBAL_LPF
|
2013-05-18 14:17:26 +02:00
|
|
|
float attitudeFiltered[CAMERASTABSETTINGS_INPUT_NUMELEM];
|
2012-11-17 15:18:37 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_GIMBAL_FF
|
2013-05-18 14:17:26 +02:00
|
|
|
float ffLastAttitude[CAMERASTABSETTINGS_INPUT_NUMELEM];
|
|
|
|
float ffLastAttitudeFiltered[CAMERASTABSETTINGS_INPUT_NUMELEM];
|
|
|
|
float ffFilterAccumulator[CAMERASTABSETTINGS_INPUT_NUMELEM];
|
2012-11-17 15:18:37 +01:00
|
|
|
#endif
|
2011-12-16 21:27:13 +01:00
|
|
|
} *csd;
|
2011-06-15 18:18:29 +02:00
|
|
|
|
|
|
|
// Private functions
|
2013-05-18 14:17:26 +02:00
|
|
|
static void attitudeUpdated(UAVObjEvent *ev);
|
2011-06-15 18:18:29 +02:00
|
|
|
|
2012-11-17 15:18:37 +01:00
|
|
|
#ifdef USE_GIMBAL_FF
|
|
|
|
static void applyFeedForward(uint8_t index, float dT, float *attitude, CameraStabSettingsData *cameraStab);
|
|
|
|
#endif
|
|
|
|
|
2017-12-03 17:59:51 +01:00
|
|
|
// this structure is equivalent to the UAVObjects for one mixer.
|
|
|
|
typedef struct {
|
|
|
|
uint8_t type;
|
|
|
|
int8_t matrix[5];
|
|
|
|
} __attribute__((packed)) Mixer_t;
|
|
|
|
|
2012-11-17 15:18:37 +01:00
|
|
|
|
2011-06-15 18:18:29 +02:00
|
|
|
/**
|
|
|
|
* Initialise the module, called on startup
|
|
|
|
* \returns 0 on success or -1 if initialisation failed
|
|
|
|
*/
|
|
|
|
int32_t CameraStabInitialize(void)
|
|
|
|
{
|
2013-05-18 14:17:26 +02:00
|
|
|
bool cameraStabEnabled;
|
2012-01-14 22:55:55 +01:00
|
|
|
|
2013-09-01 13:23:20 +02:00
|
|
|
HwSettingsOptionalModulesData optionalModules;
|
2011-11-13 17:27:52 +01:00
|
|
|
|
2013-09-01 13:23:20 +02:00
|
|
|
HwSettingsOptionalModulesGet(&optionalModules);
|
2011-06-23 07:46:41 +02:00
|
|
|
|
2017-10-29 15:41:57 +01:00
|
|
|
#ifdef MODULE_CAMERASTAB_BUILTIN
|
|
|
|
cameraStabEnabled = true;
|
|
|
|
optionalModules.CameraStab = HWSETTINGS_OPTIONALMODULES_ENABLED;
|
|
|
|
HwSettingsOptionalModulesSet(&optionalModules);
|
|
|
|
#else
|
2013-09-01 13:23:20 +02:00
|
|
|
if (optionalModules.CameraStab == HWSETTINGS_OPTIONALMODULES_ENABLED) {
|
2013-05-18 14:17:26 +02:00
|
|
|
cameraStabEnabled = true;
|
|
|
|
} else {
|
|
|
|
cameraStabEnabled = false;
|
|
|
|
}
|
2012-01-14 22:55:55 +01:00
|
|
|
#endif
|
2011-11-13 17:27:52 +01:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
if (cameraStabEnabled) {
|
|
|
|
// allocate and initialize the static data storage only if module is enabled
|
2014-06-11 20:11:48 +02:00
|
|
|
csd = (struct CameraStab_data *)pios_malloc(sizeof(struct CameraStab_data));
|
2013-05-18 14:17:26 +02:00
|
|
|
if (!csd) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-12-16 21:27:13 +01:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// initialize camera state variables
|
|
|
|
memset(csd, 0, sizeof(struct CameraStab_data));
|
|
|
|
csd->lastSysTime = xTaskGetTickCount();
|
2011-12-16 21:27:13 +01:00
|
|
|
|
2013-05-18 19:36:45 +02:00
|
|
|
AttitudeStateInitialize();
|
2013-05-18 14:17:26 +02:00
|
|
|
CameraDesiredInitialize();
|
2011-11-11 11:39:57 +01:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
UAVObjEvent ev = {
|
2013-05-18 19:36:45 +02:00
|
|
|
.obj = AttitudeStateHandle(),
|
2013-05-18 14:17:26 +02:00
|
|
|
.instId = 0,
|
|
|
|
.event = 0,
|
2014-02-18 01:04:43 +01:00
|
|
|
.lowPriority = false,
|
2013-05-18 14:17:26 +02:00
|
|
|
};
|
|
|
|
EventPeriodicCallbackCreate(&ev, attitudeUpdated, SAMPLE_PERIOD_MS / portTICK_RATE_MS);
|
2011-11-11 11:39:57 +01:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2011-11-11 11:39:57 +01:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
return -1;
|
2011-06-15 18:18:29 +02:00
|
|
|
}
|
|
|
|
|
2011-08-20 01:24:06 +02:00
|
|
|
/* stub: module has no module thread */
|
|
|
|
int32_t CameraStabStart(void)
|
|
|
|
{
|
2013-05-18 14:17:26 +02:00
|
|
|
return 0;
|
2011-08-20 01:24:06 +02:00
|
|
|
}
|
|
|
|
|
2013-06-04 05:37:40 +02:00
|
|
|
MODULE_INITCALL(CameraStabInitialize, CameraStabStart);
|
2011-11-11 11:39:57 +01:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
static void attitudeUpdated(UAVObjEvent *ev)
|
2011-06-15 18:18:29 +02:00
|
|
|
{
|
2013-05-18 19:36:45 +02:00
|
|
|
if (ev->obj != AttitudeStateHandle()) {
|
2013-05-18 14:17:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-03 17:59:51 +01:00
|
|
|
if (!gimbalOutputEnabled) {
|
|
|
|
MixerSettingsData mixerSettings;
|
|
|
|
MixerSettingsGet(&mixerSettings);
|
|
|
|
Mixer_t *mixers = (Mixer_t *)&mixerSettings.Mixer1Type;
|
|
|
|
for (int ct = 0; ct < ACTUATORCOMMAND_CHANNEL_NUMELEM; ct++) {
|
|
|
|
uint8_t mixer_type = mixers[ct].type;
|
|
|
|
if ((mixer_type >= MIXERSETTINGS_MIXER1TYPE_CAMERAROLLORSERVO1) &&
|
|
|
|
(mixer_type <= MIXERSETTINGS_MIXER1TYPE_CAMERAYAW)) {
|
|
|
|
gimbalOutputEnabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
AccessoryDesiredData accessory;
|
|
|
|
|
|
|
|
CameraStabSettingsData cameraStab;
|
|
|
|
CameraStabSettingsGet(&cameraStab);
|
|
|
|
|
|
|
|
// check how long since last update, time delta between calls in ms
|
|
|
|
portTickType thisSysTime = xTaskGetTickCount();
|
|
|
|
float dT_millis = (thisSysTime > csd->lastSysTime) ?
|
|
|
|
(float)((thisSysTime - csd->lastSysTime) * portTICK_RATE_MS) :
|
|
|
|
(float)SAMPLE_PERIOD_MS;
|
|
|
|
csd->lastSysTime = thisSysTime;
|
|
|
|
|
|
|
|
// storage for elevon roll component before the pitch component has been generated
|
|
|
|
// we are guaranteed that the iteration order of i is roll pitch yaw
|
|
|
|
// that guarnteees this won't be used uninited, but the compiler doesn't know that
|
|
|
|
// so we init it or turn the warning/error off for each compiler
|
|
|
|
float elevon_roll = 0.0f;
|
|
|
|
|
|
|
|
// process axes
|
|
|
|
for (uint8_t i = 0; i < CAMERASTABSETTINGS_INPUT_NUMELEM; i++) {
|
|
|
|
// read and process control input
|
2014-08-24 00:16:34 +02:00
|
|
|
if (CameraStabSettingsInputToArray(cameraStab.Input)[i] != CAMERASTABSETTINGS_INPUT_NONE) {
|
|
|
|
if (AccessoryDesiredInstGet(CameraStabSettingsInputToArray(cameraStab.Input)[i] -
|
2013-09-01 12:10:55 +02:00
|
|
|
CAMERASTABSETTINGS_INPUT_ACCESSORY0, &accessory) == 0) {
|
2013-05-18 14:17:26 +02:00
|
|
|
float input_rate;
|
2014-08-24 00:16:34 +02:00
|
|
|
switch (CameraStabSettingsStabilizationModeToArray(cameraStab.StabilizationMode)[i]) {
|
2013-05-18 14:17:26 +02:00
|
|
|
case CAMERASTABSETTINGS_STABILIZATIONMODE_ATTITUDE:
|
2013-09-01 12:10:55 +02:00
|
|
|
csd->inputs[i] = accessory.AccessoryVal *
|
2014-08-24 00:16:34 +02:00
|
|
|
CameraStabSettingsInputRangeToArray(cameraStab.InputRange)[i];
|
2013-05-18 14:17:26 +02:00
|
|
|
break;
|
|
|
|
case CAMERASTABSETTINGS_STABILIZATIONMODE_AXISLOCK:
|
2013-09-01 12:10:55 +02:00
|
|
|
input_rate = accessory.AccessoryVal *
|
2014-08-24 00:16:34 +02:00
|
|
|
CameraStabSettingsInputRateToArray(cameraStab.InputRate)[i];
|
2013-05-18 14:17:26 +02:00
|
|
|
if (fabsf(input_rate) > cameraStab.MaxAxisLockRate) {
|
2014-04-26 17:31:20 +02:00
|
|
|
csd->inputs[i] = boundf(csd->inputs[i] + input_rate * 0.001f * dT_millis,
|
2014-08-24 00:16:34 +02:00
|
|
|
-CameraStabSettingsInputRangeToArray(cameraStab.InputRange)[i],
|
|
|
|
CameraStabSettingsInputRangeToArray(cameraStab.InputRange)[i]);
|
2013-05-18 14:17:26 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PIOS_Assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate servo output
|
|
|
|
float attitude;
|
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
case CAMERASTABSETTINGS_INPUT_ROLL:
|
2013-05-18 19:36:45 +02:00
|
|
|
AttitudeStateRollGet(&attitude);
|
2013-05-18 14:17:26 +02:00
|
|
|
break;
|
|
|
|
case CAMERASTABSETTINGS_INPUT_PITCH:
|
2013-05-18 19:36:45 +02:00
|
|
|
AttitudeStatePitchGet(&attitude);
|
2013-05-18 14:17:26 +02:00
|
|
|
break;
|
|
|
|
case CAMERASTABSETTINGS_INPUT_YAW:
|
2013-05-18 19:36:45 +02:00
|
|
|
AttitudeStateYawGet(&attitude);
|
2013-05-18 14:17:26 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PIOS_Assert(0);
|
|
|
|
}
|
2011-12-16 21:27:13 +01:00
|
|
|
|
2012-11-17 15:18:37 +01:00
|
|
|
#ifdef USE_GIMBAL_LPF
|
2014-08-24 00:16:34 +02:00
|
|
|
if (CameraStabSettingsResponseTimeToArray(cameraStab.ResponseTime)[i]) {
|
|
|
|
float rt = (float)CameraStabSettingsResponseTimeToArray(cameraStab.ResponseTime)[i];
|
2013-05-18 14:17:26 +02:00
|
|
|
attitude = csd->attitudeFiltered[i] = ((rt * csd->attitudeFiltered[i]) + (dT_millis * attitude)) / (rt + dT_millis);
|
|
|
|
}
|
2012-11-17 15:18:37 +01:00
|
|
|
#endif
|
2011-06-23 07:46:41 +02:00
|
|
|
|
2012-11-17 15:18:37 +01:00
|
|
|
#ifdef USE_GIMBAL_FF
|
2014-08-24 00:16:34 +02:00
|
|
|
if (CameraStabSettingsFeedForwardToArray(cameraStab.FeedForward)[i]) {
|
2013-05-18 14:17:26 +02:00
|
|
|
applyFeedForward(i, dT_millis, &attitude, &cameraStab);
|
|
|
|
}
|
2012-11-17 15:18:37 +01:00
|
|
|
#endif
|
2011-08-10 03:43:48 +02:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// bounding for elevon mixing occurs on the unmixed output
|
|
|
|
// to limit the range of the mixed output you must limit the range
|
|
|
|
// of both the unmixed pitch and unmixed roll
|
2014-08-24 00:16:34 +02:00
|
|
|
float output = boundf((attitude + csd->inputs[i]) / CameraStabSettingsOutputRangeToArray(cameraStab.OutputRange)[i], -1.0f, 1.0f);
|
2013-05-18 14:17:26 +02:00
|
|
|
|
|
|
|
// set output channels
|
|
|
|
switch (i) {
|
|
|
|
case CAMERASTABSETTINGS_INPUT_ROLL:
|
|
|
|
// we are guaranteed that the iteration order of i is roll pitch yaw
|
|
|
|
// for elevon mixing we simply grab the value for later use
|
|
|
|
if (cameraStab.GimbalType == CAMERASTABSETTINGS_GIMBALTYPE_ROLLPITCHMIXED) {
|
|
|
|
elevon_roll = output;
|
|
|
|
} else {
|
|
|
|
CameraDesiredRollOrServo1Set(&output);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CAMERASTABSETTINGS_INPUT_PITCH:
|
|
|
|
// we are guaranteed that the iteration order of i is roll pitch yaw
|
|
|
|
// for elevon mixing we use the value we previously grabbed and set both s1 and s2
|
|
|
|
if (cameraStab.GimbalType == CAMERASTABSETTINGS_GIMBALTYPE_ROLLPITCHMIXED) {
|
|
|
|
float elevon_pitch = output;
|
|
|
|
// elevon reversing works like this:
|
|
|
|
// first use the normal reversing facilities to get servo 1 roll working in the correct direction
|
|
|
|
// then use the normal reversing facilities to get servo 2 roll working in the correct direction
|
|
|
|
// then use these new reversing switches to reverse servo 1 and/or 2 pitch as needed
|
|
|
|
// if servo 1 pitch is reversed
|
|
|
|
if (cameraStab.Servo1PitchReverse == CAMERASTABSETTINGS_SERVO1PITCHREVERSE_TRUE) {
|
|
|
|
// use (reversed pitch) + roll
|
|
|
|
output = ((1.0f - elevon_pitch) + elevon_roll) / 2.0f;
|
|
|
|
} else {
|
|
|
|
// use pitch + roll
|
|
|
|
output = (elevon_pitch + elevon_roll) / 2.0f;
|
|
|
|
}
|
|
|
|
CameraDesiredRollOrServo1Set(&output);
|
|
|
|
// if servo 2 pitch is reversed
|
|
|
|
if (cameraStab.Servo2PitchReverse == CAMERASTABSETTINGS_SERVO2PITCHREVERSE_TRUE) {
|
|
|
|
// use (reversed pitch) - roll
|
|
|
|
output = ((1.0f - elevon_pitch) - elevon_roll) / 2.0f;
|
|
|
|
} else {
|
|
|
|
// use pitch - roll
|
|
|
|
output = (elevon_pitch - elevon_roll) / 2.0f;
|
|
|
|
}
|
|
|
|
CameraDesiredPitchOrServo2Set(&output);
|
|
|
|
} else {
|
|
|
|
CameraDesiredPitchOrServo2Set(&output);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CAMERASTABSETTINGS_INPUT_YAW:
|
|
|
|
CameraDesiredYawSet(&output);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PIOS_Assert(0);
|
|
|
|
}
|
|
|
|
}
|
2011-06-15 18:18:29 +02:00
|
|
|
}
|
|
|
|
|
2012-11-17 15:18:37 +01:00
|
|
|
#ifdef USE_GIMBAL_FF
|
2012-12-02 13:09:21 +01:00
|
|
|
void applyFeedForward(uint8_t index, float dT_millis, float *attitude, CameraStabSettingsData *cameraStab)
|
2012-11-17 15:18:37 +01:00
|
|
|
{
|
2013-05-18 14:17:26 +02:00
|
|
|
// compensate high feed forward values depending on gimbal type
|
|
|
|
float gimbalTypeCorrection = 1.0f;
|
|
|
|
|
|
|
|
switch (cameraStab->GimbalType) {
|
|
|
|
case CAMERASTABSETTINGS_GIMBALTYPE_GENERIC:
|
|
|
|
case CAMERASTABSETTINGS_GIMBALTYPE_ROLLPITCHMIXED:
|
|
|
|
// no correction
|
|
|
|
break;
|
|
|
|
case CAMERASTABSETTINGS_GIMBALTYPE_YAWROLLPITCH:
|
|
|
|
if (index == CAMERASTABSETTINGS_INPUT_ROLL) {
|
|
|
|
float pitch;
|
2013-05-18 19:36:45 +02:00
|
|
|
AttitudeStatePitchGet(&pitch);
|
2013-09-01 12:10:55 +02:00
|
|
|
gimbalTypeCorrection = (cameraStab->OutputRange.Pitch - fabsf(pitch))
|
|
|
|
/ cameraStab->OutputRange.Pitch;
|
2013-05-18 14:17:26 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CAMERASTABSETTINGS_GIMBALTYPE_YAWPITCHROLL:
|
|
|
|
if (index == CAMERASTABSETTINGS_INPUT_PITCH) {
|
|
|
|
float roll;
|
2013-05-18 19:36:45 +02:00
|
|
|
AttitudeStateRollGet(&roll);
|
2013-09-01 12:10:55 +02:00
|
|
|
gimbalTypeCorrection = (cameraStab->OutputRange.Roll - fabsf(roll))
|
|
|
|
/ cameraStab->OutputRange.Roll;
|
2013-05-18 14:17:26 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PIOS_Assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply feed forward
|
|
|
|
float accumulator = csd->ffFilterAccumulator[index];
|
2013-09-01 12:10:55 +02:00
|
|
|
accumulator += (*attitude - csd->ffLastAttitude[index]) *
|
2014-08-24 00:16:34 +02:00
|
|
|
(float)CameraStabSettingsFeedForwardToArray(cameraStab->FeedForward)[index] * gimbalTypeCorrection;
|
2013-05-18 14:17:26 +02:00
|
|
|
csd->ffLastAttitude[index] = *attitude;
|
|
|
|
*attitude += accumulator;
|
|
|
|
|
2014-08-24 00:16:34 +02:00
|
|
|
float filter = (float)((accumulator > 0.0f) ? CameraStabSettingsAccelTimeToArray(cameraStab->AccelTime)[index] :
|
|
|
|
CameraStabSettingsDecelTimeToArray(cameraStab->DecelTime)[index]) / dT_millis;
|
2013-05-18 14:17:26 +02:00
|
|
|
if (filter < 1.0f) {
|
|
|
|
filter = 1.0f;
|
|
|
|
}
|
|
|
|
accumulator -= accumulator / filter;
|
|
|
|
csd->ffFilterAccumulator[index] = accumulator;
|
|
|
|
*attitude += accumulator;
|
|
|
|
|
|
|
|
// apply acceleration limit
|
|
|
|
float delta = *attitude - csd->ffLastAttitudeFiltered[index];
|
|
|
|
float maxDelta = (float)cameraStab->MaxAccel * 0.001f * dT_millis;
|
|
|
|
|
|
|
|
if (fabsf(delta) > maxDelta) {
|
|
|
|
// we are accelerating too hard
|
|
|
|
*attitude = csd->ffLastAttitudeFiltered[index] + ((delta > 0.0f) ? maxDelta : -maxDelta);
|
|
|
|
}
|
|
|
|
csd->ffLastAttitudeFiltered[index] = *attitude;
|
2012-11-17 15:18:37 +01:00
|
|
|
}
|
|
|
|
#endif // USE_GIMBAL_FF
|
|
|
|
|
2011-06-15 18:18:29 +02:00
|
|
|
/**
|
2013-05-18 14:17:26 +02:00
|
|
|
* @}
|
|
|
|
*/
|
2011-06-15 18:18:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|