From 4021580d828c748fc43c4ac67307a896b3b5fa8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= Date: Wed, 25 Dec 2024 19:03:30 +0100 Subject: [PATCH 1/2] Move some stuff from other functions to reconfigure() And call reconfigure() from cmd_runtime_tune_other() to apply the calculated settings. --- src/main.c | 58 ++++++++++++++---------------------------------------- 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/src/main.c b/src/main.c index 68720d1..11c0c26 100644 --- a/src/main.c +++ b/src/main.c @@ -261,6 +261,19 @@ void beep_on(data *d, bool force) { } static void reconfigure(data *d) { + d->turntilt_step_size = d->float_conf.turntilt_speed / d->float_conf.hertz; + d->startup_step_size = d->float_conf.startup_speed / d->float_conf.hertz; + d->noseangling_step_size = d->float_conf.noseangling_speed / d->float_conf.hertz; + d->startup_pitch_trickmargin = d->float_conf.startup_dirtylandings_enabled ? 10 : 0; + + d->tiltback_variable = d->float_conf.tiltback_variable / 1000; + if (d->tiltback_variable > 0) { + d->tiltback_variable_max_erpm = + fabsf(d->float_conf.tiltback_variable_max / d->tiltback_variable); + } else { + d->tiltback_variable_max_erpm = 100000; + } + motor_data_configure(&d->motor, d->float_conf.atr_filter / d->float_conf.hertz); balance_filter_configure(&d->balance_filter, &d->float_conf); torque_tilt_configure(&d->torque_tilt, &d->float_conf); @@ -281,21 +294,16 @@ static void configure(data *d) { // Loop time in seconds times 20 for a nice long grace period d->motor_timeout_s = 20.0f / d->float_conf.hertz; - d->startup_step_size = d->float_conf.startup_speed / d->float_conf.hertz; d->tiltback_duty_step_size = d->float_conf.tiltback_duty_speed / d->float_conf.hertz; d->tiltback_hv_step_size = d->float_conf.tiltback_hv_speed / d->float_conf.hertz; d->tiltback_lv_step_size = d->float_conf.tiltback_lv_speed / d->float_conf.hertz; d->tiltback_return_step_size = d->float_conf.tiltback_return_speed / d->float_conf.hertz; - d->turntilt_step_size = d->float_conf.turntilt_speed / d->float_conf.hertz; - d->noseangling_step_size = d->float_conf.noseangling_speed / d->float_conf.hertz; d->inputtilt_step_size = d->float_conf.inputtilt_speed / d->float_conf.hertz; // Feature: Stealthy start vs normal start (noticeable click when engaging) - 0-20A d->start_counter_clicks_max = 3; // Feature: Soft Start d->softstart_ramp_step_size = (float) 100 / d->float_conf.hertz; - // Feature: Dirty Landings - d->startup_pitch_trickmargin = d->float_conf.startup_dirtylandings_enabled ? 10 : 0; // Backwards compatibility hack: // If mahony kp from the firmware internal filter is higher than 1, it's @@ -339,15 +347,6 @@ static void configure(data *d) { // Speed above which to warn users about an impending full switch fault d->switch_warn_beep_erpm = d->float_conf.is_footbeep_enabled ? 2000 : 100000; - // Variable nose angle adjustment / tiltback (setting is per 1000erpm, convert to per erpm) - d->tiltback_variable = d->float_conf.tiltback_variable / 1000; - if (d->tiltback_variable > 0) { - d->tiltback_variable_max_erpm = - fabsf(d->float_conf.tiltback_variable_max / d->tiltback_variable); - } else { - d->tiltback_variable_max_erpm = 100000; - } - d->beeper_enabled = d->float_conf.is_beeper_enabled; konami_init(&d->flywheel_konami, flywheel_konami_sequence, sizeof(flywheel_konami_sequence)); @@ -1958,8 +1957,6 @@ static void cmd_runtime_tune(data *d, unsigned char *cfg, int len) { if (h2 == 0) { d->mc_current_min = fabsf(VESC_IF->get_cfg_float(CFG_PARAM_l_current_min)); } - - d->turntilt_step_size = d->float_conf.turntilt_speed / d->float_conf.hertz; } if (len >= 16) { split(cfg[12], &h1, &h2); @@ -2049,20 +2046,6 @@ static void cmd_tune_defaults(data *d) { d->float_conf.startup_simplestart_enabled = CFG_DFLT_SIMPLESTART_ENABLED; d->float_conf.startup_dirtylandings_enabled = CFG_DFLT_DIRTYLANDINGS_ENABLED; - // Update values normally done in configure() - d->turntilt_step_size = d->float_conf.turntilt_speed / d->float_conf.hertz; - - d->startup_step_size = d->float_conf.startup_speed / d->float_conf.hertz; - d->noseangling_step_size = d->float_conf.noseangling_speed / d->float_conf.hertz; - d->startup_pitch_trickmargin = d->float_conf.startup_dirtylandings_enabled ? 10 : 0; - d->tiltback_variable = d->float_conf.tiltback_variable / 1000; - if (d->tiltback_variable > 0) { - d->tiltback_variable_max_erpm = - fabsf(d->float_conf.tiltback_variable_max / d->tiltback_variable); - } else { - d->tiltback_variable_max_erpm = 100000; - } - reconfigure(d); } @@ -2101,7 +2084,6 @@ static void cmd_runtime_tune_other(data *d, unsigned char *cfg, int len) { d->float_conf.startup_pushstart_enabled = ((flags & 0x80) == 0x80); d->float_conf.is_beeper_enabled = d->beeper_enabled; - d->startup_pitch_trickmargin = dirty_landings ? 10 : 0; d->float_conf.startup_dirtylandings_enabled = dirty_landings; // startup @@ -2111,7 +2093,6 @@ static void cmd_runtime_tune_other(data *d, unsigned char *cfg, int len) { float brakecurrent = cfg[4]; float clickcurrent = cfg[5]; - d->startup_step_size = ctrspeed / d->float_conf.hertz; d->float_conf.startup_speed = ctrspeed; d->float_conf.startup_pitch_tolerance = pitchtolerance / 10; d->float_conf.startup_roll_tolerance = rolltolerance; @@ -2129,21 +2110,10 @@ static void cmd_runtime_tune_other(data *d, unsigned char *cfg, int len) { d->float_conf.tiltback_constant = tiltconst / 2; d->float_conf.tiltback_constant_erpm = tilterpm; if (tiltspeed > 0) { - d->noseangling_step_size = tiltspeed / 10 / d->float_conf.hertz; d->float_conf.noseangling_speed = tiltspeed / 10; } d->float_conf.tiltback_variable = tiltvarrate / 100; d->float_conf.tiltback_variable_max = tiltvarmax / 10; - - d->startup_step_size = d->float_conf.startup_speed / d->float_conf.hertz; - d->noseangling_step_size = d->float_conf.noseangling_speed / d->float_conf.hertz; - d->tiltback_variable = d->float_conf.tiltback_variable / 1000; - if (d->tiltback_variable > 0) { - d->tiltback_variable_max_erpm = - fabsf(d->float_conf.tiltback_variable_max / d->tiltback_variable); - } else { - d->tiltback_variable_max_erpm = 100000; - } d->float_conf.tiltback_variable_erpm = cfg[11] * 100; } @@ -2158,6 +2128,8 @@ static void cmd_runtime_tune_other(data *d, unsigned char *cfg, int len) { } } } + + reconfigure(d); } void cmd_rc_move(data *d, unsigned char *cfg) { From 9dbee3e78bb65db95d69527ddbe113c0a348b2c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= Date: Wed, 25 Dec 2024 20:04:36 +0100 Subject: [PATCH 2/2] Negative Variable Tiltback configured by negative rate Fix: Configure negative Variable Tiltback via negative rate, not maximum > This will cause negative Variable Tiltback configured through the maximum to disappear. In such case users need to configure it again. --- src/conf/settings.xml | 4 ++-- src/main.c | 25 +++++++------------------ 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/conf/settings.xml b/src/conf/settings.xml index dabeff7..330dd13 100644 --- a/src/conf/settings.xml +++ b/src/conf/settings.xml @@ -809,7 +809,7 @@ p, li { white-space: pre-wrap; } 1 0 5 - 0 + -5 0 0.05 0.1 @@ -831,7 +831,7 @@ p, li { white-space: pre-wrap; } 1 0 20 - -20 + 0 0 0.5 0 diff --git a/src/main.c b/src/main.c index 11c0c26..a24c996 100644 --- a/src/main.c +++ b/src/main.c @@ -265,14 +265,9 @@ static void reconfigure(data *d) { d->startup_step_size = d->float_conf.startup_speed / d->float_conf.hertz; d->noseangling_step_size = d->float_conf.noseangling_speed / d->float_conf.hertz; d->startup_pitch_trickmargin = d->float_conf.startup_dirtylandings_enabled ? 10 : 0; - d->tiltback_variable = d->float_conf.tiltback_variable / 1000; - if (d->tiltback_variable > 0) { - d->tiltback_variable_max_erpm = - fabsf(d->float_conf.tiltback_variable_max / d->tiltback_variable); - } else { - d->tiltback_variable_max_erpm = 100000; - } + d->tiltback_variable_max_erpm = + fabsf(d->float_conf.tiltback_variable_max / d->tiltback_variable); motor_data_configure(&d->motor, d->float_conf.atr_filter / d->float_conf.hertz); balance_filter_configure(&d->balance_filter, &d->float_conf); @@ -853,17 +848,11 @@ static void calculate_setpoint_target(data *d) { } static void apply_noseangling(data *d) { - // Nose angle adjustment, add variable then constant tiltback - float noseangling_target = 0; - - // Variable Tiltback looks at ERPM from the reference point of the set minimum ERPM - float variable_erpm = fmaxf(0, d->motor.abs_erpm - d->float_conf.tiltback_variable_erpm); - if (variable_erpm > d->tiltback_variable_max_erpm) { - noseangling_target = d->float_conf.tiltback_variable_max * d->motor.erpm_sign; - } else { - noseangling_target = d->tiltback_variable * variable_erpm * d->motor.erpm_sign * - sign(d->float_conf.tiltback_variable_max); - } + // Variable Tiltback: looks at ERPM from the reference point of the set minimum ERPM + float variable_erpm = clampf( + d->motor.abs_erpm - d->float_conf.tiltback_variable_erpm, 0, d->tiltback_variable_max_erpm + ); + float noseangling_target = d->tiltback_variable * variable_erpm * d->motor.erpm_sign; if (d->motor.abs_erpm > d->float_conf.tiltback_constant_erpm) { noseangling_target += d->float_conf.tiltback_constant * d->motor.erpm_sign;