Skip to content

Commit

Permalink
Gearbox. Calculate delta for shift clutch speeds better
Browse files Browse the repository at this point in the history
  • Loading branch information
rnd-ash committed Jul 18, 2024
1 parent c723665 commit 1d8162a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
58 changes: 34 additions & 24 deletions src/gearbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,40 +389,53 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil
}

this->shifting_velocity = {0, 0};

// Back calculate for pre-shifting clutch speeds (Used as a delta)
RpmReading pre_shift_rpm = this->rpm_reading;


ShiftClutchData pre_cs = ClutchSpeedModel::get_shifting_clutch_speeds(sensor_data.output_rpm, this->rpm_reading, req_lookup, this->gearboxConfig.bounds);
ShiftClutchData old_cs = pre_cs;
ShiftClutchData now_cs = pre_cs;

int spring_pressure_on_clutch = this->pressure_mgr->get_spring_pressure(get_clutch_to_apply(req_lookup));
int spring_pressure_off_clutch = this->pressure_mgr->get_spring_pressure(get_clutch_to_release(req_lookup));
PressureStageTiming maxp = pressure_manager->get_max_pressure_timing();
Clutch applying = get_clutch_to_apply(req_lookup);
Clutch releasing = get_clutch_to_release(req_lookup);
bool enable_torque_request = true;
bool preshift_n3_set_zero = false;
float preshift_ratio = 1.0;
switch (req_lookup) {
case ProfileGearChange::ONE_TWO:
enable_torque_request = SBS_CURRENT_SETTINGS.trq_req_1_2_enable;
preshift_ratio = this->gearboxConfig.bounds[0].ratio;
preshift_n3_set_zero = true;
break;
case ProfileGearChange::TWO_THREE:
enable_torque_request = SBS_CURRENT_SETTINGS.trq_req_2_3_enable;
preshift_ratio = this->gearboxConfig.bounds[1].ratio;
break;
case ProfileGearChange::THREE_FOUR:
enable_torque_request = SBS_CURRENT_SETTINGS.trq_req_3_4_enable;
preshift_ratio = this->gearboxConfig.bounds[2].ratio;
break;
case ProfileGearChange::FOUR_FIVE:
enable_torque_request = SBS_CURRENT_SETTINGS.trq_req_4_5_enable;
preshift_ratio = this->gearboxConfig.bounds[3].ratio;
break;
case ProfileGearChange::FIVE_FOUR:
enable_torque_request = SBS_CURRENT_SETTINGS.trq_req_5_4_enable;
preshift_ratio = this->gearboxConfig.bounds[4].ratio;
preshift_n3_set_zero = true;
break;
case ProfileGearChange::FOUR_THREE:
enable_torque_request = SBS_CURRENT_SETTINGS.trq_req_4_3_enable;
preshift_ratio = this->gearboxConfig.bounds[3].ratio;
break;
case ProfileGearChange::THREE_TWO:
enable_torque_request = SBS_CURRENT_SETTINGS.trq_req_3_2_enable;
preshift_ratio = this->gearboxConfig.bounds[2].ratio;
break;
case ProfileGearChange::TWO_ONE:
enable_torque_request = SBS_CURRENT_SETTINGS.trq_req_2_1_enable;
preshift_ratio = this->gearboxConfig.bounds[1].ratio;
break;
default:
break;
Expand All @@ -434,10 +447,8 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil
int MOD_MAX = this->pressure_mgr->get_max_solenoid_pressure();
int SPC_MAX = SPC_GAIN*(MOD_MAX - this->pressure_mgr->get_shift_regulator_pressure());

FirstOrderAverage on_velocity_avg = FirstOrderAverage<int>(100/SHIFT_DELAY_MS);
FirstOrderAverage off_velocity_avg = FirstOrderAverage<int>(100/SHIFT_DELAY_MS);
bool freeze_torque = false;
int t_delta = 0;
FirstOrderAverage on_velocity_avg = FirstOrderAverage<int>(0);
FirstOrderAverage off_velocity_avg = FirstOrderAverage<int>(0);

TorqueRequstData trd = {
.ty = TorqueRequestControlType::None,
Expand All @@ -459,6 +470,7 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil
.prefill_info = prefill_data,
.chars = chars,
.ptr_r_clutch_speeds = &now_cs,
.ptr_r_pre_clutch_speeds = &pre_cs,
.ptr_prev_pressures = &p_prev,
.ptr_w_pressures = &p_now,
.ptr_w_trq_req = &trd,
Expand All @@ -468,20 +480,12 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil

ShiftingAlgorithm* algo;
// Check if we exceed the pressure of low filling
if (sensor_data.static_torque > VEHICLE_CONFIG.engine_drag_torque/10.0 * 5.0) {
if (sensor_data.static_torque > VEHICLE_CONFIG.engine_drag_torque/10.0 && sensor_data.input_rpm > 1500) {
algo = new ReleasingShift(&sid);
} else {
algo = new CrossoverShift(&sid);
}

//if (requires_high_pressure && sensor_data.static_torque > VEHICLE_CONFIG.engine_drag_torque/5.0) {
// algo = new ReleasingShift(&sid);
//} else {
// algo = new CrossoverShift(&sid);
//}



uint8_t algo_phase_id = 0;
uint8_t algo_max_phase = algo->max_shift_stage_id();
const float multi_vel = 100.0/SHIFT_DELAY_MS;
Expand All @@ -504,6 +508,17 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil
// Shift reporting
if (!stationary_shift) {
now_cs = ClutchSpeedModel::get_shifting_clutch_speeds(sensor_data.output_rpm, this->rpm_reading, req_lookup, this->gearboxConfig.bounds);
int turbine_from_output = sensor_data.output_rpm * preshift_ratio;
pre_shift_rpm.calc_rpm = turbine_from_output;
pre_shift_rpm.n2_raw = turbine_from_output;
pre_shift_rpm.n3_raw = turbine_from_output;
if (preshift_n3_set_zero) {
pre_shift_rpm.n3_raw = 0;
// Emulate N2 speed based on turbine speed and RATIO 2_1
pre_shift_rpm.n2_raw = (float)(pre_shift_rpm.calc_rpm) / Sensors::get_ratio_2_1();
}
// Grab the clutch speeds as if a shift has not started yet. (Used for comparison of speed changes)
pre_cs = ClutchSpeedModel::get_shifting_clutch_speeds(sensor_data.output_rpm, pre_shift_rpm, req_lookup, this->gearboxConfig.bounds);

if (now_cs.off_clutch_speed < -50 || now_cs.on_clutch_speed < -50) {
flaring = true;
Expand All @@ -513,15 +528,10 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil
} else {
flaring = false;
}
if (now_cs.off_clutch_speed < 25) {
pre_cs = now_cs;
}

on_velocity_avg.add_sample((old_cs.on_clutch_speed - now_cs.on_clutch_speed)*multi_vel);
off_velocity_avg.add_sample((old_cs.off_clutch_speed - now_cs.off_clutch_speed)*multi_vel);
on_velocity_avg.add_sample((now_cs.on_clutch_speed - pre_cs.on_clutch_speed));
off_velocity_avg.add_sample((now_cs.off_clutch_speed - pre_cs.off_clutch_speed));
this->shifting_velocity.on_clutch_vel = on_velocity_avg.get_average();
this->shifting_velocity.off_clutch_vel = off_velocity_avg.get_average();
old_cs = now_cs;
if (enable_torque_request) {
this->set_torque_request(trd.ty, trd.bounds, trd.amount);
}
Expand Down
2 changes: 1 addition & 1 deletion src/shifting_algo/s_algo.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef struct {
PrefillData prefill_info;
ShiftCharacteristics chars;
ShiftClutchData* ptr_r_clutch_speeds;
ShiftClutchData* ptr_r_pre_clutch_speeds;
ShiftPressures* ptr_prev_pressures;
ShiftPressures* ptr_w_pressures;
TorqueRequstData* ptr_w_trq_req;
Expand All @@ -53,7 +54,6 @@ class ShiftingAlgorithm {
virtual uint8_t step(
uint8_t phase_id,
uint16_t abs_input_torque,
int16_t static_torque_no_reduction,
bool stationary,
bool is_upshift,
uint16_t phase_elapsed,
Expand Down

0 comments on commit 1d8162a

Please sign in to comment.