![]() |
Midnight Sun Firmware
|
Front Controller Board Firmware. More...
Classes | |
| struct | AccelPedalCalibrationData |
| struct | AccelPedalStorage |
| struct | BrakePedalCalibrationData |
| struct | BrakePedalStorage |
| struct | CruiseControlStorage |
| struct | FrontControllerConfig |
| Front Controller configuration data. More... | |
| struct | FrontControllerStorage |
| Front Controller storage. More... | |
| struct | OpdStorage |
| struct | PowerManagerStorage |
| struct | OutputGroupDef |
| struct | Ws22MotorControlData |
| Motor control command data structure. More... | |
| struct | Ws22MotorTelemetryData |
| Motor status and telemetry data structure. More... | |
| struct | Ws22MotorCanStorage |
| WS22 motor CAN interface storage structure. More... | |
Macros | |
| #define | CC_MIN_THRESHOLD 0.5f |
| #define | CC_KP 0.00000005 |
| #define | ACCELERATION_LIMIT_M_S2 1 |
| #define | ACCELERATION_LIMIT_KM_HS ACCELERATION_LIMIT_M_S2 * 3.6 |
| #define | ACCELERATION_LIMIT_PER_1000HZ_CYCLE ACCELERATION_LIMIT_KM_HS / 1000 |
| #define | CURRENT_STEP_LIMIT 0.0001 |
| #define | FRONT_CONTROLLER_ACCEL_INPUT_DEADZONE 0.02f |
| Front controller pedal set to 2% deadzone | |
| #define | FRONT_CONTROLLER_ACCEL_REMAP_MIN 0.10f |
| Front controller pedal is remapped from 0 - 1 to 0.1 to 1. | |
| #define | FRONT_CONTROLLER_ACCEL_CURVE_EXPONENT 2.0f |
| Front controller pedal exponent for non-linear feel. | |
| #define | FRONT_CONTROLLER_ACCEL_LPF_ALPHA 0.25f |
| Front controller accel pedal alpha value for low-pass filtering. | |
| #define | FRONT_CONTROLLER_BRAKE_LPF_ALPHA 0.50f |
| Front controller brake pedal alpha value for low-pass filtering. | |
| #define | FRONT_CONTROLLER_BRAKE_INPUT_DEADZONE 0.01f |
| Front controller brake pedal set to 1% deadzone | |
| #define | WS22_CONTROLLER_MAX_VELOCITY 12000 |
| Max velocity value used for ws22 motor controllers. | |
| #define | MAX_VEHICLE_SPEED_KPH 50 |
| Max speed of vehicle in KPH. | |
| #define | FRONT_CONTROLLER_GPIO_DEF(PORT, PIN) { .port = GPIO_PORT_##PORT, .pin = PIN } |
| #define | GPIO_FRONT_CONTROLLER_CAN_RX FRONT_CONTROLLER_GPIO_DEF(B, 8) |
| Front Controller CAN RX Port. | |
| #define | GPIO_FRONT_CONTROLLER_CAN_TX FRONT_CONTROLLER_GPIO_DEF(B, 9) |
| Front Controller CAN TX Port. | |
| #define | GPIO_FRONT_CONTROLLER_LEFT_SIG_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(B, 12) |
| Front Controller left signal load switch enable. | |
| #define | GPIO_FRONT_CONTROLLER_RIGHT_SIG_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(B, 13) |
| Front Controller right signal load switch enable. | |
| #define | GPIO_FRONT_CONTROLLER_BRAKE_LIGHT_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(A, 10) |
| Front Controller brake light load switch enable. | |
| #define | GPIO_FRONT_CONTROLLER_BPS_LIGHT_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(A, 9) |
| Front Controller battery-protection-system light load switch enable. | |
| #define | GPIO_FRONT_CONTROLLER_DRIVER_FAN_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(B, 14) |
| Front Controller driver fan load switch enable. | |
| #define | GPIO_FRONT_CONTROLLER_REV_CAM_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(B, 15) |
| Front Controller reverse camera load switch enable. | |
| #define | GPIO_FRONT_CONTROLLER_TELEM_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(A, 8) |
| Front Controller telemetry load switch enable. | |
| #define | GPIO_FRONT_CONTROLLER_STEERING_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(B, 11) |
| Front Controller steering load switch enable. | |
| #define | GPIO_FRONT_CONTROLLER_HORN_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(A, 11) |
| Front Controller horn load switch enable. | |
| #define | GPIO_FRONT_CONTROLLER_SPARE_1_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(A, 12) |
| Front Controller spare 12V load switch enable. | |
| #define | GPIO_FRONT_CONTROLLER_MUX_SEL_2 FRONT_CONTROLLER_GPIO_DEF(A, 6) |
| Front Controller current sense mux select 0. | |
| #define | GPIO_FRONT_CONTROLLER_MUX_SEL_3 FRONT_CONTROLLER_GPIO_DEF(A, 7) |
| Front Controller current sense mux select 1. | |
| #define | GPIO_FRONT_CONTROLLER_MUX_SEL_0 FRONT_CONTROLLER_GPIO_DEF(B, 1) |
| Front Controller current sense mux select 2. | |
| #define | GPIO_FRONT_CONTROLLER_MUX_SEL_1 FRONT_CONTROLLER_GPIO_DEF(B, 2) |
| Front Controller current sense mux select 3. | |
| #define | GPIO_FRONT_CONTROLLER_MUX_OUTPUT FRONT_CONTROLLER_GPIO_DEF(B, 0) |
| Front Controller current sense mux input. | |
| #define | GPIO_FRONT_CONTROLLER_ACCEL_PEDAL FRONT_CONTROLLER_GPIO_DEF(A, 3) |
| Front Controller accelerator pedal input. | |
| #define | GPIO_FRONT_CONTROLLER_BRAKE_PEDAL FRONT_CONTROLLER_GPIO_DEF(A, 5) |
| Front Controller brake pedal input. | |
| #define | GPIO_FRONT_CONTROLLER_BOARD_LED FRONT_CONTROLLER_GPIO_DEF(B, 10) |
| Front Controller board LED. | |
| #define | VEL_TO_RPM_RATIO 0.57147 |
| #define | WS22_CAN_BASE_CONTROL 0x500U |
| #define | WS22_CAN_BASE_STATUS 0x80U |
| #define | WS22_CAN_ID_DRIVE_CMD (WS22_CAN_BASE_CONTROL + 0x01U) |
| #define | WS22_CAN_ID_STATUS_INFO (WS22_CAN_BASE_STATUS + 0x01U) |
| #define | WS22_CAN_ID_BUS_MEASUREMENT (WS22_CAN_BASE_STATUS + 0x02U) |
| #define | WS22_CAN_ID_VELOCITY_MEASUREMENT (WS22_CAN_BASE_STATUS + 0x03U) |
| #define | WS22_CAN_ID_PHASE_CURRENT (WS22_CAN_BASE_STATUS + 0x04U) |
| #define | WS22_CAN_ID_MOTOR_VOLTAGE (WS22_CAN_BASE_STATUS + 0x05U) |
| #define | WS22_CAN_ID_MOTOR_CURRENT (WS22_CAN_BASE_STATUS + 0x06U) |
| #define | WS22_CAN_ID_MOTOR_BACK_EMF (WS22_CAN_BASE_STATUS + 0x07U) |
| #define | WS22_CAN_ID_RAIL_15V (WS22_CAN_BASE_STATUS + 0x08U) |
| #define | WS22_CAN_ID_TEMPERATURE (WS22_CAN_BASE_STATUS + 0x0BU) |
Typedefs | |
| typedef struct AccelPedalStorage | AccelPedalStorage |
| typedef struct BrakePedalStorage | BrakePedalStorage |
| typedef struct CruiseControlStorage | CruiseControlStorage |
| typedef struct OpdStorage | OpdStorage |
| typedef enum PtsRelationType | PtsRelationType |
| typedef enum CurveType | CurveType |
| typedef struct PowerManagerStorage | PowerManagerStorage |
| typedef struct Ws22MotorCanStorage | Ws22MotorCanStorage |
| WS22 motor CAN interface storage structure. | |
Enumerations | |
| enum | FrontControllerState { FRONT_CONTROLLER_STATE_IDLE = 0 , FRONT_CONTROLLER_STATE_ENGAGED , FRONT_CONTROLLER_STATE_FAULT , NUM_FRONT_CONTROLLER_STATES } |
| enum | FrontControllerEvent { FRONT_CONTROLLER_EVENT_NONE = 0 , FRONT_CONTROLLER_EVENT_IDLE_REQUEST , FRONT_CONTROLLER_EVENT_DRIVE_REQUEST , FRONT_CONTROLLER_EVENT_FAULT , FRONT_CONTROLLER_EVENT_RESET } |
| enum | PtsRelationType { PTS_TYPE_LINEAR , PTS_TYPE_EXPONENTIAL , PTS_TYPE_QUADRATIC } |
| enum | CurveType { CURVE_TYPE_LINEAR , CURVE_TYPE_EXPONENTIAL , CURVE_TYPE_QUADRATIC } |
| enum | OutputId { HORN = 0 , SPARE_1 , BRAKE_LIGHT , BPS_LIGHT , TELEM , REV_CAM , DRIVER_FAN , RIGHT_SIG , STEERING , LEFT_SIG , NUM_OUTPUTS } |
| Power outputs. More... | |
| enum | OutputGroup { OUTPUT_GROUP_ALL = 0 , OUTPUT_GROUP_ACTIVE , OUTPUT_GROUP_LEFT_LIGHTS , OUTPUT_GROUP_RIGHT_LIGHTS , OUTPUT_GROUP_HAZARD_LIGHTS , OUTPUT_GROUP_BPS_LIGHTS , OUTPUT_GROUP_BRAKE_LIGHTS , OUTPUT_GROUP_HORN , NUM_OUTPUT_GROUPS } |
| Power output groups. | |
Functions | |
| StatusCode | accel_pedal_run () |
| Reads the pedal percentage and applies deadzone and filtering before updating the storage. More... | |
| StatusCode | accel_pedal_init (FrontControllerStorage *storage) |
| Initializes the acceleration pedal hardware interface loads calibration data from memory. More... | |
| StatusCode | brake_pedal_run () |
| Reads the pedal percentage and applies deadzone and filtering before updating the brake state. More... | |
| StatusCode | brake_pedal_init (FrontControllerStorage *storage) |
| Initializes the brake pedal hardware interface loads calibration data from memory. More... | |
| StatusCode | cruise_control_run () |
| Runs one cruise control calculation cycle. Called within motor_can.c when cruise control mode is on. More... | |
| StatusCode | cruise_control_init (FrontControllerStorage *storage) |
| Initializes the cruise control module. More... | |
| StatusCode | front_controller_init (FrontControllerStorage *storage, FrontControllerConfig *config) |
| Initialize the front controller interface. More... | |
| StatusCode | front_controller_state_manager_init (FrontControllerStorage *storage) |
| Initialize the state machine. More... | |
| StatusCode | front_controller_state_manager_step (FrontControllerEvent event) |
| Advance the state machine based on inputs/events. More... | |
| FrontControllerState | front_controller_state_manager_get_state (void) |
| Get current state. More... | |
| StatusCode | front_controller_update_state_manager_medium_cycle () |
| Update the state/set load switches based on information recieved from CAN (medium cycle). More... | |
| StatusCode | horn_init () |
| Initializes the horn pin. More... | |
| StatusCode | motor_can_update_target_current_velocity () |
| Updates target current and velocity of motors based on drive state. More... | |
| StatusCode | motor_can_init (FrontControllerStorage *storage) |
| Initializes the motor can, loads front controller storage data. More... | |
| StatusCode | motor_can_get_current_state (VehicleDriveState *current_state) |
| retrieve current vehicle drive state | |
| char * | motor_can_get_current_state_str () |
| print a state as a string | |
| StatusCode | opd_calculate_handler (float pedal_percentage, PtsRelationType relation_type, float *calculated_reading, CurveType curve_type) |
| handler for opd_calculate command, runs either linear or quadratic calculation based on CurveType enum | |
| StatusCode | opd_linear_calculate (float pedal_percentage, PtsRelationType relation_type, float *calculated_reading) |
| Perform linear OPD calculation. More... | |
| StatusCode | opd_quadratic_calculate (float pedal_percentage, PtsRelationType relation_type, float *calculated_reading) |
| Perform quadratic OPD calculation. | |
| StatusCode | opd_run () |
| Reads the pedal percentage from AccelPedalStorage and saves an adjusted acceleration percentage to front controller based on OPD algorithm. More... | |
| StatusCode | opd_init (FrontControllerStorage *storage) |
| Initializes the opd, loads front controller storage. More... | |
| StatusCode | pedal_calib_read (FrontControllerStorage *storage) |
| Reads pedal calibration data. More... | |
| StatusCode | power_manager_init (FrontControllerStorage *storage) |
| Initialize all the GPIO pins. More... | |
| StatusCode | power_manager_set_output_group (OutputGroup group, bool enable) |
| Set an output group as active or inactive. | |
| StatusCode | power_manager_toggle_output_group (OutputGroup group) |
| Toggle an output group. | |
| StatusCode | power_manager_run_current_sense (OutputGroup group) |
| Run current sensing. | |
| StatusCode | ws22_motor_can_init (FrontControllerStorage *storage) |
| Initialize the WS22 motor CAN interface. More... | |
| StatusCode | ws22_motor_can_set_current (float current) |
| Set motor control current command. More... | |
| StatusCode | ws22_motor_can_set_velocity (float velocity) |
| Set motor control velocity command. More... | |
| StatusCode | ws22_motor_can_transmit_drive_command (void) |
| Build and transmit motor drive command. More... | |
| StatusCode | ws22_motor_can_process_rx (CanMessage *msg) |
| Process received CAN message for motor controller. More... | |
| Ws22MotorControlData * | ws22_motor_can_get_control_data (void) |
| Get current motor control data. More... | |
| Ws22MotorTelemetryData * | ws22_motor_can_get_telemetry_data (void) |
| Get current motor telemetry data. More... | |
Front Controller Board Firmware.
| #define WS22_CAN_BASE_CONTROL 0x500U |
Base address for control messages
| #define WS22_CAN_BASE_STATUS 0x80U |
Base address for status messages
| enum FrontControllerState |
| enum OutputId |
Power outputs.
The order of this enum matters. It matches the schematic mux indices
| StatusCode accel_pedal_init | ( | FrontControllerStorage * | storage | ) |
Initializes the acceleration pedal hardware interface loads calibration data from memory.
| StatusCode accel_pedal_run | ( | ) |
Reads the pedal percentage and applies deadzone and filtering before updating the storage.
Convert ADC Reading to readable voltage by normalizing with calibration data and dividing to get percentage press. Negatives and > 100 values will be clamped
| StatusCode brake_pedal_init | ( | FrontControllerStorage * | storage | ) |
Initializes the brake pedal hardware interface loads calibration data from memory.
| StatusCode brake_pedal_run | ( | ) |
Reads the pedal percentage and applies deadzone and filtering before updating the brake state.
| StatusCode cruise_control_init | ( | FrontControllerStorage * | storage | ) |
Initializes the cruise control module.
| StatusCode cruise_control_run | ( | ) |
Runs one cruise control calculation cycle. Called within motor_can.c when cruise control mode is on.
Perform PID calculations on current and target motor velocity...
Notes: eI must be reset on any pedal action
| StatusCode front_controller_init | ( | FrontControllerStorage * | storage, |
| FrontControllerConfig * | config | ||
| ) |
Initialize the front controller interface.
| storage | Pointer to the front controller storage |
| config | Pointer to the front controller config |
| FrontControllerState front_controller_state_manager_get_state | ( | void | ) |
Get current state.
| StatusCode front_controller_state_manager_init | ( | FrontControllerStorage * | storage | ) |
Initialize the state machine.
| storage | Pointer to the front controller storage |
| StatusCode front_controller_state_manager_step | ( | FrontControllerEvent | event | ) |
Advance the state machine based on inputs/events.
| event | The triggering event |
| StatusCode front_controller_update_state_manager_medium_cycle | ( | ) |
Update the state/set load switches based on information recieved from CAN (medium cycle).
| StatusCode horn_init | ( | ) |
Initializes the horn pin.
| StatusCode motor_can_init | ( | FrontControllerStorage * | storage | ) |
Initializes the motor can, loads front controller storage data.
| StatusCode motor_can_update_target_current_velocity | ( | ) |
Updates target current and velocity of motors based on drive state.
| StatusCode opd_init | ( | FrontControllerStorage * | storage | ) |
Initializes the opd, loads front controller storage.
| StatusCode opd_linear_calculate | ( | float | pedal_percentage, |
| PtsRelationType | relation_type, | ||
| float * | calculated_reading | ||
| ) |
Perform linear OPD calculation.
Linearly reduce regenerative braking when it's within a certain delta of the max cell voltage
| StatusCode opd_run | ( | ) |
Reads the pedal percentage from AccelPedalStorage and saves an adjusted acceleration percentage to front controller based on OPD algorithm.
| StatusCode pedal_calib_read | ( | FrontControllerStorage * | storage | ) |
Reads pedal calibration data.
| storage | Pointer to the front controller storage |
| StatusCode power_manager_init | ( | FrontControllerStorage * | storage | ) |
Initialize all the GPIO pins.
| storage | Pointer to the front controller storage |
| Ws22MotorControlData * ws22_motor_can_get_control_data | ( | void | ) |
Get current motor control data.
| Ws22MotorTelemetryData * ws22_motor_can_get_telemetry_data | ( | void | ) |
Get current motor telemetry data.
| StatusCode ws22_motor_can_init | ( | FrontControllerStorage * | storage | ) |
Initialize the WS22 motor CAN interface.
| storage | Pointer to Front controller storage structure |
| StatusCode ws22_motor_can_process_rx | ( | CanMessage * | msg | ) |
Process received CAN message for motor controller.
| msg | Pointer to received CAN message |
| StatusCode ws22_motor_can_set_current | ( | float | current | ) |
Set motor control current command.
| current | Motor current command (0.0 to 1.0) |
| StatusCode ws22_motor_can_set_velocity | ( | float | velocity | ) |
Set motor control velocity command.
| velocity | Motor velocity command (rpm) |
| StatusCode ws22_motor_can_transmit_drive_command | ( | void | ) |
Build and transmit motor drive command.