Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion VCU/firmware/Core/Inc/params/acceleration_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "default_params.h"

static const vcu_parameters_t acceleration_params = { VCU_DEFAULT_PARAMS };
static const vcu_parameters_t acceleration_params = {
VCU_DEFAULT_PARAMS,
.event_mode = 1, \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The backslash \ at the end of the line is unnecessary because this is a standard C struct initialization, not a preprocessor macro definition. Trailing backslashes outside of macros can lead to compiler warnings or unexpected line-splicing behavior if trailing whitespace is present.

    .event_mode = 1,

};

#endif /* ACCELERATION_PARAMS_H */
5 changes: 4 additions & 1 deletion VCU/firmware/Core/Inc/params/autocross_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "default_params.h"

static const vcu_parameters_t autocross_params = { VCU_DEFAULT_PARAMS };
static const vcu_parameters_t autocross_params = {
VCU_DEFAULT_PARAMS,
.event_mode = 3, \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The backslash \ at the end of the line is unnecessary because this is a standard C struct initialization, not a preprocessor macro definition. Trailing backslashes outside of macros can lead to compiler warnings or unexpected line-splicing behavior if trailing whitespace is present.

    .event_mode = 3,

};

#endif /* AUTOCROSS_PARAMS_H */
11 changes: 6 additions & 5 deletions VCU/firmware/Core/Inc/params/default_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

// clang-format off
#define VCU_DEFAULT_PARAMS \
.event_mode = 0, \
.apps = { \
.apps1_min_adc_v = 1.750f, \
.apps1_max_adc_v = 1.520f, \
.apps2_min_adc_v = 0.190f, \
.apps1_min_adc_v = 1.730f, \
.apps1_max_adc_v = 1.500f, \
.apps2_min_adc_v = 0.197f, \
.apps2_max_adc_v = -0.020f, \
.implaus_debounce_time_ms = 100u, \
.max_allowable_diff = 0.15f, \
Expand Down Expand Up @@ -67,7 +68,7 @@
/* apps= 0.9 */ 0.90f, \
/* apps= 1.0 */ 1.00f, \
}, \
.pedal_curve_exponent = 2.0f, \
.pedal_curve_exponent = 1.5f, \
.low_cell_derate_start_v = 3.2f, \
.low_cell_cutoff_v = 2.8f, \
}, \
Expand All @@ -87,7 +88,7 @@
.max_soe_cell_voltage = 4.2f, \
}, \
.regen_linelock = { \
.disable = false, \
.disable = true, \
.pressure_only_test_mode = false, \
.dc_bus_current_regen_is_negative = true, \
.rear_pressure_zero_torque_psi = 0.0f, \
Expand Down
8 changes: 7 additions & 1 deletion VCU/firmware/Core/Inc/params/endurance_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

#include "default_params.h"

static const vcu_parameters_t endurance_params = { VCU_DEFAULT_PARAMS };
static const vcu_parameters_t endurance_params = {
VCU_DEFAULT_PARAMS,
.regen_linelock = { \
.disable = true, \
}, \
.event_mode = 4, \
Comment on lines +8 to +35

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

There are two major issues here:

  1. C99 Struct Overriding: Initializing .regen_linelock = { ... } overrides the entire regen_linelock sub-struct. This means all other fields of regen_linelock (such as pack_current_limit_a, pack_terminal_voltage_limit_v, etc.) will be implicitly initialized to 0. To override only the disable field, you must use the nested designator .regen_linelock.disable.
  2. Logic Error: The PR title is "regen off except for endurance". Since regen is disabled by default in default_params.h (.disable = true), endurance mode should enable it by setting .regen_linelock.disable = false. Setting it to true here keeps it disabled.
    .regen_linelock.disable = false,
    .event_mode = 4,

};

#endif /* ENDURANCE_PARAMS_H */
5 changes: 3 additions & 2 deletions VCU/firmware/Core/Inc/params/skidpad_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ static const vcu_parameters_t skidpad_params = {
/* apps= 0.8 */ 0.70f,
/* apps= 0.9 */ 0.70f,
/* apps= 1.0 */ 0.70f,
},
.torque_map.pedal_curve_exponent = 1.0f,
}, \
.torque_map.pedal_curve_exponent = 1.0f, \
.event_mode = 2, \
Comment on lines +21 to +23

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The backslashes \ at the end of these lines are unnecessary because this is a standard C struct initialization, not a preprocessor macro definition. Trailing backslashes outside of macros can lead to compiler warnings or unexpected line-splicing behavior if trailing whitespace is present.

    },
    .torque_map.pedal_curve_exponent = 1.0f,
    .event_mode = 2,

};
// clang-format on

Expand Down
70 changes: 35 additions & 35 deletions VCU/firmware/Core/Src/app_freertos.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const osThreadAttr_t controlTask_attributes = {

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define SELECTED_PARAMS autocross_params
#define SELECTED_PARAMS endurance_params
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
Expand All @@ -97,13 +97,13 @@ const osThreadAttr_t controlTask_attributes = {

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

static vcu_parameters_t s_params;
static vcu_model_context_t ctx = {0};

/* USER CODE END Variables */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */
static vcu_parameters_t s_params;
static vcu_model_context_t ctx = {0};
/* USER CODE END Variables */
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
Expand Down Expand Up @@ -346,33 +346,33 @@ void StartControlTask(void *argument) {
in.bse1_raw = ((float)adc2_dma_buf[0] * ADC_BSE_SCALE_V) / ADC_MAX_VAL;
in.bse2_raw = ((float)adc2_dma_buf[1] * ADC_BSE_SCALE_V) / ADC_MAX_VAL;

in.drive_switch = is_drive_switch_pressed();

in.contactors_closed = hvc_tractive_ready();
inverter_voltages_t inverter_voltages = vcu_can_get_inverter_voltages();
inverter_currents_t inverter_currents = vcu_can_get_inverter_currents();
vcu_battery_pack_status_t pack_status = vcu_can_get_battery_pack_status();

in.motor_speed_rpm = fabsf(vcu_can_get_motor_speed_rpm());
in.motor_speed_valid = vcu_can_is_motor_speed_valid();
in.min_cell_voltage_v = vcu_can_get_min_cell_voltage_v();
in.max_cell_voltage_v = vcu_can_get_max_cell_voltage_v();
if (in.min_cell_voltage_v <= 0.0f) {
in.min_cell_voltage_v = s_params.torque_map.low_cell_derate_start_v;
}
if (in.max_cell_voltage_v <= 0.0f) {
in.max_cell_voltage_v = in.min_cell_voltage_v;
}
in.battery_voltage_v = inverter_voltages.dc_bus;
in.battery_current_a = inverter_currents.dc_bus;
in.battery_soc_pct = pack_status.state_of_charge_pct;
in.min_cell_temp_c = pack_status.min_cell_temp_c;
in.max_cell_temp_c = pack_status.max_cell_temp_c;
in.inverter_voltage_valid = vcu_can_is_inverter_voltage_valid();
in.inverter_current_valid = vcu_can_is_inverter_current_valid();
in.battery_pack_status_valid = pack_status.valid;

// Run control model
in.drive_switch = is_drive_switch_pressed();
in.contactors_closed = hvc_tractive_ready();
inverter_voltages_t inverter_voltages = vcu_can_get_inverter_voltages();
inverter_currents_t inverter_currents = vcu_can_get_inverter_currents();
vcu_battery_pack_status_t pack_status = vcu_can_get_battery_pack_status();
in.motor_speed_rpm = fabsf(vcu_can_get_motor_speed_rpm());
in.motor_speed_valid = vcu_can_is_motor_speed_valid();
in.min_cell_voltage_v = vcu_can_get_min_cell_voltage_v();
in.max_cell_voltage_v = vcu_can_get_max_cell_voltage_v();
if (in.min_cell_voltage_v <= 0.0f) {
in.min_cell_voltage_v = s_params.torque_map.low_cell_derate_start_v;
}
if (in.max_cell_voltage_v <= 0.0f) {
in.max_cell_voltage_v = in.min_cell_voltage_v;
}
in.battery_voltage_v = inverter_voltages.dc_bus;
in.battery_current_a = inverter_currents.dc_bus;
in.battery_soc_pct = pack_status.state_of_charge_pct;
in.min_cell_temp_c = pack_status.min_cell_temp_c;
in.max_cell_temp_c = pack_status.max_cell_temp_c;
in.inverter_voltage_valid = vcu_can_is_inverter_voltage_valid();
in.inverter_current_valid = vcu_can_is_inverter_current_valid();
in.battery_pack_status_valid = pack_status.valid;
// Run control model
vcu_model_step(&ctx, &in, &out, dt_ms);

vcu_can_set_model_inputs(&in);
Expand Down
3 changes: 3 additions & 0 deletions VCU/model/inc/vcu_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ extern "C" {
#include <stdint.h>

typedef struct {

uint8_t event_mode; // 0 = unassigned, 1 = acceleration, 2 = skidpad, 3 = autocross, 4 = endurance

float brake_enable_threshold;
uint16_t buzzer_duration_ms;

Expand Down
Loading