From 021ae849876321c58595b783ff93271d02062dc2 Mon Sep 17 00:00:00 2001 From: Ashcon Mohseninia Date: Mon, 13 May 2024 18:59:13 +0100 Subject: [PATCH] Calc input torque seperatly in shifting --- src/gearbox.cpp | 32 ++++++++++++++++++++++---------- src/models/input_torque.cpp | 17 ++++++++--------- src/models/input_torque.hpp | 2 +- src/nvs/eeprom_config.h | 10 +++++++++- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/gearbox.cpp b/src/gearbox.cpp index 7d188070..9467e607 100644 --- a/src/gearbox.cpp +++ b/src/gearbox.cpp @@ -467,7 +467,7 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil } int MOD_MAX = this->pressure_mgr->get_max_solenoid_pressure(); - int fill_p_torque_max_on_clutch = this->pressure_mgr->calc_max_torque_for_clutch(target_gear, applying, prefill_data.low_fill_pressure_on_clutch); + int fill_p_torque_max_on_clutch = this->pressure_mgr->calc_max_torque_for_clutch(target_gear, applying, prefill_data.fill_pressure_on_clutch); int DYNAMIC_SHIFT_THRESHOLD = fill_p_torque_max_on_clutch; #define FILL_RAMP_TIME 60 #define FILL_LP_HOLD_TIME 100 @@ -505,10 +505,18 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil result = false; break; } - int torque_to_use = abs(sensor_data.input_torque); + + int static_input = sensor_data.static_torque; if (output_data.ctrl_type != TorqueRequestControlType::None) { - torque_to_use += abs(current_torque_reduction); + static_input += abs(current_torque_reduction); } + + int torque_to_use = abs(InputTorqueModel::get_input_torque( + sensor_data.engine_rpm, + sensor_data.input_rpm, + static_input, + egs_can_hal->get_ac_torque_loss(500) + )); // Working pressure of the old clutch (Without torque reduction) int wp_old_clutch = pressure_manager->find_working_pressure_for_clutch(a_gear, releasing, torque_to_use, false); // Working pressure of the new clutch (Without torque reduction) @@ -712,9 +720,9 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil if (current_stage == ShiftStage::Bleed) { p_now.on_clutch = 0; - p_now.off_clutch = wp_old_clutch_real; + p_now.off_clutch = wp_old_clutch; p_now.overlap_shift = prefill_data.fill_pressure_on_clutch + spring_pressure_on_clutch; - p_now.overlap_mod = wp_old_clutch_real + spring_pressure_off_clutch; + p_now.overlap_mod = wp_old_clutch + spring_pressure_off_clutch; p_now.shift_sol_req = (p_now.overlap_shift-centrifugal_force_on_clutch)/SPC_GAIN; p_now.mod_sol_req = ((p_now.overlap_shift - centrifugal_force_on_clutch)*sd.pressure_multi_spc / SPC_GAIN)+ @@ -726,7 +734,7 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil ESP_LOGW("SHIFT", "Adapting was cancelled. Reason flag: 0x%08X", (int)prefill_adapt_flags); } if (phase_elapsed < prefill_data.fill_time) { // Hold 1 (Same for all shift types) - p_now.off_clutch = wp_old_clutch_real; + p_now.off_clutch = wp_old_clutch; p_now.on_clutch = prefill_data.fill_pressure_on_clutch; } else if (phase_elapsed < prefill_data.fill_time + FILL_RAMP_TIME) { // Ramp phase (Hold 1 -> Hold 2) if (filling_torque > DYNAMIC_SHIFT_THRESHOLD) { // Dynamic mode (Trq req starts here) @@ -753,7 +761,7 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil } else { // Hold 2 if (filling_torque > DYNAMIC_SHIFT_THRESHOLD) { // Dynamic p_now.on_clutch = prefill_data.low_fill_pressure_on_clutch; - p_now.off_clutch = wp_old_clutch; + p_now.off_clutch = wp_old_clutch_real; } else { // Comfort p_now.on_clutch = 0; p_now.off_clutch = wp_old_clutch_real; @@ -833,8 +841,7 @@ bool Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfile *profil // Phase 1. Release phase. // This part of the overlap phase should start the disengagement of the off clutch. if (filling_torque > DYNAMIC_SHIFT_THRESHOLD) { - p_now.on_clutch = interpolate_float(phase_elapsed, prefill_data.low_fill_pressure_on_clutch, prefill_data.low_fill_pressure_on_clutch+wp_new_clutch_real, 0, 500, InterpType::Linear); - int overlap_end_spc_max = spring_pressure_on_clutch + p_prev.on_clutch; + p_now.on_clutch = interpolate_float(phase_elapsed, prefill_data.low_fill_pressure_on_clutch, prefill_data.low_fill_pressure_on_clutch+wp_new_clutch_real, 0, 250, InterpType::Linear); p_now.overlap_shift = spring_pressure_on_clutch + p_now.on_clutch; p_now.shift_sol_req = MAX((p_now.overlap_shift - centrifugal_force_on_clutch)/SPC_GAIN, 0); @@ -1600,7 +1607,12 @@ void Gearbox::controller_loop() if (static_torque != INT_MAX) { this->sensor_data.static_torque = static_torque; - int input_torque = InputTorqueModel::get_input_torque(egs_can_hal, &sensor_data); + int input_torque = InputTorqueModel::get_input_torque( + sensor_data.engine_rpm, + sensor_data.input_rpm, + sensor_data.static_torque, + egs_can_hal->get_ac_torque_loss(500) + ); if (input_torque != INT16_MAX) { this->sensor_data.input_torque = input_torque; } diff --git a/src/models/input_torque.cpp b/src/models/input_torque.cpp index 92af7379..b6d64c20 100644 --- a/src/models/input_torque.cpp +++ b/src/models/input_torque.cpp @@ -2,19 +2,18 @@ #include "tcu_maths.h" #include "egs_calibration/calibration_structs.h" -int16_t InputTorqueModel::get_input_torque(EgsBaseCan* can_hal, SensorData* measures) { +int16_t InputTorqueModel::get_input_torque(uint16_t engine_rpm, uint16_t input_rpm, int16_t static_torque, uint8_t ac_torque) { int16_t ret = 0; - if (measures->static_torque == INT16_MAX) { + if (static_torque == INT16_MAX) { ret = INT16_MAX; - } else if (measures->engine_rpm == 0 || measures->engine_rpm == INT16_MAX) { - ret = measures->static_torque; + } else if (engine_rpm == 0 || engine_rpm == INT16_MAX) { + ret = static_torque; } else { - int motor_torque = measures->static_torque; - uint8_t ac_loss = can_hal->get_ac_torque_loss(500); - if (ac_loss != UINT8_MAX) { - motor_torque -= ac_loss; + int motor_torque = static_torque; + if (ac_torque != UINT8_MAX) { + motor_torque -= ac_torque; } - float multi = InputTorqueModel::get_input_torque_factor(measures->engine_rpm, measures->input_rpm); + float multi = InputTorqueModel::get_input_torque_factor(engine_rpm, input_rpm); ret = motor_torque * multi; } return ret; diff --git a/src/models/input_torque.hpp b/src/models/input_torque.hpp index ae4506f5..87bdfc3c 100644 --- a/src/models/input_torque.hpp +++ b/src/models/input_torque.hpp @@ -6,7 +6,7 @@ #include namespace InputTorqueModel { - int16_t get_input_torque(EgsBaseCan* can_hal, SensorData* measures); + int16_t get_input_torque(uint16_t engine_rpm, uint16_t input_rpm, int16_t static_torque, uint8_t ac_torque); float get_input_torque_factor(uint16_t engine, uint16_t input); }; diff --git a/src/nvs/eeprom_config.h b/src/nvs/eeprom_config.h index 44ac5421..bed0e679 100644 --- a/src/nvs/eeprom_config.h +++ b/src/nvs/eeprom_config.h @@ -27,6 +27,9 @@ struct __attribute__ ((packed)) TCM_CORE_CONFIG{ // 1 - TRRS // 2 - SLR uint8_t shifter_style; + // 0 - Output (Generic) + // 1 - Vehicle speed sensor + // 2 - TCC Manual MOSFET (1.3 ONLY) uint8_t io_0_usage; uint8_t input_sensor_pulses_per_rev; uint8_t output_pulse_width_per_kmh; @@ -50,7 +53,12 @@ struct __attribute__ ((packed)) TCM_CORE_CONFIG{ // PRODUCT.M_YEAR, EFUSE_BLK3, 32, 8 struct __attribute__ ((packed)) TCM_EFUSE_CONFIG { - uint8_t board_ver; // 1 - Red PCB, 2 - Black PCB, 3 - Black PCB with GPIO (WIP) + // 1 - Red PCB (V1.1) + // 2 - Blue PCB (V1.2) + // 3 - Black PCB (V1.3) + // 4 - Green PCB (V1.4 - PRE PROD) + // 0xF | 4 - Green PCB HGS Variant + uint8_t board_ver; uint8_t manufacture_day; uint8_t manufacture_week; uint8_t manufacture_month;