mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 16:25:31 +03:00
Allow autotune to be compiled in/out.
This commit is contained in:
parent
a6f4633272
commit
326a10b1dc
10 changed files with 30 additions and 2 deletions
4
Makefile
4
Makefile
|
@ -127,7 +127,6 @@ COMMON_SRC = build_config.c \
|
|||
common/typeconversion.c \
|
||||
main.c \
|
||||
mw.c \
|
||||
flight/autotune.c \
|
||||
flight/altitudehold.c \
|
||||
flight/failsafe.c \
|
||||
flight/flight.c \
|
||||
|
@ -156,7 +155,8 @@ COMMON_SRC = build_config.c \
|
|||
$(CMSIS_SRC) \
|
||||
$(DEVICE_STDPERIPH_SRC)
|
||||
|
||||
HIGHEND_SRC = io/gps.c \
|
||||
HIGHEND_SRC = flight/autotune.c \
|
||||
io/gps.c \
|
||||
io/gps_conversion.c \
|
||||
io/ledstrip.c \
|
||||
rx/sbus.c \
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#ifdef AUTOTUNE
|
||||
|
||||
#include "common/axis.h"
|
||||
#include "common/maths.h"
|
||||
|
||||
|
@ -384,3 +388,4 @@ bool havePidsBeenUpdatedByAutotune(void)
|
|||
return targetAngle != 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -76,10 +76,12 @@ void resetErrorGyro(void)
|
|||
|
||||
const angle_index_t rcAliasToAngleIndexMap[] = { AI_ROLL, AI_PITCH };
|
||||
|
||||
#ifdef AUTOTUNE
|
||||
bool shouldAutotune(void)
|
||||
{
|
||||
return f.ARMED && f.AUTOTUNE_MODE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void pidBaseflight(pidProfile_t *pidProfile, controlRateConfig_t *controlRateConfig,
|
||||
uint16_t max_angle_inclination, rollAndPitchTrims_t *angleTrim)
|
||||
|
@ -109,9 +111,12 @@ static void pidBaseflight(pidProfile_t *pidProfile, controlRateConfig_t *control
|
|||
errorAngle = (constrain(rcCommand[axis], -((int) max_angle_inclination),
|
||||
+max_angle_inclination) - inclination.raw[axis] + angleTrim->raw[axis]) / 10.0f; // 16 bits is ok here
|
||||
#endif
|
||||
|
||||
#ifdef AUTOTUNE
|
||||
if (shouldAutotune()) {
|
||||
errorAngle = autotune(rcAliasToAngleIndexMap[axis], &inclination, errorAngle);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (f.ANGLE_MODE) {
|
||||
// it's the ANGLE mode - control is angle based, so control loop is needed
|
||||
|
@ -186,9 +191,11 @@ static void pidMultiWii(pidProfile_t *pidProfile, controlRateConfig_t *controlRa
|
|||
+max_angle_inclination) - inclination.raw[axis] + angleTrim->raw[axis];
|
||||
#endif
|
||||
|
||||
#ifdef AUTOTUNE
|
||||
if (shouldAutotune()) {
|
||||
errorAngle = DEGREES_TO_DECIDEGREES(autotune(rcAliasToAngleIndexMap[axis], &inclination, DECIDEGREES_TO_DEGREES(errorAngle)));
|
||||
}
|
||||
#endif
|
||||
|
||||
PTermACC = errorAngle * pidProfile->P8[PIDLEVEL] / 100; // 32 bits is needed for calculation: errorAngle*P8[PIDLEVEL] could exceed 32768 16 bits is ok for result
|
||||
PTermACC = constrain(PTermACC, -pidProfile->D8[PIDLEVEL] * 5, +pidProfile->D8[PIDLEVEL] * 5);
|
||||
|
@ -259,9 +266,12 @@ static void pidRewrite(pidProfile_t *pidProfile, controlRateConfig_t *controlRat
|
|||
errorAngle = constrain(2 * rcCommand[axis], -((int) max_angle_inclination),
|
||||
+max_angle_inclination) - inclination.raw[axis] + angleTrim->raw[axis]; // 16 bits is ok here
|
||||
#endif
|
||||
|
||||
#ifdef AUTOTUNE
|
||||
if (shouldAutotune()) {
|
||||
errorAngle = DEGREES_TO_DECIDEGREES(autotune(rcAliasToAngleIndexMap[axis], &inclination, DECIDEGREES_TO_DEGREES(errorAngle)));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!f.ANGLE_MODE) { //control is GYRO based (ACRO and HORIZON - direct sticks control is applied to rate PID
|
||||
AngleRateTmp = ((int32_t)(controlRateConfig->rollPitchRate + 27) * rcCommand[axis]) >> 4;
|
||||
|
|
|
@ -100,6 +100,8 @@ void applyAndSaveAccelerometerTrimsDelta(rollAndPitchTrims_t *rollAndPitchTrimsD
|
|||
saveAndReloadCurrentProfileToCurrentProfileSlot();
|
||||
}
|
||||
|
||||
#ifdef AUTOTUNE
|
||||
|
||||
void updateAutotuneState(void)
|
||||
{
|
||||
static bool landedAfterAutoTuning = false;
|
||||
|
@ -134,6 +136,7 @@ void updateAutotuneState(void)
|
|||
landedAfterAutoTuning = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool isCalibrating()
|
||||
{
|
||||
|
@ -590,7 +593,10 @@ void loop(void)
|
|||
#ifdef BARO
|
||||
haveProcessedAnnexCodeOnce = true;
|
||||
#endif
|
||||
|
||||
#ifdef AUTOTUNE
|
||||
updateAutotuneState();
|
||||
#endif
|
||||
|
||||
#ifdef MAG
|
||||
if (sensors(SENSOR_MAG)) {
|
||||
|
|
|
@ -34,3 +34,4 @@
|
|||
#define TELEMETRY
|
||||
#define SOFT_SERIAL
|
||||
#define SERIAL_RX
|
||||
#define AUTOTUNE
|
||||
|
|
|
@ -49,3 +49,4 @@
|
|||
#define TELEMETRY
|
||||
#define SOFT_SERIAL
|
||||
#define SERIAL_RX
|
||||
#define AUTOTUNE
|
||||
|
|
|
@ -55,3 +55,4 @@
|
|||
#define TELEMETRY
|
||||
#define SOFT_SERIAL
|
||||
#define SERIAL_RX
|
||||
#define AUTOTUNE
|
||||
|
|
|
@ -39,3 +39,4 @@
|
|||
#define TELEMETRY
|
||||
#define SOFT_SERIAL
|
||||
#define SERIAL_RX
|
||||
#define AUTOTUNE
|
||||
|
|
|
@ -53,3 +53,5 @@
|
|||
#define TELEMETRY
|
||||
#define SOFT_SERIAL
|
||||
#define SERIAL_RX
|
||||
#define AUTOTUNE
|
||||
|
||||
|
|
|
@ -51,3 +51,4 @@
|
|||
#define TELEMETRY
|
||||
#define SOFT_SERIAL
|
||||
#define SERIAL_RX
|
||||
#define AUTOTUNE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue