SHIFT_RPT: Add new reporter for logging shifts

This commit is contained in:
Ashcon Mohseninia 2022-06-07 21:06:51 +01:00
parent 9936d62745
commit 1d6579b1d0
6 changed files with 150 additions and 39 deletions

View File

@ -6,4 +6,5 @@ factory, app, factory, 0x10000, 0x100000
ota_0, app, ota_0, 0x110000, 0x100000
ota_1, app, ota_1, 0x210000, 0x100000
coredump, data, coredump, 0x310000, 0x20000
tcm_user_config, data, nvs, 0x330000, 0x19000
tcm_user_config, data, nvs, 0x330000, 0x19000
tcm_shift_store, data, nvs, 0x349000, 0x7D000
1 # Name, Type, SubType, Offset, Size, Flags
6 ota_0, app, ota_0, 0x110000, 0x100000
7 ota_1, app, ota_1, 0x210000, 0x100000
8 coredump, data, coredump, 0x310000, 0x20000
9 tcm_user_config, data, nvs, 0x330000, 0x19000
10 tcm_shift_store, data, nvs, 0x349000, 0x7D000

View File

@ -0,0 +1,61 @@
#include "shift_report.h"
#include "string.h"
#define NVS_NAME_SS "SHIFT_STORE"
ShiftReporter::ShiftReporter() {
bool failure = true;
if (nvs_open("tcm_shift_store", NVS_READWRITE, &this->nvs_handle) != ESP_OK) {
ESP_LOGE("SHIFT_REPORTER","Cannot open TCM Shift store partition, no data will be saved");
return;
}
// Ok so now we have our default grp structure,
// Try to allocate memory
memset(&this->report_group, 0x00, sizeof(ShiftReportNvsGroup));
size_t s = sizeof(ShiftReportNvsGroup);
esp_err_t e = nvs_get_blob(this->nvs_handle, NVS_NAME_SS, &this->report_group, &s);
if (e == ESP_ERR_NVS_NOT_FOUND) {
ESP_LOGE("SHIFT_REPORTER", "History not found in NVS, Creating a new one!");
// Init a blank slate
e = nvs_set_blob(this->nvs_handle, NVS_NAME_SS, &this->report_group, s);
if (e != ESP_OK) {
ESP_LOGE("SHIFT_REPORTER", "Error writing new Shift report to EEPROM (%s)", esp_err_to_name(e));
} else {
failure = false;
}
} else if (e != ESP_OK) {
ESP_LOGE("SHIFT_REPORTER", "Could not read current stored shift report: %s", esp_err_to_name(e));
} else {
failure = false;
}
// Copy structure over
if(!failure) {
ESP_LOGI("SHIFT_REPORTER", "Init OK!");
}
}
ShiftReporter::~ShiftReporter() {
}
void ShiftReporter::add_report(ShiftReport src) {
// Which index to we write to?
if (this->report_group.index >= MAX_REPORTS) {
this->report_group.index = 0;
}
uint8_t idx = this->report_group.index;
ESP_LOGI("SHIFTER", "Writing to report %d as writable", idx);
this->report_group.reports[idx] = src;
this->report_group.index++;
this->has_change = true;
}
void ShiftReporter::save() {
if (!has_change) {
return;
}
nvs_set_blob(this->nvs_handle, NVS_NAME_SS, &this->report_group, sizeof(ShiftReportNvsGroup));
nvs_commit(this->nvs_handle);
}

View File

@ -0,0 +1,33 @@
#ifndef __SHIFT_REPORT_H__
#define __SHIFT_REPORT_H__
#include "common_structs.h"
#include "nvs.h"
#define MAX_REPORTS 10
typedef struct {
ShiftReport reports[MAX_REPORTS];
uint8_t index;
} ShiftReportNvsGroup;
// 0x7D000 from partitions.csv (tcm_shift_store) partition
static_assert(sizeof(ShiftReportNvsGroup) < 0x7D000, "ShiftReportNvsGroup cannot fit into designated partition!");
class ShiftReporter {
public:
ShiftReporter();
~ShiftReporter();
void add_report(ShiftReport src);
void save();
ShiftReportNvsGroup* diag_get_nvs_group_ptr() { return &this->report_group; }
private:
bool has_change = false;
ShiftReportNvsGroup report_group;
nvs_handle_t nvs_handle;
};
#endif // __SHIFT_REPORT_H__

View File

@ -260,41 +260,29 @@ typedef struct {
int min_slip_rpm;
} TccLockupBounds;
#define MAX_POINTS_PER_SR_ARRAY 6000/20/2
typedef struct {
/**
* @brief Initial MPC pwm (From map)
*/
int initial_mpc_pwm;
/**
* @brief Initial SPC pwm (From map)
*/
int initial_spc_pwm;
/**
* @brief Ramp down speed of SPC PWM (Ramp down -> Increase pressure) (1 = 0.1% per 50ms)
*/
float spc_ramp_down_speed;
/**
* @brief Once the shift has started, how quickly do we reduce `spc_ramp_down_speed`
* to smooth out the end of the shift so we don't slam the clutches into place
*/
float spc_ramp_down_fade_multiplier;
/**
* @brief PWM for SPC to open before shift valve is commanded
*/
int spc_pre_open_pwm;
/**
* @brief Time for SPC to open before shift valve is commanded
*/
int spc_pre_open_time;
/**
* @brief Time for SPC to stick to initial_spc_pwm once shift valve has opened
*/
int spc_prefill_time;
/**
* @brief The multiplier for MPC to increase its pressure by whilst SPC is prefilling
* (Aids flare reduction by compensating for lost pressure on MPC line)
*/
int mpc_compensation_prefill;
} ShiftData2;
int atf_temp_c;
// Target << 4 | current
uint8_t targ_curr;
uint8_t interval_points;
uint16_t report_array_len;
uint16_t engine_rpm[MAX_POINTS_PER_SR_ARRAY];
uint16_t input_rpm[MAX_POINTS_PER_SR_ARRAY];
int16_t engine_torque[MAX_POINTS_PER_SR_ARRAY];
uint16_t total_ms;
ShiftPhase hold1_data;
ShiftPhase hold2_data;
ShiftPhase hold3_data;
ShiftPhase torque_data;
ShiftPhase overlap_data;
ShiftPhase max_pressure_data;
// Flags for reporting shift errors
uint16_t flare_timestamp;
uint8_t shift_timeout;
} __attribute__ ((packed)) ShiftReport;
const int SD_Size = sizeof(ShiftReport);
#endif

View File

@ -60,6 +60,7 @@ Gearbox::Gearbox() {
};
this->tcc = new TorqueConverter();
this->pressure_mgr = new PressureManager(&this->sensor_data);
this->shift_reporter = new ShiftReporter();
if(VEHICLE_CONFIG.is_large_nag) {
this->gearboxConfig = GearboxConfiguration {
@ -266,7 +267,19 @@ ShiftResponse Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfil
ESP_LOGI("ELAPSE_SHIFT", "Shift started!");
ShiftData sd = pressure_mgr->get_shift_data(&this->sensor_data, req_lookup, profile->get_shift_characteristics(req_lookup, &this->sensor_data), gearboxConfig.max_torque);
ShiftReport dest_report;
memset(&dest_report, 0x00, sizeof(ShiftReport));
// Copy data
dest_report.hold1_data = sd.hold1_data;
dest_report.hold2_data = sd.hold2_data;
dest_report.hold3_data = sd.hold3_data;
dest_report.torque_data = sd.torque_data;
dest_report.overlap_data = sd.overlap_data;
dest_report.max_pressure_data = sd.max_pressure_data;
dest_report.atf_temp_c = sensor_data.atf_temp;
uint16_t index = 0;
bool add_report = true;
uint16_t stage_elapsed = 0;
uint16_t total_elapsed = 0;
uint8_t shift_stage = SHIFT_PHASE_HOLD_1;
@ -275,7 +288,7 @@ ShiftResponse Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfil
uint16_t curr_sd_percent = 0;
pressure_mgr->set_target_spc_percent(curr_spc_pwm_percent ,-1);
ShiftPhase* curr_phase = &sd.hold1_data;
float ramp = (curr_spc_pwm_percent-(float)(curr_phase->pwm_percent)) / ((float)MAX(curr_phase->ramp_time,SHIFT_DELAY_MS)/(float)SHIFT_DELAY_MS);
uint8_t timeout = 0;
ESP_LOGI("SHIFT", "Shift start phase hold 1");
while(true) {
// Execute the current phase
@ -338,12 +351,18 @@ ShiftResponse Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfil
break;
}
if (stage_elapsed > SHIFT_TIMEOUT_MS) { // Too long at max p and car didn't shift!?
timeout = 1;
break;
}
}
// Always monitor the progress of the shift!
pressure_mgr->set_target_spc_percent(curr_spc_pwm_percent ,-1);
if (add_report && index < MAX_POINTS_PER_SR_ARRAY) {
dest_report.engine_rpm[index] = (uint16_t)sensor_data.engine_rpm;
dest_report.input_rpm[index] = (uint16_t)sensor_data.input_rpm;
dest_report.engine_torque[index] = (int16_t)sensor_data.static_torque;
index++;
}
add_report = !add_report;
sd.shift_solenoid->write_pwm_percent_with_voltage(curr_sd_percent, sensor_data.voltage); // Write to shift solenoid
vTaskDelay(SHIFT_DELAY_MS);
total_elapsed += SHIFT_DELAY_MS;
@ -354,6 +373,13 @@ ShiftResponse Gearbox::elapse_shift(ProfileGearChange req_lookup, AbstractProfil
sd.shift_solenoid->write_pwm_percent(0); // Close SPC and Shift solenoid
egs_can_hal->set_torque_request(TorqueRequest::None);
egs_can_hal->set_requested_torque(0);
// Copy the response len
dest_report.report_array_len = index-1;
dest_report.interval_points = SHIFT_DELAY_MS*2;
dest_report.total_ms = total_elapsed;
dest_report.shift_timeout = timeout;
this->shift_reporter->add_report(dest_report);
ShiftResponse response = {
.measure_ok = false,
.flared = false,
@ -619,6 +645,7 @@ void Gearbox::controller_loop() {
if (this->pressure_mgr != nullptr) {
this->pressure_mgr->save();
}
this->shift_reporter->save();
} else if (this->shifter_pos == ShifterPosition::N) {
this->target_gear = GearboxGear::Neutral;
last_position = this->shifter_pos;

View File

@ -87,6 +87,7 @@ public:
return this->sensor_data.gear_ratio * 100;
}
static uint16_t redline_rpm;
ShiftReporter* shift_reporter;
private:
ShiftResponse elapse_shift(ProfileGearChange req_lookup, AbstractProfile* profile, bool is_upshift);
bool calcGearFromRatio(bool is_reverse);