diff --git a/Core/Inc/dti.h b/Core/Inc/dti.h index 802448ca..79a77e90 100644 --- a/Core/Inc/dti.h +++ b/Core/Inc/dti.h @@ -27,7 +27,7 @@ 0x496 /* Throttle signal, Brake signal, IO, Drive enable */ #define TIRE_DIAMETER 16 /* inches */ -#define GEAR_RATIO 47 / 13.0 /* unitless */ +#define GEAR_RATIO 35 / 13.0 /* unitless */ #define POLE_PAIRS 10 /* unitless */ typedef struct { diff --git a/Core/Inc/emrax.h b/Core/Inc/emrax.h index 10df36c4..3957327c 100644 --- a/Core/Inc/emrax.h +++ b/Core/Inc/emrax.h @@ -18,7 +18,7 @@ #define EMRAX_NOMINAL_VOLTAGE 520 /* V */ #define EMRAX_PEAK_EFFICIENCY 90 /* % */ #define EMRAX_PEAK_POWER 124 /* kW, at 5500 RPM */ -#define EMRAX_PEAK_TORQUE 230 /* Nm */ +#define EMRAX_PEAK_TORQUE 220 /* Nm */ #define EMRAX_CONT_TORQUE 112 /* Nm */ #define EMRAX_LIMITING_SPEED 6500 /* RPM */ #define EMRAX_KV 15.53 diff --git a/Core/Src/pedals.c b/Core/Src/pedals.c index 5c114281..21c46354 100644 --- a/Core/Src/pedals.c +++ b/Core/Src/pedals.c @@ -37,6 +37,9 @@ float torque_limit_percentage = 1.0; #define PEDAL_DIFF_THRESH 30 #define PEDAL_FAULT_TIME 500 /* ms */ +/* Alterante pedal mode */ +//#define POWER_REGRESSION_PEDAL_TORQUE_TRANSFER + static bool brake_state = false; osMutexId_t brake_mutex; @@ -216,6 +219,7 @@ bool calc_bspd_prefault(float accel_val, float brake_val) return motor_disabled; } +#ifndef POWER_REGRESSION_PEDAL_TORQUE_TRANSFER static void linear_accel_to_torque(float accel) { /* Sometimes, the pedal travel jumps to 1% even if it is not pressed. */ @@ -228,6 +232,22 @@ static void linear_accel_to_torque(float accel) dti_set_torque(torque); } +#else +static void power_regression_accel_to_torque(float accel) +{ + /* Sometimes, the pedal travel jumps to 1% even if it is not pressed. */ + if (fabs(accel - 0.01) < 0.001) { + accel = 0; + } + /* map acceleration to torque */ + int16_t torque = + (int16_t)(0.137609 * powf(accel, 1.43068) * MAX_TORQUE); + /* These values came from creating a power regression function intersecting three points: (0,0) (20,10) & (100,100)*/ + + dti_set_torque(torque); +} +#endif + /** * @brief Derate torque target to keep car below the maximum pit/reverse mode speed. * @@ -459,7 +479,11 @@ void vProcessPedals(void *pv_params) handle_endurance(mc, mph, accelerator_value, brake_val); break; case F_PERFORMANCE: +#ifndef POWER_REGRESSION_PEDAL_TORQUE_TRANSFER linear_accel_to_torque(accelerator_value); +#else + power_regression_accel_to_torque(accelerator_value); +#endif break; case F_PIT: handle_pit(mph, accelerator_value);