Skip to content

Commit

Permalink
Merge pull request #12 from rnd-ash/dev
Browse files Browse the repository at this point in the history
Update new features + Loads of fixes!
  • Loading branch information
rnd-ash authored Apr 3, 2022
2 parents 3cdf827 + 7f8ae2d commit 74c4896
Show file tree
Hide file tree
Showing 13 changed files with 336 additions and 143 deletions.
10 changes: 5 additions & 5 deletions src/adaptation/adapt_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,18 @@ void AdaptationMap::perform_adaptation(SensorData* sensors, ProfileGearChange ch
bool accel_shift = sensors->d_output_rpm > 0;
bool idle_shift = sensors->static_torque > 0;

if (response.spc_map_start - response.spc_change_start > 20) { // SPC is taking too long to bite so reduce it || Gearbox flared so needs more SPC
if (response.spc_map_start - response.spc_change_start > 50) { // SPC is taking too long to bite so reduce it || Gearbox flared so needs more SPC
if (idle_shift) {
if (accel_shift) {
this->adapt_data[adaptation_idx].offset_accel_idle -= 10; // +1% pressure
this->adapt_data[adaptation_idx].offset_accel_idle -= 5; // +1% pressure
} else {
this->adapt_data[adaptation_idx].offset_decel_idle -= 10; // +1% pressure
this->adapt_data[adaptation_idx].offset_decel_idle -= 5; // +1% pressure
}
} else {
if (accel_shift) {
this->adapt_data[adaptation_idx].offset_accel_load -= 5; // +1% pressure
this->adapt_data[adaptation_idx].offset_accel_load -= 10; // +1% pressure
} else {
this->adapt_data[adaptation_idx].offset_decel_load -= 5; // +1% pressure
this->adapt_data[adaptation_idx].offset_decel_load -= 7; // +1% pressure
}
}
} else if (response.spc_map_start - response.spc_change_start < 10) { // SPC tolorance is too tight, decrease initial SPC pressure
Expand Down
4 changes: 3 additions & 1 deletion src/canbus/can_egs52.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,13 @@ PaddlePosition Egs52Can::get_paddle_position(uint64_t now, uint64_t expire_time_
return PaddlePosition::Plus;
case SBW_232h_LRT_PM3::MINUS:
return PaddlePosition::Minus;
case SBW_232h_LRT_PM3::SNV:
return PaddlePosition::SNV;
default:
return PaddlePosition::None;
}
} else {
return PaddlePosition::None;
return PaddlePosition::SNV;
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/canbus/can_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum class WheelDirection {
Forward, // Wheel going forwards
Reverse, // Wheel going backwards
Stationary, // Stationary (Not forward or backwards)
SignalNotAvaliable // SNV
SignalNotAvaliable = 0xFF // SNV
};

struct WheelData {
Expand All @@ -44,7 +44,7 @@ enum class SystemStatusCheck {
enum class EngineType {
Diesel,
Petrol,
Unknown
Unknown = 0xFF
};

enum class TorqueRequest {
Expand All @@ -63,14 +63,15 @@ enum class GearboxGear {
Neutral = 9,
Reverse_First = 10,
Reverse_Second = 11,
SignalNotAvaliable = 12,
SignalNotAvaliable = 0xFF,
};

enum class PaddlePosition {
None,
Plus,
Minus,
PlusAndMinus
PlusAndMinus,
SNV = 0xFF
};

enum class ClutchStatus {
Expand Down Expand Up @@ -106,7 +107,7 @@ enum class ShifterPosition {
D,
PLUS,
MINUS,
SignalNotAvaliable // SNV
SignalNotAvaliable = 0xFF // SNV
};

enum class SolenoidName {
Expand All @@ -130,7 +131,7 @@ enum class GearboxDisplayGear {
Four,
Five,
Failure,
SNA,
SNA = 0xFF,
};

enum class GearboxMessage {
Expand Down
19 changes: 11 additions & 8 deletions src/common_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,16 @@ enum class ProfileGearChange {
typedef struct {
/// The initial SPC PWM value to start the shift off. This should be the 'biting point' of the clutch packs
uint16_t initial_spc_pwm;
/// The intial MPC PWM value to start the shift off. This should allow for easy SPC movement, but not
/// too little otherwise the gearbox will slip too much
uint16_t mpc_pwm;
/// Target time in milliseconds for the shift to complete
uint16_t targ_d_rpm;
// Shift speed factor. Valid range = 1 - 10 (Auto clamped if value is outside this range) - Higher = faster shift
float shift_speed;
/// The intial MPC PWM value to start the shift off.
/// This must ALWAYS be more or equal to initial_spc_pwm, otherwise the box will hydralically
/// perform an ABORT shift
uint16_t initial_mpc_pwm;
/// SPC Ramp speed, denotes the speed of which SPC pressure will increase during the shift
float spc_dec_speed;
/// MPC Ramp speed, denotes the speed of which MPC pressure will increase during the shift
/// IMPORTANT: This value must ALWAYS be less than spc_dec_speed, otherwise the box will
/// fail to shift!
float mpc_dec_speed;
/// The shift solenoid required to change gears
Solenoid* shift_solenoid;
/// Current gear the gearbox is in as an integer
Expand All @@ -117,7 +120,7 @@ typedef struct {
} ShiftData;

#pragma GCC diagnostic ignored "-Wmissing-field-initializers" // This is ALWAYS correctly initialized in pressure_manager.cpp
const ShiftData DEFAULT_SHIFT_DATA = { .initial_spc_pwm = 100, .mpc_pwm = 100, .targ_d_rpm = 50, .shift_speed = 5.0};
const ShiftData DEFAULT_SHIFT_DATA = { .initial_spc_pwm = 100, .initial_mpc_pwm = 100, .spc_dec_speed = 5.0, .mpc_dec_speed = 3.0};

typedef struct {
/**
Expand Down
50 changes: 47 additions & 3 deletions src/diag/diag_data.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "diag_data.h"
#include "sensors.h"
#include "solenoids/solenoids.h"

DATA_GEARBOX_SENSORS get_gearbox_sensors() {
DATA_GEARBOX_SENSORS ret = {};
Expand All @@ -8,11 +9,11 @@ DATA_GEARBOX_SENSORS get_gearbox_sensors() {
if (!Sensors::read_input_rpm(&d, false)) {
ret.n2_rpm = 0xFFFF;
ret.n3_rpm = 0xFFFF;
ret.calc_rpm = 0xFFFF;
ret.calculated_rpm = 0xFFFF;
} else {
ret.n2_rpm = d.n2_raw;
ret.n3_rpm = d.n3_raw;
ret.calc_rpm = d.calc_rpm;
ret.calculated_rpm = d.calc_rpm;
}
if(!Sensors::read_atf_temp(&ret.atf_temp_c)) {
ret.atf_temp_c = 0xFFFF;
Expand All @@ -25,6 +26,49 @@ DATA_GEARBOX_SENSORS get_gearbox_sensors() {
} else {
ret.parking_lock = 0xFF;
}
ret.rli = RLI_GEARBOX_SENSORS;
return ret;
}

DATA_SOLENOIDS get_solenoid_data() {
DATA_SOLENOIDS ret = {};

ret.mpc_current = sol_mpc->get_current_estimate();
ret.spc_current = sol_spc->get_current_estimate();
ret.tcc_current = sol_tcc->get_current_estimate();
ret.y3_current = sol_y3->get_current_estimate();
ret.y4_current = sol_y4->get_current_estimate();
ret.y5_current = sol_y5->get_current_estimate();

ret.mpc_pwm = sol_mpc->get_pwm();
ret.spc_pwm = sol_spc->get_pwm();
ret.tcc_pwm = sol_tcc->get_pwm();
ret.y3_pwm = sol_y3->get_pwm();
ret.y4_pwm = sol_y4->get_pwm();
ret.y5_pwm = sol_y5->get_pwm();

return ret;
}

DATA_CANBUS_RX get_rx_can_data(AbstractCan* can_layer) {
DATA_CANBUS_RX ret = {};
uint64_t now = esp_timer_get_time() / 1000;

WheelData t = can_layer->get_rear_left_wheel(now, 250);
ret.left_rear_rpm = t.current_dir == WheelDirection::SignalNotAvaliable ? 0xFFFF : t.double_rpm;
t = can_layer->get_rear_right_wheel(now, 250);
ret.right_rear_rpm = t.current_dir == WheelDirection::SignalNotAvaliable ? 0xFFFF : t.double_rpm;

ret.paddle_position = can_layer->get_paddle_position(now, 250);
ret.pedal_pos = can_layer->get_pedal_value(now, 250);

int torque = 0xFFFF;
torque = can_layer->get_maximum_engine_torque(now, 250);
ret.max_torque = torque == INT_MAX ? 0xFFFF : (torque + 500)*4;
torque = can_layer->get_minimum_engine_torque(now, 250);
ret.min_torque = torque == INT_MAX ? 0xFFFF : (torque + 500)*4;
torque = can_layer->get_static_engine_torque(now, 250);
ret.static_torque = torque == INT_MAX ? 0xFFFF : (torque + 500)*4;
ret.shift_button_pressed = can_layer->get_profile_btn_press(now, 250);
ret.shifter_position = can_layer->get_shifter_position_ewm(now, 250);
return ret;
}
40 changes: 37 additions & 3 deletions src/diag/diag_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __DIAG_DATA_H__

#include <stdint.h>
#include "canbus/can_hal.h"

// Diagnostic data IDs and data structures
// used by the KWP2000 server on the TCM
Expand All @@ -12,19 +13,52 @@
// The following IDs are already taken by the OEM EGS52/53 module
// 0F,30-60,7A,A0,B0,B1,C0-C4,D1

#define RLI_GEARBOX_SENSORS 0x20
#define RLI_GEARBOX_SENSORS 0x20 // Sensor data status
#define RLI_SOLENOID_STATUS 0x21 // Solenoid data status
#define RLI_CAN_DATA_DUMP 0x22 // Gearbox brain logic status

// Gearbox sensor struct
typedef struct {
uint8_t rli; // MUST FOR KWP DEF
uint16_t n2_rpm; // Raw N2 RPM
uint16_t n3_rpm; // Raw N3 RPM
uint16_t calc_rpm; // Calculated input RPM (From N2 and N3)
uint16_t calculated_rpm; // Calculated input RPM (From N2 and N3)
uint16_t v_batt; // Battery voltage (mV)
int atf_temp_c; // ATF Temp (Celcius)
uint8_t parking_lock; // Parking lock (1 for Engaged, 0 for disengaged)
} __attribute__ ((packed)) DATA_GEARBOX_SENSORS;

// Solenoid command struct
typedef struct {
uint16_t spc_pwm;
uint16_t mpc_pwm;
uint16_t tcc_pwm;
uint16_t y3_pwm;
uint16_t y4_pwm;
uint16_t y5_pwm;
uint16_t spc_current;
uint16_t mpc_current;
uint16_t tcc_current;
uint16_t y3_current;
uint16_t y4_current;
uint16_t y5_current;
} __attribute__ ((packed)) DATA_SOLENOIDS;

// Solenoid command struct
typedef struct {
uint8_t pedal_pos;
uint16_t min_torque;
uint16_t max_torque;
uint16_t static_torque;
uint16_t left_rear_rpm;
uint16_t right_rear_rpm;
uint8_t shift_button_pressed;
ShifterPosition shifter_position;
PaddlePosition paddle_position;
} __attribute__ ((packed)) DATA_CANBUS_RX;

DATA_GEARBOX_SENSORS get_gearbox_sensors();
DATA_SOLENOIDS get_solenoid_data();
DATA_CANBUS_RX get_rx_can_data(AbstractCan* can_layer);


#endif // __DIAG_DATA_H__
Loading

0 comments on commit 74c4896

Please sign in to comment.