Skip to content

Commit

Permalink
Split shifting code into new classes per algo
Browse files Browse the repository at this point in the history
  • Loading branch information
rnd-ash committed Jun 23, 2024
1 parent 19c3a39 commit 796fa8b
Show file tree
Hide file tree
Showing 16 changed files with 532 additions and 540 deletions.
4 changes: 3 additions & 1 deletion src/adaptation/shift_adaptation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ void ShiftAdaptationSystem::record_shift_start(uint64_t time_into_shift, int ove
}
}

/*
void ShiftAdaptationSystem::record_shift_end(ShiftStage c_stage, uint64_t time_into_phase, uint16_t mpc, uint16_t spc) {
ESP_LOGI("ADAPT", "Shift ended. %d mBar on MPC, %d mBar on SPC", mpc, spc);
}
Expand All @@ -129,6 +130,7 @@ void ShiftAdaptationSystem::record_flare(ShiftStage when, uint64_t elapsed){
this->flare_location = when;
this->flare_time = elapsed;
}
*/

uint16_t ShiftAdaptationSystem::get_overlap_end_shift_pressure(ProfileGearChange change, uint16_t selected_prefill_pressure) {
uint16_t ret = selected_prefill_pressure*2;
Expand All @@ -142,7 +144,7 @@ uint32_t ShiftAdaptationSystem::check_prefill_adapt_conditions_start(SensorData*
uint32_t ret = (int)AdaptCancelFlag::ADAPTABLE;
this->current_change = change;
this->flared = false;
this->flare_location = ShiftStage::Bleed;
//this->flare_location = ShiftStage::Bleed;
this->flare_time = 0;

if (sensors->input_rpm < ADP_CURRENT_SETTINGS.min_input_rpm) {
Expand Down
5 changes: 2 additions & 3 deletions src/adaptation/shift_adaptation.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class ShiftAdaptationSystem {
uint32_t check_prefill_adapt_conditions_start(SensorData* sensors, ProfileGearChange change);

void record_shift_start(uint64_t time_into_shift, int overlap_start_ts, uint16_t mpc, uint16_t spc, ShiftClutchVelocity vel, uint16_t delta_rpm);
void record_shift_end(ShiftStage c_stage, uint64_t time_into_phase, uint16_t mpc, uint16_t spc);
//void record_shift_end(ShiftStage c_stage, uint64_t time_into_phase, uint16_t mpc, uint16_t spc);

void record_flare(ShiftStage when, uint64_t elapsed);
//void record_flare(ShiftStage when, uint64_t elapsed);
uint16_t get_overlap_end_shift_pressure(ProfileGearChange change, uint16_t selected_prefill_pressure);

AdaptPrefillData get_prefill_adapt_data(ProfileGearChange change);
Expand All @@ -67,7 +67,6 @@ class ShiftAdaptationSystem {
ProfileGearChange current_change;

bool flared = false;
ShiftStage flare_location = ShiftStage::Bleed;
uint64_t flare_time = 0;
};

Expand Down
31 changes: 1 addition & 30 deletions src/common_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,6 @@
typedef int16_t pressure_map[11];
typedef float rpm_modifier_map[9];

/**
* @brief Shifting state
*/
enum class ShiftStage {
/**
* @brief Hydralic bleed phase.
* In this phase, Shift pressure fluid is bled in order to not over pressurise the overlap valve
* The shift solenoid is not active
*/
Bleed = 1,
/**
* @brief Clutch filling phase.
* In this phase, the shift solenoid is engaged, and Shift pressure is ramped in order to clear
* the tolorance between the engaging clutch pack, without actually applying it.
*/
Fill = 2,
/**
* @brief Clutch overlap phase.
* In this phase, the engaging clutch's pressure is raised, whilst the disengaging clutch's pressure
* is reduced, causing (Via the overlap hydralic valve), the gearbox to transition clutch packs.
*/
Overlap = 3,
/**
* @brief Shift pressure is increased to its maximum via a ramp in order to lock the engaging clutch in place.
* Then, the shift solenoid turns off, completing the gear change.
*/
MaxPressure = 4
};

enum class Clutch {
K1 = 0,
K2 = 1,
Expand Down Expand Up @@ -169,7 +140,7 @@ enum class ShiftCircuit {
* @brief Shift data request structure
*
*/
struct ShiftData{
struct CircuitInfo{
ShiftCircuit shift_circuit;
uint8_t targ_g;
uint8_t curr_g;
Expand Down
13 changes: 0 additions & 13 deletions src/common_structs_ops.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
#include "common_structs_ops.h"

ShiftStage next_shift_stage(ShiftStage now) {
switch(now) {
case ShiftStage::Bleed:
return ShiftStage::Fill;
case ShiftStage::Fill:
return ShiftStage::Overlap;
case ShiftStage::Overlap:
case ShiftStage::MaxPressure:
default:
return ShiftStage::MaxPressure;
}
}

Clutch get_clutch_to_apply(ProfileGearChange change) {
switch(change) {
case ProfileGearChange::ONE_TWO:
Expand Down
1 change: 0 additions & 1 deletion src/common_structs_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "common_structs.h"
#include "shifter/shifter.h"

ShiftStage next_shift_stage(ShiftStage now);
Clutch get_clutch_to_apply(ProfileGearChange change);
Clutch get_clutch_to_release(ProfileGearChange change);

Expand Down
2 changes: 1 addition & 1 deletion src/diag/diag_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ DATA_GEARBOX_SENSORS get_gearbox_sensors(Gearbox* g) {

DATA_SOLENOIDS get_solenoid_data(Gearbox* gb_ptr) {
DATA_SOLENOIDS ret = {};
if (gb_ptr == nullptr) {
if (sol_mpc == nullptr) {
memset(&ret, 0xFF, sizeof(ret));
return ret;
}
Expand Down
15 changes: 11 additions & 4 deletions src/diag/kwp2000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1276,9 +1276,14 @@ void Kwp2000_server::run_solenoid_test() {

SolRtRes res{};
res.lid = this->routine_id;
res.atf_temp = this->gearbox_ptr->sensor_data.atf_temp;

this->gearbox_ptr->diag_inhibit_control();
int16_t tmp = 0;
if (Sensors::read_atf_temp(&tmp) != ESP_OK) {
return;
}
res.atf_temp = tmp;
if (nullptr != this->gearbox_ptr) {
this->gearbox_ptr->diag_inhibit_control();
}
Solenoids::notify_diag_test_start();

PwmSolenoid* order[6] = {sol_mpc, sol_spc, sol_tcc, sol_y3, sol_y4, sol_y5};
Expand All @@ -1297,7 +1302,9 @@ void Kwp2000_server::run_solenoid_test() {
}
this->routine_running = false;
Solenoids::notify_diag_test_end();
this->gearbox_ptr->diag_regain_control();
if (nullptr != this->gearbox_ptr) {
this->gearbox_ptr->diag_regain_control();
}
memcpy(this->routine_result, &res, sizeof(SolRtRes));
vTaskDelete(nullptr);
}
Loading

0 comments on commit 796fa8b

Please sign in to comment.