Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative variable tiltback via negative rate #33

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/conf/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ p, li { white-space: pre-wrap; }
<editorScale>1</editorScale>
<editAsPercentage>0</editAsPercentage>
<maxDouble>5</maxDouble>
<minDouble>0</minDouble>
<minDouble>-5</minDouble>
<showDisplay>0</showDisplay>
<stepDouble>0.05</stepDouble>
<valDouble>0.1</valDouble>
Expand All @@ -831,7 +831,7 @@ p, li { white-space: pre-wrap; }
<editorScale>1</editorScale>
<editAsPercentage>0</editAsPercentage>
<maxDouble>20</maxDouble>
<minDouble>-20</minDouble>
<minDouble>0</minDouble>
<showDisplay>0</showDisplay>
<stepDouble>0.5</stepDouble>
<valDouble>0</valDouble>
Expand Down
69 changes: 15 additions & 54 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ 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;
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);
torque_tilt_configure(&d->torque_tilt, &d->float_conf);
Expand All @@ -281,21 +289,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
Expand Down Expand Up @@ -339,15 +342,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));
Expand Down Expand Up @@ -854,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;
Expand Down Expand Up @@ -1958,8 +1946,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);
Expand Down Expand Up @@ -2049,20 +2035,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);
}

Expand Down Expand Up @@ -2101,7 +2073,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
Expand All @@ -2111,7 +2082,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;
Expand All @@ -2129,21 +2099,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;
}

Expand All @@ -2158,6 +2117,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) {
Expand Down
Loading