mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 17:55:30 +03:00
precalculate divisors in initRcProcessing
This commit is contained in:
parent
04e5e3bf24
commit
57a5fd937a
1 changed files with 19 additions and 4 deletions
|
@ -71,6 +71,8 @@ static bool reverseMotors = false;
|
||||||
static applyRatesFn *applyRates;
|
static applyRatesFn *applyRates;
|
||||||
static uint16_t currentRxRefreshRate;
|
static uint16_t currentRxRefreshRate;
|
||||||
static bool isRxDataNew = false;
|
static bool isRxDataNew = false;
|
||||||
|
static float rcCommandDivider = 500.0f;
|
||||||
|
static float rcCommandYawDivider = 500.0f;
|
||||||
|
|
||||||
FAST_RAM_ZERO_INIT uint8_t interpolationChannels;
|
FAST_RAM_ZERO_INIT uint8_t interpolationChannels;
|
||||||
static FAST_RAM_ZERO_INIT uint32_t rcFrameNumber;
|
static FAST_RAM_ZERO_INIT uint32_t rcFrameNumber;
|
||||||
|
@ -231,6 +233,7 @@ float getRcCurveSlope(int axis, float deflection)
|
||||||
static void calculateSetpointRate(int axis)
|
static void calculateSetpointRate(int axis)
|
||||||
{
|
{
|
||||||
float angleRate;
|
float angleRate;
|
||||||
|
float rcCommandf;
|
||||||
|
|
||||||
#ifdef USE_GPS_RESCUE
|
#ifdef USE_GPS_RESCUE
|
||||||
if ((axis == FD_YAW) && FLIGHT_MODE(GPS_RESCUE_MODE)) {
|
if ((axis == FD_YAW) && FLIGHT_MODE(GPS_RESCUE_MODE)) {
|
||||||
|
@ -244,9 +247,13 @@ static void calculateSetpointRate(int axis)
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
const uint8_t deadband = axis == FD_YAW ? rcControlsConfig()->yaw_deadband : rcControlsConfig()->deadband;
|
|
||||||
// scale rcCommandf to range [-1.0, 1.0]
|
// scale rcCommandf to range [-1.0, 1.0]
|
||||||
float rcCommandf = rcCommand[axis] / (500.0f - deadband);
|
if (axis == FD_YAW) {
|
||||||
|
rcCommandf = rcCommand[axis] / rcCommandYawDivider;
|
||||||
|
} else {
|
||||||
|
rcCommandf = rcCommand[axis] / rcCommandDivider;
|
||||||
|
}
|
||||||
|
|
||||||
rcDeflection[axis] = rcCommandf;
|
rcDeflection[axis] = rcCommandf;
|
||||||
const float rcCommandfAbs = fabsf(rcCommandf);
|
const float rcCommandfAbs = fabsf(rcCommandf);
|
||||||
rcDeflectionAbs[axis] = rcCommandfAbs;
|
rcDeflectionAbs[axis] = rcCommandfAbs;
|
||||||
|
@ -683,10 +690,15 @@ FAST_CODE void processRcCommand(void)
|
||||||
|
|
||||||
#ifdef USE_INTERPOLATED_SP
|
#ifdef USE_INTERPOLATED_SP
|
||||||
if (isRxDataNew) {
|
if (isRxDataNew) {
|
||||||
|
float rcCommandf;
|
||||||
|
|
||||||
for (int i = FD_ROLL; i <= FD_YAW; i++) {
|
for (int i = FD_ROLL; i <= FD_YAW; i++) {
|
||||||
oldRcCommand[i] = rcCommand[i];
|
oldRcCommand[i] = rcCommand[i];
|
||||||
const uint8_t deadband = i == FD_YAW ? rcControlsConfig()->yaw_deadband : rcControlsConfig()->deadband;
|
if (i == FD_YAW) {
|
||||||
const float rcCommandf = rcCommand[i] / (500.0f - deadband);
|
rcCommandf = rcCommand[i] / rcCommandYawDivider;
|
||||||
|
} else {
|
||||||
|
rcCommandf = rcCommand[i] / rcCommandDivider;
|
||||||
|
}
|
||||||
const float rcCommandfAbs = fabsf(rcCommandf);
|
const float rcCommandfAbs = fabsf(rcCommandf);
|
||||||
rawSetpoint[i] = applyRates(i, rcCommandf, rcCommandfAbs);
|
rawSetpoint[i] = applyRates(i, rcCommandf, rcCommandfAbs);
|
||||||
rawDeflection[i] = rcCommandf;
|
rawDeflection[i] = rcCommandf;
|
||||||
|
@ -837,6 +849,9 @@ bool isMotorsReversed(void)
|
||||||
|
|
||||||
void initRcProcessing(void)
|
void initRcProcessing(void)
|
||||||
{
|
{
|
||||||
|
rcCommandDivider = 500.0f - rcControlsConfig()->deadband;
|
||||||
|
rcCommandYawDivider = 500.0f - rcControlsConfig()->yaw_deadband;
|
||||||
|
|
||||||
for (int i = 0; i < THROTTLE_LOOKUP_LENGTH; i++) {
|
for (int i = 0; i < THROTTLE_LOOKUP_LENGTH; i++) {
|
||||||
const int16_t tmp = 10 * i - currentControlRateProfile->thrMid8;
|
const int16_t tmp = 10 * i - currentControlRateProfile->thrMid8;
|
||||||
uint8_t y = 1;
|
uint8_t y = 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue