Skip to content

Commit eb771ef

Browse files
committed
225
adding sharpness parameter, needs emu 0.2.32 or higher to work :)
1 parent 22ca51f commit eb771ef

File tree

6 files changed

+20
-22
lines changed

6 files changed

+20
-22
lines changed

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.r_weight = (int16_t) ((int16_t)(command->param10 >> 16));
158-
if (!filterConfig.r_weight)
157+
filterConfig.sharpness = (int16_t) ((int16_t)(command->param10 >> 16));
158+
if (!filterConfig.sharpness)
159159
{
160-
filterConfig.r_weight = 100;
160+
filterConfig.sharpness = 35;
161161
}
162162
filterConfig.acc_lpf_hz = (int16_t)(command->param10 & 0xFFFF);
163163
if (!filterConfig.acc_lpf_hz)

src/filter/filter.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ volatile axisData_t oldSetPoint;
7373
volatile axisData_t setPoint;
7474
volatile int allowFilterInit = 1;
7575

76-
extern float r_filter_weight;
76+
float sharpness;
7777

7878
void allow_filter_init(void)
7979
{
@@ -104,7 +104,7 @@ void filter_init(void)
104104
pt1FilterInit(&ay_filter, k, 0.0f);
105105
pt1FilterInit(&az_filter, k, 0.0f);
106106

107-
r_filter_weight = (float)filterConfig.r_weight / 100.0f;
107+
sharpness = (float)filterConfig.sharpness / 250.0f;
108108
}
109109

110110
void filter_data(volatile axisData_t *gyroRateData, volatile axisData_t *gyroAccData, float gyroTempData, filteredData_t *filteredData)
@@ -131,23 +131,23 @@ void filter_data(volatile axisData_t *gyroRateData, volatile axisData_t *gyroAcc
131131
filteredData->rateData.z = biquad_update(filteredData->rateData.z, &(lpfFilterStateRate.z));
132132

133133
// calculate the error
134-
float errorMultiplierX = ABS(setPoint.x - filteredData->rateData.x / 6.0f);
135-
float errorMultiplierY = ABS(setPoint.y - filteredData->rateData.y / 6.0f);
136-
float errorMultiplierZ = ABS(setPoint.z - filteredData->rateData.z / 6.0f);
134+
float errorMultiplierX = ABS(setPoint.x - filteredData->rateData.x) * sharpness;
135+
float errorMultiplierY = ABS(setPoint.y - filteredData->rateData.y) * sharpness;
136+
float errorMultiplierZ = ABS(setPoint.z - filteredData->rateData.z) * sharpness;
137137

138-
float setPointChangeBoostX = CONSTRAIN((ABS(setPoint.x - setPoint.x) / 10.0f) + 1.0f, 1.0f, 10.0f);
139-
float setPointChangeBoostY = CONSTRAIN((ABS(setPoint.y - setPoint.y) / 10.0f) + 1.0f, 1.0f, 10.0f);
140-
float setPointChangeBoostZ = CONSTRAIN((ABS(setPoint.z - setPoint.z) / 10.0f) + 1.0f, 1.0f, 10.0f);
138+
// float setPointChangeBoostX = CONSTRAIN((ABS(setPoint.x - setPoint.x) / 10.0f) + 1.0f, 1.0f, 10.0f);
139+
// float setPointChangeBoostY = CONSTRAIN((ABS(setPoint.y - setPoint.y) / 10.0f) + 1.0f, 1.0f, 10.0f);
140+
// float setPointChangeBoostZ = CONSTRAIN((ABS(setPoint.z - setPoint.z) / 10.0f) + 1.0f, 1.0f, 10.0f);
141141

142142
// errorMultiplierX = errorMultiplierX * CONSTRAIN(ABS(setPoint.x / 100.0f), 0.1f, 1.0f);
143143
// errorMultiplierY = errorMultiplierY * CONSTRAIN(ABS(setPoint.y / 100.0f), 0.1f, 1.0f);
144144
// errorMultiplierZ = errorMultiplierZ * CONSTRAIN(ABS(setPoint.z / 100.0f), 0.1f, 1.0f);
145145

146146
// give a boost to the setpoint, used to caluclate the filter cutoff, based on the error and setpoint/gyrodata
147147

148-
errorMultiplierX = CONSTRAIN(errorMultiplierX * setPointChangeBoostX * ABS(1.0f - (setPoint.x / filteredData->rateData.x)) + 1.0f, 1.0f, 10.0f);
149-
errorMultiplierY = CONSTRAIN(errorMultiplierY * setPointChangeBoostX * ABS(1.0f - (setPoint.y / filteredData->rateData.y)) + 1.0f, 1.0f, 10.0f);
150-
errorMultiplierZ = CONSTRAIN(errorMultiplierZ * setPointChangeBoostX * ABS(1.0f - (setPoint.z / filteredData->rateData.z)) + 1.0f, 1.0f, 10.0f);
148+
errorMultiplierX = CONSTRAIN(errorMultiplierX * ABS(1.0f - (setPoint.x / filteredData->rateData.x)) + 1.0f, 1.0f, 10.0f);
149+
errorMultiplierY = CONSTRAIN(errorMultiplierY * ABS(1.0f - (setPoint.y / filteredData->rateData.y)) + 1.0f, 1.0f, 10.0f);
150+
errorMultiplierZ = CONSTRAIN(errorMultiplierZ * ABS(1.0f - (setPoint.z / filteredData->rateData.z)) + 1.0f, 1.0f, 10.0f);
151151

152152

153153
if (setPointNew)

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 r_weight;
33+
uint16_t sharpness;
3434
} filter_config_t;
3535

3636
extern volatile filter_config_t filterConfig;

src/filter/kalman.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
variance_t varStruct;
77
kalman_t kalmanFilterStateRate[3];
8-
float r_filter_weight = 1.0f;
9-
108

119
void init_kalman(kalman_t *filter, float q)
1210
{
@@ -72,11 +70,11 @@ void update_kalman_covariance(volatile axisData_t *gyroRateData)
7270

7371
float squirt;
7472
arm_sqrt_f32(varStruct.xVar + varStruct.xyCoVar + varStruct.xzCoVar, &squirt);
75-
kalmanFilterStateRate[ROLL].r = squirt * r_filter_weight;
73+
kalmanFilterStateRate[ROLL].r = squirt * VARIANCE_SCALE;
7674
arm_sqrt_f32(varStruct.yVar + varStruct.xyCoVar + varStruct.yzCoVar, &squirt);
77-
kalmanFilterStateRate[PITCH].r = squirt * r_filter_weight;
75+
kalmanFilterStateRate[PITCH].r = squirt * VARIANCE_SCALE;
7876
arm_sqrt_f32(varStruct.zVar + varStruct.yzCoVar + varStruct.xzCoVar, &squirt);
79-
kalmanFilterStateRate[YAW].r = squirt * r_filter_weight;
77+
kalmanFilterStateRate[YAW].r = squirt * VARIANCE_SCALE;
8078
}
8179

8280
inline float kalman_process(kalman_t* kalmanState, volatile float input, volatile float target) {

src/filter/kalman.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define MIN_WINDOW_SIZE 6
99

1010
// #define VARIANCE_SCALE 0.001
11-
#define VARIANCE_SCALE 0.3333333f
11+
#define VARIANCE_SCALE 0.67f
1212

1313
typedef struct kalman
1414
{

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 224
6+
#define FIRMWARE_VERSION 225

0 commit comments

Comments
 (0)