From 083f6e8d4943bd42057d3d3a2b076beb6ea70b7d Mon Sep 17 00:00:00 2001 From: Myers-Ty Date: Fri, 10 Jan 2025 11:54:13 -0500 Subject: [PATCH 1/8] torque debug ifdef --- Core/Src/nero.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Core/Src/nero.c b/Core/Src/nero.c index 97de4995..de12d4bb 100644 --- a/Core/Src/nero.c +++ b/Core/Src/nero.c @@ -11,6 +11,8 @@ #include "pedals.h" #include "string.h" +//#define TORQUE_DEBUG + static int8_t mph = 0; void send_nero_msg() @@ -41,6 +43,12 @@ void send_nero_msg() memcpy(&msg.data, &nero_data, sizeof(nero_data)); + #ifdef TORQUE_DEBUG + nero_data.tsms = 1; + nero_data.nero_index = 1; /* Used for selecting drive mode */ + dti_set_current(0); + #endif + /* Send CAN message */ queue_can_msg(msg); } From 46da9de621afd2f56e16d32455fe615df11214f8 Mon Sep 17 00:00:00 2001 From: Myers-Ty Date: Fri, 10 Jan 2025 12:01:41 -0500 Subject: [PATCH 2/8] formatting --- Core/Src/nero.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Core/Src/nero.c b/Core/Src/nero.c index de12d4bb..1c0f7e48 100644 --- a/Core/Src/nero.c +++ b/Core/Src/nero.c @@ -1,17 +1,17 @@ #include "nero.h" -#include "stdint.h" -#include "stdbool.h" -#include "can_handler.h" -#include "state_machine.h" -#include "queues.h" #include "c_utils.h" -#include "stdio.h" +#include "can_handler.h" #include "cerberus_conf.h" #include "monitor.h" #include "pedals.h" +#include "queues.h" +#include "state_machine.h" +#include "stdbool.h" +#include "stdint.h" +#include "stdio.h" #include "string.h" -//#define TORQUE_DEBUG +// #define TORQUE_DEBUG static int8_t mph = 0; @@ -25,7 +25,8 @@ void send_nero_msg() uint8_t torque_lim_percentage; } nero_data; - /* Since the screen on NERO relies on the NERO index, and reverse and pit have the same index, reverse gets a special index */ + /* Since the screen on NERO relies on the NERO index, and reverse and pit have the same index, + * reverse gets a special index */ if (get_func_state() == REVERSE) { nero_data.nero_index = 255; } else { @@ -33,21 +34,20 @@ void send_nero_msg() } nero_data.home_mode = (uint8_t)get_nero_state().home_mode; - nero_data.mph = mph; - nero_data.tsms = (uint8_t)get_tsms(); + nero_data.mph = mph; + nero_data.tsms = (uint8_t)get_tsms(); /* Percentage from 0 - 1, multiplied by 100 */ - nero_data.torque_lim_percentage = - (uint8_t)(get_torque_limit_percentage() * 100); + nero_data.torque_lim_percentage = (uint8_t)(get_torque_limit_percentage() * 100); can_msg_t msg = { .id = 0x501, .len = sizeof(nero_data) }; memcpy(&msg.data, &nero_data, sizeof(nero_data)); - #ifdef TORQUE_DEBUG - nero_data.tsms = 1; - nero_data.nero_index = 1; /* Used for selecting drive mode */ - dti_set_current(0); - #endif +#ifdef TORQUE_DEBUG + nero_data.tsms = 1; + nero_data.nero_index = 1; /* Used for selecting drive mode */ + dti_set_current(0); +#endif /* Send CAN message */ queue_can_msg(msg); From 4a52856363a1cbfce6493a0ea7b5f1b55a544445 Mon Sep 17 00:00:00 2001 From: Myers-Ty Date: Fri, 10 Jan 2025 13:02:46 -0500 Subject: [PATCH 3/8] formatting --- Core/Src/nero.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Core/Src/nero.c b/Core/Src/nero.c index 1c0f7e48..07abb339 100644 --- a/Core/Src/nero.c +++ b/Core/Src/nero.c @@ -34,21 +34,22 @@ void send_nero_msg() } nero_data.home_mode = (uint8_t)get_nero_state().home_mode; - nero_data.mph = mph; - nero_data.tsms = (uint8_t)get_tsms(); + nero_data.mph = mph; + nero_data.tsms = (uint8_t)get_tsms(); /* Percentage from 0 - 1, multiplied by 100 */ - nero_data.torque_lim_percentage = (uint8_t)(get_torque_limit_percentage() * 100); - - can_msg_t msg = { .id = 0x501, .len = sizeof(nero_data) }; - - memcpy(&msg.data, &nero_data, sizeof(nero_data)); + nero_data.torque_lim_percentage = + (uint8_t)(get_torque_limit_percentage() * 100); #ifdef TORQUE_DEBUG - nero_data.tsms = 1; + nero_data.tsms = 1; nero_data.nero_index = 1; /* Used for selecting drive mode */ dti_set_current(0); #endif + can_msg_t msg = { .id = 0x501, .len = sizeof(nero_data) }; + + memcpy(&msg.data, &nero_data, sizeof(nero_data)); + /* Send CAN message */ queue_can_msg(msg); } From d93c27ab98bf7f77a476e56437221500887ef74c Mon Sep 17 00:00:00 2001 From: Myers-Ty Date: Sun, 12 Jan 2025 18:36:57 -0500 Subject: [PATCH 4/8] tsms override --- Core/Src/dti.c | 7 +++++++ Core/Src/nero.c | 6 ------ Core/Src/state_machine.c | 5 ++++- Makefile | 2 ++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Core/Src/dti.c b/Core/Src/dti.c index 8a65690d..5b0304c1 100644 --- a/Core/Src/dti.c +++ b/Core/Src/dti.c @@ -97,7 +97,14 @@ void dti_set_regen(uint16_t current_target) void dti_set_current(int16_t current) { can_msg_t msg = { .id = 0x036, .len = 2, .data = { 0 } }; + +#ifdef TSMS_OVERRIDE + dti_set_drive_enable(false); + printf("%d/n", current); +#else dti_set_drive_enable(true); +#endif + /* Send CAN message in big endian format */ //endian_swap(¤t, sizeof(current)); diff --git a/Core/Src/nero.c b/Core/Src/nero.c index 07abb339..4a40bbef 100644 --- a/Core/Src/nero.c +++ b/Core/Src/nero.c @@ -40,12 +40,6 @@ void send_nero_msg() nero_data.torque_lim_percentage = (uint8_t)(get_torque_limit_percentage() * 100); -#ifdef TORQUE_DEBUG - nero_data.tsms = 1; - nero_data.nero_index = 1; /* Used for selecting drive mode */ - dti_set_current(0); -#endif - can_msg_t msg = { .id = 0x501, .len = sizeof(nero_data) }; memcpy(&msg.data, &nero_data, sizeof(nero_data)); diff --git a/Core/Src/state_machine.c b/Core/Src/state_machine.c index 64849f23..91018c02 100644 --- a/Core/Src/state_machine.c +++ b/Core/Src/state_machine.c @@ -110,8 +110,11 @@ static int transition_functional_state(func_state_t new_state, pdu_t *pdu, // Do Nothing break; } - +#ifdef TSMS_OVERRIDE + cerberus_state.functional = READY; +#else cerberus_state.functional = new_state; +#endif return 0; } diff --git a/Makefile b/Makefile index 2d324c85..2017f22b 100644 --- a/Makefile +++ b/Makefile @@ -198,6 +198,8 @@ LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BU # default action: build all all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin +# motor Test +CFLAGS += -DTSMS_OVERRIDE ####################################### # build the application From 66d9a5cd47fce97b92a4b946390f9551bd7d0d7b Mon Sep 17 00:00:00 2001 From: Myers-Ty Date: Sun, 12 Jan 2025 18:47:42 -0500 Subject: [PATCH 5/8] fixed tsms override --- Core/Src/state_machine.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Core/Src/state_machine.c b/Core/Src/state_machine.c index 91018c02..3644fe02 100644 --- a/Core/Src/state_machine.c +++ b/Core/Src/state_machine.c @@ -78,9 +78,15 @@ static int transition_functional_state(func_state_t new_state, pdu_t *pdu, if (dti_get_mph(mc) > 1) return 2; /* Only turn on motor if brakes engaged and tsms is on */ +#ifdef TSMS_OVERRIDE + if (!get_brake_state()) { + return 3; + } +#else if (!get_brake_state() || !get_tsms()) { return 3; } +#endif osThreadFlagsSet(rtds_thread, SOUND_RTDS_FLAG); } @@ -110,11 +116,9 @@ static int transition_functional_state(func_state_t new_state, pdu_t *pdu, // Do Nothing break; } -#ifdef TSMS_OVERRIDE - cerberus_state.functional = READY; -#else + cerberus_state.functional = new_state; -#endif + return 0; } From 9fc35f96228990eea489fe46b3be8fea1c787683 Mon Sep 17 00:00:00 2001 From: Myers-Ty Date: Mon, 13 Jan 2025 11:48:15 -0500 Subject: [PATCH 6/8] Default off --- Core/Src/dti.c | 1 - Makefile | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/Src/dti.c b/Core/Src/dti.c index 5b0304c1..b6a70c30 100644 --- a/Core/Src/dti.c +++ b/Core/Src/dti.c @@ -100,7 +100,6 @@ void dti_set_current(int16_t current) #ifdef TSMS_OVERRIDE dti_set_drive_enable(false); - printf("%d/n", current); #else dti_set_drive_enable(true); #endif diff --git a/Makefile b/Makefile index 2017f22b..d77285dd 100644 --- a/Makefile +++ b/Makefile @@ -199,7 +199,7 @@ LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BU all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin # motor Test -CFLAGS += -DTSMS_OVERRIDE +#CFLAGS += -DTSMS_OVERRIDE ####################################### # build the application From 9b571affaee2badc670e35a767061da6514e1716 Mon Sep 17 00:00:00 2001 From: Myers-Ty Date: Mon, 13 Jan 2025 14:23:34 -0500 Subject: [PATCH 7/8] new pedal torque transfer option --- Core/Inc/dti.h | 2 +- Core/Inc/emrax.h | 2 +- Core/Src/pedals.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) 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..32461287 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,21 @@ 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); + + dti_set_torque(torque); +} +#endif + /** * @brief Derate torque target to keep car below the maximum pit/reverse mode speed. * @@ -371,8 +390,12 @@ void handle_endurance(dti_t *mc, float mph, float accel_val, float brake_val) if (brake_val > 650 && (mph * 1.609) > 5) { brake_pedal_regen(brake_val); } else { - // accelerating, limit torque +// accelerating, limit torque +#ifndef POWER_REGRESSION_PEDAL_TORQUE_TRANSFER linear_accel_to_torque(accel_val, torque); +#else + power_regression_accel_to_torque(accel_val, torque); +#endif } #else /* Factor for converting MPH to KMH */ @@ -459,7 +482,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); From f716b4c8d491d81f0e45232cfe6ba4287adc3f9b Mon Sep 17 00:00:00 2001 From: Myers-Ty Date: Mon, 13 Jan 2025 18:24:14 -0500 Subject: [PATCH 8/8] removed option for break regen --- Core/Src/pedals.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Core/Src/pedals.c b/Core/Src/pedals.c index 32461287..21c46354 100644 --- a/Core/Src/pedals.c +++ b/Core/Src/pedals.c @@ -242,6 +242,7 @@ static void power_regression_accel_to_torque(float accel) /* 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); } @@ -390,12 +391,8 @@ void handle_endurance(dti_t *mc, float mph, float accel_val, float brake_val) if (brake_val > 650 && (mph * 1.609) > 5) { brake_pedal_regen(brake_val); } else { -// accelerating, limit torque -#ifndef POWER_REGRESSION_PEDAL_TORQUE_TRANSFER + // accelerating, limit torque linear_accel_to_torque(accel_val, torque); -#else - power_regression_accel_to_torque(accel_val, torque); -#endif } #else /* Factor for converting MPH to KMH */