Skip to content

Commit

Permalink
Shift and TCC improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rnd-ash committed Mar 3, 2023
1 parent a195f6a commit d1d12b2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
36 changes: 20 additions & 16 deletions src/gearbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,15 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil
float curr_torq_request = 0;
bool do_egs_req = true;
float mpc_release_delay = 0;
float reduction_factor = 0;
while(process_shift) {
int rpm_target_gear = calc_input_rpm_from_req_gear(sensor_data.output_rpm, this->target_gear, this->gearboxConfig.ratios);
int rpm_current_gear = calc_input_rpm_from_req_gear(sensor_data.output_rpm, this->actual_gear, this->gearboxConfig.ratios);
int rpm_to_target_gear = abs(sensor_data.input_rpm - rpm_current_gear);

int current_trq = sensor_data.input_torque;
if (sensor_data.input_torque > 0 && sensor_data.driver_requested_torque > sensor_data.input_torque) {
current_trq = sensor_data.driver_requested_torque;
}
if (phase_elapsed > phase_hold_time+phase_ramp_time && current_phase < SHIFT_PHASE_OVERLAP) {
phase_elapsed = 0;
current_phase++;
Expand Down Expand Up @@ -410,7 +414,7 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil
float spc_trq_multi;
ShiftCharacteristics ss_now = profile->get_shift_characteristics(req_lookup, &this->sensor_data);
// 0% - 100% (Or more)
float torque_decimal = (float)(abs(sensor_data.input_torque)*100.0) / (float)(gearboxConfig.max_torque);
float torque_decimal = (float)(abs(current_trq)*100.0) / (float)(gearboxConfig.max_torque);
switch (apply_clutch) {
case Clutch::K1: // 1->2 and 5->4
if (req_lookup == ProfileGearChange::ONE_TWO) {
Expand Down Expand Up @@ -567,22 +571,17 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil
}

// Torque request behaviour (Experiment for EGS52 and ME2.7/8)
if (current_phase > SHIFT_PHASE_BLEED) {
if (sensor_data.static_torque > 100 && is_upshift && do_egs_req) { // No need for EGS Req
if (current_phase >= SHIFT_PHASE_BLEED) {
if (sensor_data.driver_requested_torque > 100) { // No need for EGS Req
TorqueRequest req = TorqueRequest::LessThan;
if (shift_progress_percentage < 50 && curr_torq_request > 50) { // Decrease torque from driver demand
curr_torq_request -= scale_number(sensor_data.static_torque, 0.5, 2.0, 0, gearboxConfig.max_torque) * scale_number(chars.target_shift_time, 2.5, 1.0, 100, 1000); ;
if (shift_progress_percentage < 50) { // Decrease torque from driver demand
reduction_factor = scale_number(chars.target_shift_time , 50, 80, 100, 1000)/100.0;
curr_torq_request = linear_interp(MIN(sensor_data.driver_requested_torque, sensor_data.static_torque), (float)sensor_data.driver_requested_torque*reduction_factor, shift_progress_percentage, 50);
} else { // Shifting nearing completion
req = TorqueRequest::LessThanFast;
curr_torq_request += scale_number(sensor_data.static_torque, 0.5, 2.0, 0, gearboxConfig.max_torque);
}
if (sensor_data.static_torque < curr_torq_request) {
do_egs_req = false;
this->set_torque_request(TorqueRequest::None, 0);
curr_torq_request = linear_interp(sensor_data.static_torque, sensor_data.driver_requested_torque, shift_progress_percentage-50, 50);
}
this->set_torque_request(req, curr_torq_request);
} else {
do_egs_req = false;
}
} else {
// Set the start torque amount, but don't use it yet
Expand Down Expand Up @@ -617,9 +616,11 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil
pressure_manager->set_target_spc_pressure(c);
this->mpc_working = pressure_manager->find_working_mpc_pressure(this->target_gear);
// Finish torque request
if (do_egs_req) {
if (curr_torq_request != 0 && curr_torq_request < MIN(sensor_data.static_torque, sensor_data.driver_requested_torque)) {
// End target is always pedal torque
this->set_torque_request(TorqueRequest::LessThanFast, linear_interp(curr_torq_request, sensor_data.driver_requested_torque, e, sd.max_pressure_data.ramp_time + sd.max_pressure_data.hold_time));
this->set_torque_request(TorqueRequest::LessThanFast, linear_interp(curr_torq_request, sensor_data.driver_requested_torque, e, sd.max_pressure_data.ramp_time));
} else {
this->set_torque_request(TorqueRequest::None, 0);
}
vTaskDelay(20);
e += 20;
Expand Down Expand Up @@ -871,6 +872,7 @@ void Gearbox::controller_loop()

bool can_read_input = this->calc_input_rpm(&sensor_data.input_rpm);
bool can_read_output = this->calc_output_rpm(&this->sensor_data.output_rpm, now);
//ESP_LOGI("MAIN", "%d %d", can_read_input, can_read_output);
bool can_read = can_read_input && can_read_output;
if (can_read)
{
Expand Down Expand Up @@ -1303,7 +1305,7 @@ bool Gearbox::calc_output_rpm(uint16_t *dest, uint64_t now)
}
rpm *= this->diff_ratio_f;
rpm /= 2;

//ESP_LOGI("ORPM", "Output RPM %.1f (%d %d)", rpm, sensor_data.rl_wheel.double_rpm, sensor_data.rr_wheel.double_rpm);
// Car is 4Matic, but only calcualte extra if it is not a 1:1 4Matic.
// Cars tend to be always 1:1 (Simple 4WD), but vehicles like G-Wagon / Sprinter will have a variable transfer case
if (VEHICLE_CONFIG.is_four_matic && (VEHICLE_CONFIG.transfer_case_high_ratio != 1000 || VEHICLE_CONFIG.transfer_case_low_ratio != 1000))
Expand Down Expand Up @@ -1348,6 +1350,7 @@ bool Gearbox::calc_output_rpm(uint16_t *dest, uint64_t now)
bool Gearbox::calcGearFromRatio(bool is_reverse)
{
float ratio = (float)this->sensor_data.input_rpm / (float)this->sensor_data.output_rpm;
//ESP_LOGI("CGFR", "R %.3f", ratio);
if (is_reverse)
{
ratio *= -1;
Expand All @@ -1356,6 +1359,7 @@ bool Gearbox::calcGearFromRatio(bool is_reverse)
GearRatioLimit limits = gearboxConfig.bounds[i + 5];
if (ratio >= limits.min && ratio <= limits.max)
{
//ESP_LOGI("CGFR", "G %d", i+1);
this->est_gear_idx = i + 1;
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/pressure_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ uint16_t PressureManager::find_working_mpc_pressure(GearboxGear curr_g) {
break;
}

float trq_percent = (float)(sensor_data->input_torque*100.0)/(float)this->gb_max_torque;
float trq_percent = (float)(MAX(sensor_data->input_torque, sensor_data->driver_requested_torque)*100.0)/(float)this->gb_max_torque;
return this->mpc_working_pressure->get_value(trq_percent, gear_idx);
}

Expand Down Expand Up @@ -344,7 +344,7 @@ void PressureManager::set_target_tcc_pressure(uint16_t targ) {
uint16_t PressureManager::get_mpc_hold_adder(Clutch to_apply) {
uint16_t ret = 0;
if (this->hold2_pressure_mpc_adder_map != nullptr) {
float trq_percent = (float)(sensor_data->input_torque*100.0)/(float)this->gb_max_torque;
float trq_percent = (float)(MAX(sensor_data->input_torque, sensor_data->driver_requested_torque)*100.0)/(float)this->gb_max_torque;
ret = hold2_pressure_mpc_adder_map->get_value(trq_percent, (uint8_t)to_apply);
}
return ret;
Expand Down
9 changes: 5 additions & 4 deletions src/torque_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void TorqueConverter::adjust_map_cell(GearboxGear g, uint16_t new_pressure) {

void TorqueConverter::update(GearboxGear curr_gear, PressureManager* pm, AbstractProfile* profile, SensorData* sensors, bool is_shifting) {
uint32_t input_rpm = sensors->input_rpm;
int trq = MAX(sensors->static_torque, sensors->driver_requested_torque);
if (input_rpm <= TCC_MIN_LOCKING_RPM) {
if (this->last_idle_timestamp == 0) {
this->last_idle_timestamp = sensors->current_timestamp_ms;
Expand Down Expand Up @@ -125,7 +126,7 @@ void TorqueConverter::update(GearboxGear curr_gear, PressureManager* pm, Abstrac
// Requires:
// * torque in bounds
// * Engine RPM - Less than TCC stall speed
if (sensors->static_torque >= this->low_torque_adapt_limit && sensors->static_torque <= this->high_torque_adapt_limit && sensors->engine_rpm < 2500) {
if (trq >= this->low_torque_adapt_limit && trq <= this->high_torque_adapt_limit && sensors->engine_rpm < 2500) {
if (sensors->tcc_slip_rpm > 0 && sensors->tcc_slip_rpm < TCC_ADAPT_CONSIDERED_LOCK) {
adapt_lock_count++;
} else {
Expand Down Expand Up @@ -155,9 +156,9 @@ void TorqueConverter::update(GearboxGear curr_gear, PressureManager* pm, Abstrac
// Dynamic TCC pressure increase based on torque
this->curr_tcc_pressure = this->base_tcc_pressure;
if (!learning) {
if (sensors->static_torque > high_torque_adapt_limit) {
int torque_delta = sensors->static_torque - high_torque_adapt_limit;
this->curr_tcc_pressure += (1.4*torque_delta); // 2mBar per Nm
if (trq > high_torque_adapt_limit) {
int torque_delta = trq - high_torque_adapt_limit;
this->curr_tcc_pressure += (1.5*torque_delta); // 2mBar per Nm
} else if (sensors->static_torque < 40) {
if (this->curr_tcc_pressure > TCC_PREFILL) {
this->curr_tcc_pressure -= scale_number(sensors->static_torque, 100, 50, -40, 40);
Expand Down

0 comments on commit d1d12b2

Please sign in to comment.