Merge pull request #2872 from cleanflight/fix-servo-filtering
CF/BF - Fix servo filter initialisation.
This commit is contained in:
parent
b052c60fd0
commit
545e30e3c4
|
@ -502,6 +502,10 @@ void init(void)
|
||||||
// gyro.targetLooptime set in sensorsAutodetect(), so we are ready to call pidInit()
|
// gyro.targetLooptime set in sensorsAutodetect(), so we are ready to call pidInit()
|
||||||
pidInit(currentPidProfile);
|
pidInit(currentPidProfile);
|
||||||
|
|
||||||
|
#ifdef USE_SERVOS
|
||||||
|
servosFilterInit();
|
||||||
|
#endif
|
||||||
|
|
||||||
imuInit();
|
imuInit();
|
||||||
|
|
||||||
mspFcInit();
|
mspFcInit();
|
||||||
|
|
|
@ -499,23 +499,25 @@ bool isMixerUsingServos(void)
|
||||||
return useServo;
|
return useServo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static biquadFilter_t servoFilter[MAX_SUPPORTED_SERVOS];
|
||||||
|
|
||||||
|
void servosFilterInit(void)
|
||||||
|
{
|
||||||
|
if (servoConfig()->servo_lowpass_freq) {
|
||||||
|
for (int servoIdx = 0; servoIdx < MAX_SUPPORTED_SERVOS; servoIdx++) {
|
||||||
|
biquadFilterInitLPF(&servoFilter[servoIdx], servoConfig()->servo_lowpass_freq, targetPidLooptime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
static void filterServos(void)
|
static void filterServos(void)
|
||||||
{
|
{
|
||||||
static int16_t servoIdx;
|
|
||||||
static bool servoFilterIsSet;
|
|
||||||
static biquadFilter_t servoFilter[MAX_SUPPORTED_SERVOS];
|
|
||||||
|
|
||||||
#if defined(MIXER_DEBUG)
|
#if defined(MIXER_DEBUG)
|
||||||
uint32_t startTime = micros();
|
uint32_t startTime = micros();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (servoConfig()->servo_lowpass_freq) {
|
if (servoConfig()->servo_lowpass_freq) {
|
||||||
for (servoIdx = 0; servoIdx < MAX_SUPPORTED_SERVOS; servoIdx++) {
|
for (int servoIdx = 0; servoIdx < MAX_SUPPORTED_SERVOS; servoIdx++) {
|
||||||
if (!servoFilterIsSet) {
|
|
||||||
biquadFilterInitLPF(&servoFilter[servoIdx], servoConfig()->servo_lowpass_freq, targetPidLooptime);
|
|
||||||
servoFilterIsSet = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
servo[servoIdx] = lrintf(biquadFilterApply(&servoFilter[servoIdx], (float)servo[servoIdx]));
|
servo[servoIdx] = lrintf(biquadFilterApply(&servoFilter[servoIdx], (float)servo[servoIdx]));
|
||||||
// Sanity check
|
// Sanity check
|
||||||
servo[servoIdx] = constrain(servo[servoIdx], servoParams(servoIdx)->min, servoParams(servoIdx)->max);
|
servo[servoIdx] = constrain(servo[servoIdx], servoParams(servoIdx)->min, servoParams(servoIdx)->max);
|
||||||
|
|
|
@ -132,3 +132,4 @@ void loadCustomServoMixer(void);
|
||||||
int servoDirection(int servoIndex, int fromChannel);
|
int servoDirection(int servoIndex, int fromChannel);
|
||||||
void servoConfigureOutput(void);
|
void servoConfigureOutput(void);
|
||||||
void servosInit(void);
|
void servosInit(void);
|
||||||
|
void servosFilterInit(void);
|
||||||
|
|
Loading…
Reference in New Issue