@@ -161,6 +161,7 @@ typedef struct {
161
161
float mc_max_temp_fet , mc_max_temp_mot ;
162
162
float mc_current_max , mc_current_min , current_max , current_min , max_continuous_current ;
163
163
float surge_angle , surge_angle2 , surge_angle3 , surge_adder ;
164
+ float ki ; // config ki scaled taking account the loop frequency.
164
165
bool overcurrent ;
165
166
bool surge_enable ;
166
167
bool current_beeping ;
@@ -393,6 +394,11 @@ static void app_init(data *d) {
393
394
d -> odometer = VESC_IF -> mc_get_odometer ();
394
395
}
395
396
397
+ static float normalized_to_iteration_ki (float normalized_ki , int loop_freq_hz ) {
398
+ // Default frequency of Float thread used to be 832 Hz so we retain that scale.
399
+ return normalized_ki * (832.0 / loop_freq_hz );
400
+ }
401
+
396
402
static void configure (data * d ) {
397
403
d -> debug_render_1 = 2 ;
398
404
d -> debug_render_2 = 4 ;
@@ -418,6 +424,7 @@ static void configure(data *d) {
418
424
d -> turntilt_step_size = d -> float_conf .turntilt_speed / d -> float_conf .hertz ;
419
425
d -> noseangling_step_size = d -> float_conf .noseangling_speed / d -> float_conf .hertz ;
420
426
d -> inputtilt_step_size = d -> float_conf .inputtilt_speed / d -> float_conf .hertz ;
427
+ d -> ki = normalized_to_iteration_ki (d -> float_conf .ki , d -> float_conf .hertz );
421
428
422
429
d -> surge_angle = d -> float_conf .surge_angle ;
423
430
d -> surge_angle2 = d -> float_conf .surge_angle * 2 ;
@@ -2011,7 +2018,7 @@ static void float_thd(void *arg) {
2011
2018
bool tail_down = SIGN (d -> proportional ) != SIGN (d -> erpm );
2012
2019
2013
2020
// Resume real PID maths
2014
- d -> pid_integral = d -> pid_integral + d -> proportional * d -> float_conf . ki ;
2021
+ d -> pid_integral = d -> pid_integral + d -> proportional * d -> ki ;
2015
2022
2016
2023
// Apply I term Filter
2017
2024
if (d -> float_conf .ki_limit > 0 && fabsf (d -> pid_integral ) > d -> float_conf .ki_limit ) {
@@ -2729,6 +2736,7 @@ static void cmd_runtime_tune(data *d, unsigned char *cfg, int len)
2729
2736
d -> float_conf .ki = 0.005 ;
2730
2737
else if (h1 > 1 )
2731
2738
d -> float_conf .ki = ((float )(h1 - 1 )) / 100 ;
2739
+ d -> ki = normalized_to_iteration_ki (d -> float_conf .ki , d -> float_conf .hertz );
2732
2740
d -> float_conf .ki_limit = h2 + 19 ;
2733
2741
if (h2 == 0 )
2734
2742
d -> float_conf .ki_limit = 0 ;
0 commit comments