Skip to content

Commit 5f44c3e

Browse files
remove biquad replace with ptn filter (#13)
* code cleanup of unused * allow users to select the level for their ptn filter * Update board_comm.c * Update board_comm.c * 🦋 * QuickFlash's PT(n) * fixed default init ptn_order * Andrey flight tested & BBL proved working; nerdCopter hover tested proved non-borked * v256, a number of serendipity * Butterfly for ode to Helio Co-authored-by: nerdCopter <[email protected]>
1 parent 7447d82 commit 5f44c3e

File tree

5 files changed

+24
-31
lines changed

5 files changed

+24
-31
lines changed

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"fft.h": "c",
4444
"biquad.h": "c",
4545
"scheduler.h": "c",
46-
"kalman.h": "c"
46+
"kalman.h": "c",
47+
"ptnFilter.h": "c"
4748
}
48-
}
49+
}

src/board_comm/board_comm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ static void run_command(volatile imufCommand_t* command, volatile imufCommand_t*
154154
gyroSettingsConfig.smallX = (int32_t) ((int16_t)(command->param8 >> 16));
155155
gyroSettingsConfig.smallY = (int32_t) ((int16_t)(command->param9 & 0xFFFF));
156156
gyroSettingsConfig.smallZ = (int32_t) ((int16_t)(command->param9 >> 16));
157-
filterConfig.sharpness = (int16_t) ((int16_t)(command->param10 >> 16));
158-
if (!filterConfig.sharpness)
157+
filterConfig.ptnFilterType = (int16_t)(command->param10 >> 16);
158+
if (!filterConfig.ptnFilterType || filterConfig.ptnFilterType > 4)
159159
{
160-
filterConfig.sharpness = 2500;
160+
filterConfig.ptnFilterType = 3;
161161
}
162162
filterConfig.acc_lpf_hz = (int16_t)(command->param10 & 0xFFFF);
163163
if (!filterConfig.acc_lpf_hz)

src/filter/filter.c

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,21 @@
66

77
volatile filter_config_t filterConfig =
88
{
9-
DEFAULT_ROLL_Q,
10-
DEFAULT_PITCH_Q,
11-
DEFAULT_YAW_Q,
12-
MIN_WINDOW_SIZE,
13-
14-
(float)DEFAULT_ROLL_Q,
15-
(float)DEFAULT_PITCH_Q,
16-
(float)DEFAULT_YAW_Q,
17-
18-
(float)BASE_LPF_HZ,
19-
(float)BASE_LPF_HZ,
20-
(float)BASE_LPF_HZ,
21-
22-
40.0f,
23-
24-
BASE_LPF_HZ,
25-
BASE_LPF_HZ,
26-
BASE_LPF_HZ,
27-
100,
9+
DEFAULT_ROLL_Q, //init defaults for: uint16_t i_roll_q;
10+
DEFAULT_PITCH_Q, //init defaults for: uint16_t i_pitch_q;
11+
DEFAULT_YAW_Q, //init defaults for: uint16_t i_yaw_q;
12+
MIN_WINDOW_SIZE, //init defaults for: uint16_t w;
13+
(float)DEFAULT_ROLL_Q, //init defaults for: float roll_q;
14+
(float)DEFAULT_PITCH_Q, //init defaults for: float pitch_q;
15+
(float)DEFAULT_YAW_Q, //init defaults for: float yaw_q;
16+
(float)BASE_LPF_HZ, //init defaults for: float pitch_lpf_hz;
17+
(float)BASE_LPF_HZ, //init defaults for: float roll_lpf_hz;
18+
(float)BASE_LPF_HZ, //init defaults for: float yaw_lpf_hz;
19+
40.0f, //init defaults for: uint16_t acc_lpf_hz;
20+
BASE_LPF_HZ, //init defaults for: uint16_t i_roll_lpf_hz;
21+
BASE_LPF_HZ, //init defaults for: uint16_t i_pitch_lpf_hz;
22+
BASE_LPF_HZ, //init defaults for: uint16_t i_yaw_lpf_hz;
23+
3, //init defaults for: uint16_t ptnFilterType;
2824
};
2925

3026
// PT1 Low Pass filter
@@ -49,16 +45,14 @@ volatile axisData_t oldSetPoint;
4945
volatile axisData_t setPoint;
5046
volatile int allowFilterInit = 1;
5147

52-
float sharpness;
53-
5448
void allow_filter_init(void)
5549
{
5650
allowFilterInit = 1;
5751
}
5852

5953
void ptnFilter_init(float freq, ptnFilter_axis_t *filterState)
6054
{
61-
ptnFilterInit(freq, filterState, 2);
55+
ptnFilterInit(freq, filterState, filterConfig.ptnFilterType);
6256
}
6357

6458
void filter_init(void)
@@ -79,8 +73,6 @@ void filter_init(void)
7973
pt1FilterInit(&ax_filter, k, 0.0f);
8074
pt1FilterInit(&ay_filter, k, 0.0f);
8175
pt1FilterInit(&az_filter, k, 0.0f);
82-
83-
sharpness = (float)filterConfig.sharpness / 250.0f;
8476
}
8577

8678
void filter_data(volatile axisData_t *gyroRateData, volatile axisData_t *gyroAccData, float gyroTempData, filteredData_t *filteredData)

src/filter/filter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ typedef struct filter_config
3030
uint16_t i_roll_lpf_hz;
3131
uint16_t i_pitch_lpf_hz;
3232
uint16_t i_yaw_lpf_hz;
33-
uint16_t sharpness;
33+
uint16_t ptnFilterType;
3434
} filter_config_t;
3535

3636
extern volatile filter_config_t filterConfig;

src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#define HARDWARE_VERSION 101
44
#define BOOTLOADER_VERSION 101
55

6-
#define FIRMWARE_VERSION 254
6+
#define FIRMWARE_VERSION 256

0 commit comments

Comments
 (0)