mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 21:05:35 +03:00
Decouple min_check from throttle // Add modern expo calculation to throttle curve
This commit is contained in:
parent
b7c1c58abb
commit
58bcb981ed
7 changed files with 9 additions and 101 deletions
2
Makefile
2
Makefile
|
@ -594,7 +594,6 @@ COMMON_SRC = \
|
||||||
fc/fc_msp.c \
|
fc/fc_msp.c \
|
||||||
fc/fc_tasks.c \
|
fc/fc_tasks.c \
|
||||||
fc/rc_controls.c \
|
fc/rc_controls.c \
|
||||||
fc/rc_curves.c \
|
|
||||||
fc/runtime_config.c \
|
fc/runtime_config.c \
|
||||||
fc/cli.c \
|
fc/cli.c \
|
||||||
flight/altitudehold.c \
|
flight/altitudehold.c \
|
||||||
|
@ -714,7 +713,6 @@ SPEED_OPTIMISED_SRC := $(SPEED_OPTIMISED_SRC) \
|
||||||
fc/fc_tasks.c \
|
fc/fc_tasks.c \
|
||||||
fc/fc_rc.c \
|
fc/fc_rc.c \
|
||||||
fc/rc_controls.c \
|
fc/rc_controls.c \
|
||||||
fc/rc_curves.c \
|
|
||||||
fc/runtime_config.c \
|
fc/runtime_config.c \
|
||||||
flight/altitudehold.c \
|
flight/altitudehold.c \
|
||||||
flight/failsafe.c \
|
flight/failsafe.c \
|
||||||
|
|
|
@ -53,7 +53,6 @@
|
||||||
|
|
||||||
#include "fc/config.h"
|
#include "fc/config.h"
|
||||||
#include "fc/rc_controls.h"
|
#include "fc/rc_controls.h"
|
||||||
#include "fc/rc_curves.h"
|
|
||||||
#include "fc/runtime_config.h"
|
#include "fc/runtime_config.h"
|
||||||
|
|
||||||
#include "sensors/sensors.h"
|
#include "sensors/sensors.h"
|
||||||
|
@ -882,15 +881,8 @@ static void resetConf(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void activateControlRateConfig(void)
|
|
||||||
{
|
|
||||||
generateThrottleCurve(currentControlRateProfile, &masterConfig.motorConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
void activateConfig(void)
|
void activateConfig(void)
|
||||||
{
|
{
|
||||||
activateControlRateConfig();
|
|
||||||
|
|
||||||
resetAdjustmentStates();
|
resetAdjustmentStates();
|
||||||
|
|
||||||
useRcControlsConfig(
|
useRcControlsConfig(
|
||||||
|
@ -1168,7 +1160,6 @@ void changeControlRateProfile(uint8_t profileIndex)
|
||||||
profileIndex = MAX_RATEPROFILES - 1;
|
profileIndex = MAX_RATEPROFILES - 1;
|
||||||
}
|
}
|
||||||
setControlRateProfile(profileIndex);
|
setControlRateProfile(profileIndex);
|
||||||
activateControlRateConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void beeperOffSet(uint32_t mask)
|
void beeperOffSet(uint32_t mask)
|
||||||
|
|
|
@ -41,7 +41,6 @@
|
||||||
|
|
||||||
#include "fc/config.h"
|
#include "fc/config.h"
|
||||||
#include "fc/rc_controls.h"
|
#include "fc/rc_controls.h"
|
||||||
#include "fc/rc_curves.h"
|
|
||||||
#include "fc/runtime_config.h"
|
#include "fc/runtime_config.h"
|
||||||
#include "fc/cli.h"
|
#include "fc/cli.h"
|
||||||
#include "fc/fc_rc.h"
|
#include "fc/fc_rc.h"
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
|
@ -29,7 +30,6 @@
|
||||||
|
|
||||||
#include "fc/config.h"
|
#include "fc/config.h"
|
||||||
#include "fc/rc_controls.h"
|
#include "fc/rc_controls.h"
|
||||||
#include "fc/rc_curves.h"
|
|
||||||
#include "fc/runtime_config.h"
|
#include "fc/runtime_config.h"
|
||||||
#include "fc/fc_rc.h"
|
#include "fc/fc_rc.h"
|
||||||
#include "fc/fc_core.h"
|
#include "fc/fc_core.h"
|
||||||
|
@ -266,7 +266,14 @@ void updateRcCommands(void)
|
||||||
tmp = constrain(rcData[THROTTLE], rxConfig()->mincheck, PWM_RANGE_MAX);
|
tmp = constrain(rcData[THROTTLE], rxConfig()->mincheck, PWM_RANGE_MAX);
|
||||||
tmp = (uint32_t)(tmp - rxConfig()->mincheck) * PWM_RANGE_MIN / (PWM_RANGE_MAX - rxConfig()->mincheck);
|
tmp = (uint32_t)(tmp - rxConfig()->mincheck) * PWM_RANGE_MIN / (PWM_RANGE_MAX - rxConfig()->mincheck);
|
||||||
}
|
}
|
||||||
rcCommand[THROTTLE] = rcLookupThrottle(tmp);
|
|
||||||
|
if (currentControlRateProfile->thrExpo8) {
|
||||||
|
float expof = currentControlRateProfile->thrExpo8 / 100.0f;
|
||||||
|
float tmpf = (tmp / (PWM_RANGE_MAX - PWM_RANGE_MIN));
|
||||||
|
tmp = lrintf(tmp * sq(tmpf) * expof + tmp * (1-expof));
|
||||||
|
}
|
||||||
|
|
||||||
|
rcCommand[THROTTLE] = tmp + (PWM_RANGE_MAX - PWM_RANGE_MIN);
|
||||||
|
|
||||||
if (feature(FEATURE_3D) && IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH) && !failsafeIsActive()) {
|
if (feature(FEATURE_3D) && IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH) && !failsafeIsActive()) {
|
||||||
fix12_t throttleScaler = qConstruct(rcCommand[THROTTLE] - 1000, 1000);
|
fix12_t throttleScaler = qConstruct(rcCommand[THROTTLE] - 1000, 1000);
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
#include "fc/config.h"
|
#include "fc/config.h"
|
||||||
#include "fc/fc_core.h"
|
#include "fc/fc_core.h"
|
||||||
#include "fc/rc_controls.h"
|
#include "fc/rc_controls.h"
|
||||||
#include "fc/rc_curves.h"
|
|
||||||
#include "fc/runtime_config.h"
|
#include "fc/runtime_config.h"
|
||||||
|
|
||||||
#include "io/gps.h"
|
#include "io/gps.h"
|
||||||
|
@ -524,7 +523,6 @@ static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t
|
||||||
case ADJUSTMENT_THROTTLE_EXPO:
|
case ADJUSTMENT_THROTTLE_EXPO:
|
||||||
newValue = constrain((int)controlRateConfig->thrExpo8 + delta, 0, 100); // FIXME magic numbers repeated in cli.c
|
newValue = constrain((int)controlRateConfig->thrExpo8 + delta, 0, 100); // FIXME magic numbers repeated in cli.c
|
||||||
controlRateConfig->thrExpo8 = newValue;
|
controlRateConfig->thrExpo8 = newValue;
|
||||||
generateThrottleCurve(controlRateConfig, motorConfig);
|
|
||||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_THROTTLE_EXPO, newValue);
|
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_THROTTLE_EXPO, newValue);
|
||||||
break;
|
break;
|
||||||
case ADJUSTMENT_PITCH_ROLL_RATE:
|
case ADJUSTMENT_PITCH_ROLL_RATE:
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of Cleanflight.
|
|
||||||
*
|
|
||||||
* Cleanflight 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.
|
|
||||||
*
|
|
||||||
* Cleanflight 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 Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "platform.h"
|
|
||||||
|
|
||||||
#include "config/feature.h"
|
|
||||||
|
|
||||||
#include "io/motors.h"
|
|
||||||
|
|
||||||
#include "fc/config.h"
|
|
||||||
#include "fc/rc_curves.h"
|
|
||||||
#include "fc/rc_controls.h"
|
|
||||||
|
|
||||||
#include "rx/rx.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define THROTTLE_LOOKUP_LENGTH 12
|
|
||||||
static int16_t lookupThrottleRC[THROTTLE_LOOKUP_LENGTH]; // lookup table for expo & mid THROTTLE
|
|
||||||
|
|
||||||
void generateThrottleCurve(controlRateConfig_t *controlRateConfig, motorConfig_t *motorConfig)
|
|
||||||
{
|
|
||||||
uint8_t i;
|
|
||||||
uint16_t minThrottle = (feature(FEATURE_3D && IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH)) ? PWM_RANGE_MIN : motorConfig->minthrottle);
|
|
||||||
|
|
||||||
for (i = 0; i < THROTTLE_LOOKUP_LENGTH; i++) {
|
|
||||||
int16_t tmp = 10 * i - controlRateConfig->thrMid8;
|
|
||||||
uint8_t y = 1;
|
|
||||||
if (tmp > 0)
|
|
||||||
y = 100 - controlRateConfig->thrMid8;
|
|
||||||
if (tmp < 0)
|
|
||||||
y = controlRateConfig->thrMid8;
|
|
||||||
lookupThrottleRC[i] = 10 * controlRateConfig->thrMid8 + tmp * (100 - controlRateConfig->thrExpo8 + (int32_t) controlRateConfig->thrExpo8 * (tmp * tmp) / (y * y)) / 10;
|
|
||||||
lookupThrottleRC[i] = minThrottle + (int32_t) (motorConfig->maxthrottle - minThrottle) * lookupThrottleRC[i] / 1000; // [MINTHROTTLE;MAXTHROTTLE]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int16_t rcLookupThrottle(int32_t tmp)
|
|
||||||
{
|
|
||||||
const int32_t tmp2 = tmp / 100;
|
|
||||||
// [0;1000] -> expo -> [MINTHROTTLE;MAXTHROTTLE]
|
|
||||||
return lookupThrottleRC[tmp2] + (tmp - tmp2 * 100) * (lookupThrottleRC[tmp2 + 1] - lookupThrottleRC[tmp2]) / 100;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of Cleanflight.
|
|
||||||
*
|
|
||||||
* Cleanflight 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.
|
|
||||||
*
|
|
||||||
* Cleanflight 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 Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
struct controlRateConfig_s;
|
|
||||||
struct motorConfig_s;
|
|
||||||
void generateThrottleCurve(struct controlRateConfig_s *controlRateConfig, struct motorConfig_s *motorConfig);
|
|
||||||
|
|
||||||
int16_t rcLookupThrottle(int32_t tmp);
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue