Skip to content
Open

Q-Tune #8546

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
00f4dbd
Push raw data
DzikuVx Oct 6, 2021
0d959d3
Compute error, filter and store data vectors
DzikuVx Oct 6, 2021
3386ed1
Compute and log basic statistics
DzikuVx Oct 6, 2021
d14217b
Correctly compute windows
DzikuVx Oct 6, 2021
66eb351
Normalize all data
DzikuVx Oct 6, 2021
04d0aa2
Update sampling and filtering frequencies. Feed gyro analyze data
DzikuVx Oct 7, 2021
b229ca9
Feed ITerm
DzikuVx Oct 7, 2021
04e833e
Compute setpoint derivative
DzikuVx Oct 8, 2021
b3baa78
Two separate buffers for data
DzikuVx Oct 10, 2021
4544f46
Fix RMS and StdDev computation
DzikuVx Oct 10, 2021
890df3d
Log Error and Iterm frequency
DzikuVx Oct 18, 2021
06c631d
Drop iTerm FFT
DzikuVx Oct 21, 2021
0cc19f5
Drop setpoint table
DzikuVx Oct 21, 2021
120b878
Drop mesurement buffer
DzikuVx Oct 21, 2021
7350130
Drop unused field
DzikuVx Oct 23, 2021
9347aca
Log FFT energy
DzikuVx Oct 23, 2021
b2f028f
Attach 10Hz HPF to error
DzikuVx Oct 23, 2021
a786f87
Basic osicllation detector
DzikuVx Oct 26, 2021
3423a5f
Merge branch 'master' into dzikuvx-q-tune
DzikuVx Oct 29, 2021
10b3f62
Add mean FFT value to logging
DzikuVx Oct 29, 2021
99734f9
Log ROLL P gain
DzikuVx Oct 29, 2021
1c2c2e9
Merge remote-tracking branch 'origin/master' into dzikuvx-q-tune
DzikuVx Dec 13, 2021
38a66bd
Merge remote-tracking branch 'origin/master' into dzikuvx-q-tune
DzikuVx Mar 25, 2022
b7c53ef
Merge branch 'master' into dzikuvx-q-tune
DzikuVx Jul 6, 2022
855d8e7
Merge branch 'master' into dzikuvx-q-tune
DzikuVx Mar 30, 2024
69d9f1a
Syntax fix
DzikuVx Mar 31, 2024
dfb9fd6
Fix cmake
DzikuVx Mar 31, 2024
cbe31e4
Merge remote-tracking branch 'origin/master' into dzikuvx-q-tune
Mar 7, 2026
a127871
Fix data buffer length issue
Mar 7, 2026
1d5b6d8
refactor high-frequency oscillation detection
Mar 7, 2026
48fba6f
Low frequency detector
Mar 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ cov-int*
/debug/
/release/
/*_SITL/
.conda/
.venv/

# script-generated files
docs/Manual.pdf
Expand Down
4 changes: 3 additions & 1 deletion cmake/at32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(CMSIS_DSP_SRC
BasicMathFunctions/arm_scale_f32.c
BasicMathFunctions/arm_sub_f32.c
BasicMathFunctions/arm_mult_f32.c
BasicMathFunctions/arm_scale_f32.c
BasicMathFunctions/arm_offset_f32.c
TransformFunctions/arm_rfft_fast_f32.c
TransformFunctions/arm_cfft_f32.c
Expand All @@ -27,9 +28,10 @@ set(CMSIS_DSP_SRC
CommonTables/arm_common_tables.c
ComplexMathFunctions/arm_cmplx_mag_f32.c
StatisticsFunctions/arm_max_f32.c
StatisticsFunctions/arm_var_f32.c
StatisticsFunctions/arm_rms_f32.c
StatisticsFunctions/arm_std_f32.c
StatisticsFunctions/arm_mean_f32.c
StatisticsFunctions/arm_std_f32.c
)
list(TRANSFORM CMSIS_DSP_SRC PREPEND "${CMSIS_DSP_DIR}/Source/")

Expand Down
4 changes: 3 additions & 1 deletion cmake/stm32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(CMSIS_DSP_SRC
BasicMathFunctions/arm_scale_f32.c
BasicMathFunctions/arm_sub_f32.c
BasicMathFunctions/arm_mult_f32.c
BasicMathFunctions/arm_scale_f32.c
BasicMathFunctions/arm_offset_f32.c
TransformFunctions/arm_rfft_fast_f32.c
TransformFunctions/arm_cfft_f32.c
Expand All @@ -28,9 +29,10 @@ set(CMSIS_DSP_SRC
CommonTables/arm_common_tables.c
ComplexMathFunctions/arm_cmplx_mag_f32.c
StatisticsFunctions/arm_max_f32.c
StatisticsFunctions/arm_var_f32.c
StatisticsFunctions/arm_rms_f32.c
StatisticsFunctions/arm_std_f32.c
StatisticsFunctions/arm_mean_f32.c
StatisticsFunctions/arm_std_f32.c
)
list(TRANSFORM CMSIS_DSP_SRC PREPEND "${CMSIS_DSP_DIR}/Source/")

Expand Down
50 changes: 50 additions & 0 deletions dev/scratch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
...
#include "arm_math.h"
#define SAMPLES 128
const int samplingFreq = 1000;
...

static void pdAdcTask(void* parameters) {

DEBUG_PRINT("FFT test function is running!");

//Configure delay
float delay = 500 / portTICK_PERIOD_MS;
DEBUG_PRINT("Delay in ticks is %f \n", delay);
const TickType_t xDelay = delay;

//Some parameters
int peakFrequency;
int f = 150;
int A = 58;

while (true) {
//Force Delay
vTaskDelay(xDelay);

//Create input signal
for(int i=0; i<SAMPLES; i++){
mySine[i] = A*arm_sin_f32(2*PI*f*i/samplingFreq);
}

//Create RFFT instance
arm_rfft_fast_instance_f32 S;
arm_rfft_fast_init_f32(&S, SAMPLES);

//RFFT transform
arm_rfft_fast_f32(&S, mySine,rfft_output,0);
//Calculate magnitude of imaginary coefficients
arm_cmplx_mag_f32(rfft_output,test_output, SAMPLES/2);
//Set DC component to 0
test_output[0] = 0;
//Obtain peak frequency
arm_max_f32(test_output, SAMPLES/2, &maxvalue, &maxindex);

peakFrequency = maxindex * samplingFreq / SAMPLES;

DEBUG_PRINT("Peak frequency %d \n\r", peakFrequency);

DEBUG_PRINT("Max Value:[%ld]:%f Output=[",maxindex,2*maxvalue/SAMPLES);
DEBUG_PRINT("]\r\n");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* \par
* This Function also initializes Twiddle factor table pointer and Bit reversal table pointer.
*/
arm_status arm_rfft_fast_init_f32(
arm_status __attribute__ ( (noinline) ) arm_rfft_fast_init_f32(
arm_rfft_fast_instance_f32 * S,
uint16_t fftLen)
{
Expand Down
2 changes: 2 additions & 0 deletions src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ main_sources(COMMON_SRC
flight/smith_predictor.h
flight/rate_dynamics.c
flight/rate_dynamics.h
flight/q_tune.c
flight/q_tune.h
flight/mixer.c
flight/mixer.h
flight/pid.c
Expand Down
1 change: 1 addition & 0 deletions src/main/build/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ typedef enum {
DEBUG_GPS,
DEBUG_LULU,
DEBUG_SBUS2,
DEBUG_Q_TUNE,
DEBUG_COUNT // also update debugModeNames in cli.c
} debugType_e;

Expand Down
3 changes: 2 additions & 1 deletion src/main/fc/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ static const char *debugModeNames[DEBUG_COUNT] = {
"HEADTRACKER",
"GPS",
"LULU",
"SBUS2"
"SBUS2",
"Q_TUNE"
};

/* Sensor names (used in lookup tables for *_hardware settings and in status
Expand Down
12 changes: 12 additions & 0 deletions src/main/fc/fc_tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "flight/rpm_filter.h"
#include "flight/servos.h"
#include "flight/wind_estimator.h"
#include "flight/q_tune.h"
#include "flight/adaptive_filter.h"

#include "navigation/navigation.h"
Expand Down Expand Up @@ -435,6 +436,9 @@ void fcTasksInit(void)
#if defined(USE_SMARTPORT_MASTER)
setTaskEnabled(TASK_SMARTPORT_MASTER, true);
#endif
#ifdef USE_Q_TUNE
setTaskEnabled(TASK_Q_TUNE, true);
#endif

#ifdef USE_SERIAL_GIMBAL
setTaskEnabled(TASK_GIMBAL, true);
Expand Down Expand Up @@ -708,6 +712,14 @@ cfTask_t cfTasks[TASK_COUNT] = {
.desiredPeriod = TASK_PERIOD_HZ(RPM_FILTER_UPDATE_RATE_HZ), // 300Hz @3,33ms
.staticPriority = TASK_PRIORITY_LOW,
},
#endif
#ifdef USE_Q_TUNE
[TASK_Q_TUNE] = {
.taskName = "QTUNE",
.taskFunc = qTuneProcessTask,
.desiredPeriod = TASK_PERIOD_HZ(Q_TUNE_UPDATE_RATE_HZ), // 20Hz @50ms
.staticPriority = TASK_PRIORITY_LOW,
},
#endif
[TASK_AUX] = {
.taskName = "AUX",
Expand Down
2 changes: 1 addition & 1 deletion src/main/fc/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ tables:
"VIBE", "CRUISE", "REM_FLIGHT_TIME", "SMARTAUDIO", "ACC",
"NAV_YAW", "PCF8574", "DYN_GYRO_LPF", "AUTOLEVEL", "ALTITUDE",
"AUTOTRIM", "AUTOTUNE", "RATE_DYNAMICS", "LANDING", "POS_EST",
"ADAPTIVE_FILTER", "HEADTRACKER", "GPS", "LULU", "SBUS2"]
"ADAPTIVE_FILTER", "HEADTRACKER", "GPS", "LULU", "SBUS2", "Q_TUNE"]
- name: aux_operator
values: ["OR", "AND"]
enum: modeActivationOperator_e
Expand Down
6 changes: 5 additions & 1 deletion src/main/flight/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "flight/rpm_filter.h"
#include "flight/kalman.h"
#include "flight/smith_predictor.h"
#include "flight/q_tune.h"
#include "flight/adaptive_filter.h"

#include "io/gps.h"
Expand Down Expand Up @@ -947,10 +948,13 @@ static void FAST_CODE NOINLINE pidApplyMulticopterRateController(pidState_t *pid
pidState->errorGyroIf = constrainf(pidState->errorGyroIf, -itermLimit, +itermLimit);
}


// Don't grow I-term if motors are at their limit
applyItermLimiting(pidState);

#ifdef USE_Q_TUNE
qTunePushSample(pidState->axis, pidState->rateTarget, pidState->gyroRate, pidState->errorGyroIf);
#endif

axisPID[pidState->axis] = newOutputLimited;

#ifdef USE_BLACKBOX
Expand Down
Loading
Loading