Skip to content

Commit

Permalink
Optimize shift release
Browse files Browse the repository at this point in the history
  • Loading branch information
rnd-ash committed Sep 17, 2024
1 parent e6503c0 commit ad51a21
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/core/firstorder_average.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FirstOrderAverage {
}

float get_average_float() const {
return (float)this->current_sample/100;
return (float)this->current_sample/100.0;
}

void reset(int32_t reset_value = 0) {
Expand Down
6 changes: 4 additions & 2 deletions src/gearbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil
this->sensor_data.last_shift_time = GET_CLOCK_TIME();
this->flaring = false;
shifting_velocity = {0, 0};
// Reset the pedal delta
sensor_data.pedal_delta->reset(0);
delete algo;
}
return result;
Expand Down Expand Up @@ -1006,8 +1008,8 @@ void Gearbox::controller_loop()
p_tmp = 250/4; // 25% as a fallback
}
this->pedal_average->add_sample(p_tmp);
int16_t delta_sec = ((int16_t)p_tmp - (int16_t)(this->pedal_last))*50.0;
sensor_data.pedal_delta->add_sample(delta_sec);
int16_t percent_delta_sec = ((int16_t)p_tmp - (int16_t)(this->pedal_last))*20.0; // 20.0 = 50 (Cycles/sec) / 2.5 (Pedal raw -> %)
sensor_data.pedal_delta->add_sample(percent_delta_sec);
sensor_data.is_braking = egs_can_hal->get_is_brake_pressed(1000);
int tmp_rpm = 0;
tmp_rpm = egs_can_hal->get_engine_rpm(1000);
Expand Down
67 changes: 41 additions & 26 deletions src/shifting_algo/shift_release.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,20 @@ uint8_t ReleasingShift::step(

// Keep calculating these values until we have to start using them
if (phase_id == PHASE_BLEED) {
this->sports_factor = interpolate_float(sd->pedal_pos, 1.0, 2.5, 10, 250, InterpType::Linear);
this->sports_factor *= interpolate_float(sid->targ_time, 0.8, 1.5, 1000, 100, InterpType::Linear);
this->sports_factor = MIN(3.0, MAX(1.0, this->sports_factor));
float max = interpolate_float(sid->targ_time, 2.5, 4.0, 1000, 100, InterpType::Linear);
this->sports_factor = interpolate_float(sd->pedal_delta->get_average(), 1.0, max, 10, 200, InterpType::Linear); //10%/sec - 200%/sec
}

// Threshold RPM for ramping up based on torque
int freeing_torque = pm->find_freeing_torque(sid->change, sd->static_torque_wo_request, sd->output_rpm);
// Calculate torque request trq here. (Only used until we ramp down torque
int clutch_max_trq_req = pm->calc_max_torque_for_clutch(sid->targ_g, sid->applying, sid->SPC_MAX, true);
int trq_request_raw = calc_trq_req(sd->input_rpm, MAX(0, sd->static_torque_wo_request), clutch_max_trq_req);
if (is_upshift) {
this->trq_request_target = this->sports_factor;
this->trq_request_target = trq_request_raw;
} else {
// Downshift uses pedal multiplier
this->trq_request_target = MIN(this->sports_factor * trq_request_raw, abs_input_torque);
}
// Threshold RPM for ramping up based on torque
int freeing_torque = pm->find_freeing_torque(sid->change, sd->static_torque_wo_request, sd->output_rpm);
freeing_torque = MIN(this->sports_factor * freeing_torque, abs_input_torque);
int effective_torque = MIN(freeing_torque,
(freeing_torque + this->torque_at_new_clutch) / 2);
Expand Down Expand Up @@ -113,17 +111,20 @@ uint8_t ReleasingShift::step(
}
this->torque_at_new_clutch = 0;
} else if (1 == this->subphase_shift) { // Ramp to low pressure
#define RAMP_TIME 60
#define RAMP_TIME 40
uint16_t elapsed = phase_elapsed - this->ts_phase_shift;
p_now->on_clutch = interpolate_float(elapsed, sid->prefill_info.fill_pressure_on_clutch, sid->prefill_info.low_fill_pressure_on_clutch, 0, RAMP_TIME, InterpType::Linear);
p_now->overlap_shift = sid->spring_on_clutch + p_now->on_clutch;
p_now->shift_sol_req = p_now->overlap_shift - centrifugal_force_on_clutch;
if (elapsed > RAMP_TIME) {
this->subphase_shift = 2;
this->ts_phase_shift = phase_elapsed;
//sid->prefill_info.low_fill_pressure_on_clutch = MAX(
// sid->prefill_info.low_fill_pressure_on_clutch,
// pm->find_working_pressure_for_clutch(sid->targ_g, sid->applying, abs_input_torque, false)
//);
}
this->torque_at_new_clutch = 0;
this->pre_shift_trq = sd->driver_requested_torque;
} else if (2 == this->subphase_shift) { // Low pressure filling
#define HOLD_3_TIME 40
uint16_t elapsed = phase_elapsed - this->ts_phase_shift;
Expand All @@ -141,9 +142,11 @@ uint8_t ReleasingShift::step(
p_now->overlap_shift = sid->spring_on_clutch + p_now->on_clutch;
p_now->shift_sol_req = p_now->overlap_shift - centrifugal_force_on_clutch;

bool sync_with_mod = (this->subphase_mod > 1);

if ((abs(sid->ptr_r_clutch_speeds->off_clutch_speed) > 100 || sync_with_mod) || elapsed > 5000) {
bool sync_with_mod = phase_elapsed > (this->mod_time_phase_0 + this->mod_time_phase_1);
// Sync with mod reached, but no speed difference
// Or timeout
// Or new clutch speed is near target
if ((sid->ptr_r_clutch_speeds->off_clutch_speed < 100 && sync_with_mod) || elapsed > 5000 || sid->ptr_r_clutch_speeds->on_clutch_speed < 100) {
this->subphase_shift = 4;
this->ts_phase_shift = phase_elapsed;
this->rpm_shift_phase_3 = sid->ptr_r_clutch_speeds->off_clutch_speed;
Expand All @@ -152,11 +155,13 @@ uint8_t ReleasingShift::step(
} else if (4 == this->subphase_shift) { // Ramping new clutch (Clutch is still not moving)
uint16_t elapsed = phase_elapsed - this->ts_phase_shift;
this->filling_adder += 8.0;
if (sid->profile == race) {
this->filling_adder += 8;
}
p_now->on_clutch = sid->prefill_info.low_fill_pressure_on_clutch + filling_adder;
p_now->overlap_shift = sid->spring_on_clutch + p_now->on_clutch;
p_now->shift_sol_req = p_now->overlap_shift - centrifugal_force_on_clutch;
//bool moving = sid->ptr_r_clutch_speeds->off_clutch_speed > 100;
if ((sid->ptr_r_clutch_speeds->on_clutch_speed < this->threshold_rpm) || elapsed > 5000) {
if (sid->ptr_r_clutch_speeds->off_clutch_speed > 100 || (sid->ptr_r_clutch_speeds->on_clutch_speed < this->threshold_rpm) || elapsed > 5000) {
this->subphase_shift = 5;
this->ts_phase_shift = phase_elapsed;
}
Expand Down Expand Up @@ -206,7 +211,7 @@ uint8_t ReleasingShift::step(
((p_now->overlap_mod - centrifugal_force_off_clutch) * sid->inf.pressure_multi_mpc)+
sid->inf.mpc_pressure_spring_reduction
, 0);
if (elapsed > this->mod_time_phase_0 || sid->ptr_r_clutch_speeds->on_clutch_speed < -100) {
if (elapsed > this->mod_time_phase_0 || sid->ptr_r_clutch_speeds->on_clutch_speed < 100) {
this->subphase_mod = 1;
this->ts_phase_mod = phase_elapsed;
}
Expand Down Expand Up @@ -235,8 +240,8 @@ uint8_t ReleasingShift::step(
, 0);
if (
elapsed > this->mod_time_phase_1 ||
(sid->ptr_r_clutch_speeds->on_clutch_speed < this->threshold_rpm &&
sid->ptr_r_clutch_speeds->off_clutch_speed > 100)
(sid->ptr_r_clutch_speeds->on_clutch_speed < this->threshold_rpm &&
sid->ptr_r_clutch_speeds->off_clutch_speed > 100)
|| sid->ptr_r_clutch_speeds->on_clutch_speed < 100
) {
this->subphase_mod = 2;
Expand All @@ -245,19 +250,23 @@ uint8_t ReleasingShift::step(
} else if (2 == this->subphase_mod) {
// Reducing until releasing the clutch
this->filling_trq_reducer += (10.0 * this->sports_factor) + (this->sports_factor * 0.05 * this->filling_trq_reducer);
int trq = MAX(0, abs_input_torque - freeing_torque - filling_trq_reducer);

int wp_old_clutch = pm->find_working_pressure_for_clutch(sid->curr_g, sid->releasing, trq, false);

int trq = abs_input_torque - freeing_torque - filling_trq_reducer;
int spring_reducer = 0;
int wp_old_clutch = 0;
if (trq >= 0) {
wp_old_clutch = pm->find_working_pressure_for_clutch(sid->curr_g, sid->releasing, trq, false);
} else { // Negative loss
spring_reducer = pm->find_working_pressure_for_clutch(sid->curr_g, sid->releasing, abs(trq), false);
}
p_now->off_clutch = wp_old_clutch;
p_now->overlap_mod = sid->spring_off_clutch + p_now->off_clutch;
p_now->overlap_mod = sid->spring_off_clutch + p_now->off_clutch - spring_reducer;
p_now->mod_sol_req = MAX(
((p_now->overlap_shift - centrifugal_force_on_clutch) * sid->inf.pressure_multi_spc)+
((p_now->overlap_mod - centrifugal_force_off_clutch) * sid->inf.pressure_multi_mpc)+
sid->inf.mpc_pressure_spring_reduction
, 0);
if (
trq <= 0 || // No more torque to reduce by
trq < -50.0 || // No more torque to reduce by
(sid->ptr_r_clutch_speeds->off_clutch_speed > 100) || // Released old clutch
(sid->ptr_r_clutch_speeds->on_clutch_speed < 100) // Early sync.
) {
Expand All @@ -267,10 +276,16 @@ uint8_t ReleasingShift::step(

} else if (3 == this->subphase_mod) {
// Hold pressure until we can sync.
int trq = MAX(0, abs_input_torque - freeing_torque - filling_trq_reducer);
int wp_old_clutch = pm->find_working_pressure_for_clutch(sid->curr_g, sid->releasing, trq, false);
int trq = abs_input_torque - freeing_torque - filling_trq_reducer;
int spring_reducer = 0;
int wp_old_clutch = 0;
if (trq >= 0) {
wp_old_clutch = pm->find_working_pressure_for_clutch(sid->curr_g, sid->releasing, trq, false);
} else { // Negative loss
spring_reducer = pm->find_working_pressure_for_clutch(sid->curr_g, sid->releasing, abs(trq), false);
}
p_now->off_clutch = wp_old_clutch;
p_now->overlap_mod = sid->spring_off_clutch + p_now->off_clutch;
p_now->overlap_mod = sid->spring_off_clutch + p_now->off_clutch - spring_reducer;
p_now->mod_sol_req = MAX(
((p_now->overlap_shift - centrifugal_force_on_clutch) * sid->inf.pressure_multi_spc)+
((p_now->overlap_mod - centrifugal_force_off_clutch) * sid->inf.pressure_multi_mpc * sid->inf.centrifugal_factor_off_clutch)+
Expand Down
3 changes: 1 addition & 2 deletions src/shifting_algo/shift_release.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class ReleasingShift : public ShiftingAlgorithm {
) override;
FirstOrderAverage* trq_req_avg;
uint8_t max_shift_stage_id() override;
uint16_t torque_adder = 0;
int16_t pre_shift_trq = 0;
uint16_t threshold_rpm = 0;
float filling_adder = 0;
float filling_trq_reducer = 0;
Expand All @@ -44,6 +42,7 @@ class ReleasingShift : public ShiftingAlgorithm {

float sports_factor=1.0;
float trq_request_target = 0;
float trq_request_target_adder = 0;
float trq_request_absolute_target=0;

uint16_t rpm_shift_phase_3 = 0;
Expand Down

0 comments on commit ad51a21

Please sign in to comment.