Skip to content

Commit

Permalink
Calc input torque seperatly in shifting
Browse files Browse the repository at this point in the history
  • Loading branch information
rnd-ash committed May 13, 2024
1 parent ceb42d9 commit 021ae84
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
32 changes: 22 additions & 10 deletions src/gearbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)+
Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
17 changes: 8 additions & 9 deletions src/models/input_torque.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/models/input_torque.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <common_structs.h>

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);
};

Expand Down
10 changes: 9 additions & 1 deletion src/nvs/eeprom_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 021ae84

Please sign in to comment.