1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-18 05:45:31 +03:00

Added more options for RC interpolation channel selection.

This commit is contained in:
mikeller 2018-06-04 22:41:54 +12:00
parent 6fa1a26e71
commit 9738a1cdd2
4 changed files with 70 additions and 24 deletions

View file

@ -59,6 +59,15 @@ static bool reverseMotors = false;
static applyRatesFn *applyRates; static applyRatesFn *applyRates;
uint16_t currentRxRefreshRate; uint16_t currentRxRefreshRate;
FAST_RAM_ZERO_INIT uint8_t interpolationChannels;
enum {
ROLL_FLAG = 1 << ROLL,
PITCH_FLAG = 1 << PITCH,
YAW_FLAG = 1 << YAW,
THROTTLE_FLAG = 1 << THROTTLE,
};
#ifdef USE_RC_SMOOTHING_FILTER #ifdef USE_RC_SMOOTHING_FILTER
#define RC_SMOOTHING_FILTER_TRAINING_DELAY_MS 3000 // Wait 3 seconds after power to let the PID loop stabilize before starting average frame rate calculation #define RC_SMOOTHING_FILTER_TRAINING_DELAY_MS 3000 // Wait 3 seconds after power to let the PID loop stabilize before starting average frame rate calculation
#define RC_SMOOTHING_FILTER_TRAINING_SAMPLES 50 #define RC_SMOOTHING_FILTER_TRAINING_SAMPLES 50
@ -197,7 +206,6 @@ FAST_CODE uint8_t processRcInterpolation(void)
static FAST_RAM_ZERO_INIT float rcStepSize[4]; static FAST_RAM_ZERO_INIT float rcStepSize[4];
static FAST_RAM_ZERO_INIT int16_t rcInterpolationStepCount; static FAST_RAM_ZERO_INIT int16_t rcInterpolationStepCount;
const uint8_t interpolationChannels = rxConfig()->rcInterpolationChannels + 2; //"RP", "RPY", "RPYT"
uint16_t rxRefreshRate; uint16_t rxRefreshRate;
uint8_t updatedChannel = 0; uint8_t updatedChannel = 0;
@ -219,8 +227,10 @@ FAST_CODE uint8_t processRcInterpolation(void)
if (isRXDataNew && rxRefreshRate > 0) { if (isRXDataNew && rxRefreshRate > 0) {
rcInterpolationStepCount = rxRefreshRate / targetPidLooptime; rcInterpolationStepCount = rxRefreshRate / targetPidLooptime;
for (int channel = ROLL; channel < interpolationChannels; channel++) { for (int channel = ROLL; channel <= THROTTLE; channel++) {
rcStepSize[channel] = (rcCommand[channel] - rcCommandInterp[channel]) / (float)rcInterpolationStepCount; if ((1 << channel) & interpolationChannels) {
rcStepSize[channel] = (rcCommand[channel] - rcCommandInterp[channel]) / (float)rcInterpolationStepCount;
}
} }
DEBUG_SET(DEBUG_RC_INTERPOLATION, 0, lrintf(rcCommand[0])); DEBUG_SET(DEBUG_RC_INTERPOLATION, 0, lrintf(rcCommand[0]));
@ -231,9 +241,11 @@ FAST_CODE uint8_t processRcInterpolation(void)
// Interpolate steps of rcCommand // Interpolate steps of rcCommand
if (rcInterpolationStepCount > 0) { if (rcInterpolationStepCount > 0) {
for (updatedChannel = ROLL; updatedChannel < interpolationChannels; updatedChannel++) { for (updatedChannel = ROLL; updatedChannel <= THROTTLE; updatedChannel++) {
rcCommandInterp[updatedChannel] += rcStepSize[updatedChannel]; if ((1 << updatedChannel) & interpolationChannels) {
rcCommand[updatedChannel] = rcCommandInterp[updatedChannel]; rcCommandInterp[updatedChannel] += rcStepSize[updatedChannel];
rcCommand[updatedChannel] = rcCommandInterp[updatedChannel];
}
} }
} }
} else { } else {
@ -254,7 +266,6 @@ uint8_t calcRcSmoothingCutoff(float avgRxFrameRate, float filterBaseline)
FAST_CODE uint8_t processRcSmoothingFilter(void) FAST_CODE uint8_t processRcSmoothingFilter(void)
{ {
uint8_t updatedChannel = 0; uint8_t updatedChannel = 0;
static FAST_RAM_ZERO_INIT float lastRxData[4]; static FAST_RAM_ZERO_INIT float lastRxData[4];
@ -268,18 +279,18 @@ FAST_CODE uint8_t processRcSmoothingFilter(void)
static FAST_RAM_ZERO_INIT uint16_t defaultDerivativeCutoffFrequency; static FAST_RAM_ZERO_INIT uint16_t defaultDerivativeCutoffFrequency;
static FAST_RAM_ZERO_INIT uint16_t filterCutoffFrequency; static FAST_RAM_ZERO_INIT uint16_t filterCutoffFrequency;
static FAST_RAM_ZERO_INIT uint16_t derivativeCutoffFrequency; static FAST_RAM_ZERO_INIT uint16_t derivativeCutoffFrequency;
static FAST_RAM_ZERO_INIT uint8_t interpolationChannels;
if (!initialized) { if (!initialized) {
initialized = true; initialized = true;
interpolationChannels = rxConfig()->rcInterpolationChannels + 2; //"RP", "RPY", "RPYT"
filterCutoffFrequency = rxConfig()->rc_smoothing_input_cutoff; filterCutoffFrequency = rxConfig()->rc_smoothing_input_cutoff;
derivativeCutoffFrequency = rxConfig()->rc_smoothing_derivative_cutoff; derivativeCutoffFrequency = rxConfig()->rc_smoothing_derivative_cutoff;
} }
if (isRXDataNew) { if (isRXDataNew) {
for (int i = 0; i < interpolationChannels; i++) { for (int i = 0; i <= THROTTLE; i++) {
lastRxData[i] = rcCommand[i]; if ((1 << i) & interpolationChannels) {
lastRxData[i] = rcCommand[i];
}
} }
// If the filter cutoffs are set to auto and we have good rx data, then determine the average rx frame rate // If the filter cutoffs are set to auto and we have good rx data, then determine the average rx frame rate
// and use that to calculate the filter cutoff frequencies // and use that to calculate the filter cutoff frequencies
@ -295,15 +306,17 @@ FAST_CODE uint8_t processRcSmoothingFilter(void)
derivativeCutoffFrequency = (derivativeCutoffFrequency == 0) ? defaultDerivativeCutoffFrequency : derivativeCutoffFrequency; derivativeCutoffFrequency = (derivativeCutoffFrequency == 0) ? defaultDerivativeCutoffFrequency : derivativeCutoffFrequency;
const float dT = targetPidLooptime * 1e-6f; const float dT = targetPidLooptime * 1e-6f;
for (int i = 0; i < interpolationChannels; i++) { for (int i = 0; i <= THROTTLE; i++) {
switch (rxConfig()->rc_smoothing_input_type) { if ((1 << i) & interpolationChannels) {
case RC_SMOOTHING_INPUT_BIQUAD: switch (rxConfig()->rc_smoothing_input_type) {
biquadFilterInitLPF(&rcCommandFilterBiquad[i], filterCutoffFrequency, targetPidLooptime); case RC_SMOOTHING_INPUT_BIQUAD:
break; biquadFilterInitLPF(&rcCommandFilterBiquad[i], filterCutoffFrequency, targetPidLooptime);
case RC_SMOOTHING_INPUT_PT1: break;
default: case RC_SMOOTHING_INPUT_PT1:
pt1FilterInit(&rcCommandFilterPt1[i], pt1FilterGain(filterCutoffFrequency, dT)); default:
break; pt1FilterInit(&rcCommandFilterPt1[i], pt1FilterGain(filterCutoffFrequency, dT));
break;
}
} }
} }
pidInitSetpointDerivativeLpf(derivativeCutoffFrequency, rxConfig()->rc_smoothing_debug_axis, rxConfig()->rc_smoothing_derivative_type); pidInitSetpointDerivativeLpf(derivativeCutoffFrequency, rxConfig()->rc_smoothing_debug_axis, rxConfig()->rc_smoothing_derivative_type);
@ -319,8 +332,8 @@ FAST_CODE uint8_t processRcSmoothingFilter(void)
DEBUG_SET(DEBUG_RC_SMOOTHING, 0, lrintf(lastRxData[rxConfig()->rc_smoothing_debug_axis])); DEBUG_SET(DEBUG_RC_SMOOTHING, 0, lrintf(lastRxData[rxConfig()->rc_smoothing_debug_axis]));
DEBUG_SET(DEBUG_RC_SMOOTHING, 3, defaultInputCutoffFrequency); DEBUG_SET(DEBUG_RC_SMOOTHING, 3, defaultInputCutoffFrequency);
for (updatedChannel = ROLL; updatedChannel < interpolationChannels; updatedChannel++) { for (updatedChannel = ROLL; updatedChannel <= THROTTLE; updatedChannel++) {
if (filterInitialized) { if (filterInitialized && (1 << updatedChannel) & interpolationChannels) {
switch (rxConfig()->rc_smoothing_input_type) { switch (rxConfig()->rc_smoothing_input_type) {
case RC_SMOOTHING_INPUT_BIQUAD: case RC_SMOOTHING_INPUT_BIQUAD:
rcCommand[updatedChannel] = biquadFilterApply(&rcCommandFilterBiquad[updatedChannel], lastRxData[updatedChannel]); rcCommand[updatedChannel] = biquadFilterApply(&rcCommandFilterBiquad[updatedChannel], lastRxData[updatedChannel]);
@ -517,4 +530,28 @@ void initRcProcessing(void)
break; break;
} }
interpolationChannels = 0;
switch (rxConfig()->rcInterpolationChannels) {
case INTERPOLATION_CHANNELS_RPYT:
interpolationChannels |= THROTTLE_FLAG;
FALLTHROUGH;
case INTERPOLATION_CHANNELS_RPY:
interpolationChannels |= YAW_FLAG;
FALLTHROUGH;
case INTERPOLATION_CHANNELS_RP:
interpolationChannels |= ROLL_FLAG | PITCH_FLAG;
break;
case INTERPOLATION_CHANNELS_T:
interpolationChannels |= THROTTLE_FLAG;
FALLTHROUGH;
case INTERPOLATION_CHANNELS_RPT:
interpolationChannels |= ROLL_FLAG | PITCH_FLAG;
break;
}
} }

View file

@ -20,6 +20,14 @@
#pragma once #pragma once
typedef enum {
INTERPOLATION_CHANNELS_RP,
INTERPOLATION_CHANNELS_RPY,
INTERPOLATION_CHANNELS_RPYT,
INTERPOLATION_CHANNELS_T,
INTERPOLATION_CHANNELS_RPT,
} interpolationChannels_e;
extern uint16_t currentRxRefreshRate; extern uint16_t currentRxRefreshRate;
void processRcCommand(void); void processRcCommand(void);

View file

@ -259,7 +259,7 @@ static const char * const lookupTableRcInterpolation[] = {
}; };
static const char * const lookupTableRcInterpolationChannels[] = { static const char * const lookupTableRcInterpolationChannels[] = {
"RP", "RPY", "RPYT" "RP", "RPY", "RPYT", "T", "RPT",
}; };
static const char * const lookupTableLowpassType[] = { static const char * const lookupTableLowpassType[] = {

View file

@ -29,6 +29,7 @@
#include "config/config_reset.h" #include "config/config_reset.h"
#include "drivers/io.h" #include "drivers/io.h"
#include "fc/fc_rc.h"
#include "fc/rc_controls.h" #include "fc/rc_controls.h"
#include "rx/rx.h" #include "rx/rx.h"
#include "rx/rx_spi.h" #include "rx/rx_spi.h"
@ -55,7 +56,7 @@ void pgResetFn_rxConfig(rxConfig_t *rxConfig)
.rssi_offset = 0, .rssi_offset = 0,
.rssi_invert = 0, .rssi_invert = 0,
.rcInterpolation = RC_SMOOTHING_AUTO, .rcInterpolation = RC_SMOOTHING_AUTO,
.rcInterpolationChannels = 0, .rcInterpolationChannels = INTERPOLATION_CHANNELS_RP,
.rcInterpolationInterval = 19, .rcInterpolationInterval = 19,
.fpvCamAngleDegrees = 0, .fpvCamAngleDegrees = 0,
.airModeActivateThreshold = 32, .airModeActivateThreshold = 32,