![]() |
Midnight Sun Firmware
|
Front Controller Board Firmware. More...
Classes | |
| struct | AccelPedalCalibrationData |
| struct | AccelPedalStorage |
| struct | BrakePedalCalibrationData |
| struct | BrakePedalStorage |
| 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 | 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 pedal alpha value for low-pass filtering. | |
| #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 | FRONT_CONTROLLER_CAN_RX FRONT_CONTROLLER_GPIO_DEF(B, 8) |
| Front Controller CAN RX Port. | |
| #define | FRONT_CONTROLLER_CAN_TX FRONT_CONTROLLER_GPIO_DEF(B, 9) |
| Front Controller CAN TX Port. | |
| #define | FRONT_CONTROLLER_LEFT_SIG_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(B, 12) |
| Front Controller left signal load switch enable. | |
| #define | FRONT_CONTROLLER_RIGHT_SIG_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(B, 13) |
| Front Controller right signal load switch enable. | |
| #define | FRONT_CONTROLLER_BRAKE_LIGHT_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(A, 10) |
| Front Controller brake light load switch enable. | |
| #define | FRONT_CONTROLLER_BPS_LIGHT_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(A, 9) |
| Front Controller battery-protection-system light load switch enable. | |
| #define | FRONT_CONTROLLER_DRIVER_FAN_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(B, 14) |
| Front Controller driver fan load switch enable. | |
| #define | FRONT_CONTROLLER_REV_CAM_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(B, 15) |
| Front Controller reverse camera load switch enable. | |
| #define | FRONT_CONTROLLER_TELEM_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(A, 8) |
| Front Controller telemetry load switch enable. | |
| #define | FRONT_CONTROLLER_STEERING_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(B, 11) |
| Front Controller steering load switch enable. | |
| #define | FRONT_CONTROLLER_HORN_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(A, 11) |
| Front Controller horn load switch enable. | |
| #define | FRONT_CONTROLLER_SPARE_1_LS_ENABLE FRONT_CONTROLLER_GPIO_DEF(A, 12) |
| Front Controller spare 12V load switch enable. | |
| #define | FRONT_CONTROLLER_MUX_SEL_2 FRONT_CONTROLLER_GPIO_DEF(A, 6) |
| Front Controller current sense mux select 0. | |
| #define | FRONT_CONTROLLER_MUX_SEL_3 FRONT_CONTROLLER_GPIO_DEF(A, 7) |
| Front Controller current sense mux select 1. | |
| #define | FRONT_CONTROLLER_MUX_SEL_0 FRONT_CONTROLLER_GPIO_DEF(B, 1) |
| Front Controller current sense mux select 2. | |
| #define | FRONT_CONTROLLER_MUX_SEL_1 FRONT_CONTROLLER_GPIO_DEF(B, 2) |
| Front Controller current sense mux select 3. | |
| #define | FRONT_CONTROLLER_MUX_OUTPUT FRONT_CONTROLLER_GPIO_DEF(B, 0) |
| Front Controller current sense mux input. | |
| #define | FRONT_CONTROLLER_ACCEL_PEDAL FRONT_CONTROLLER_GPIO_DEF(A, 3) |
| Front Controller accelerator pedal input. | |
| #define | FRONT_CONTROLLER_BRAKE_PEDAL FRONT_CONTROLLER_GPIO_DEF(A, 5) |
| Front Controller brake pedal input. | |
| #define | FRONT_CONTROLLER_BOARD_LED FRONT_CONTROLLER_GPIO_DEF(B, 10) |
| Front Controller accelerator pedal input. | |
| #define | VEL_TO_RPM_RATIO 0.57147 |
| #define | WS22_CAN_BASE_CONTROL 0x500U |
| #define | WS22_CAN_BASE_STATUS 0x400U |
| #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 OpdStorage | OpdStorage |
| typedef struct PowerManagerStorage | PowerManagerStorage |
| typedef struct Ws22MotorCanStorage | Ws22MotorCanStorage |
| WS22 motor CAN interface storage structure. | |
Enumerations | |
| enum | FrontControllerState { FRONT_CONTROLLER_STATE_INIT = 0 , FRONT_CONTROLLER_STATE_IDLE , FRONT_CONTROLLER_STATE_DRIVE , FRONT_CONTROLLER_STATE_FAULT } |
| enum | FrontControllerEvent { FRONT_CONTROLLER_EVENT_NONE = 0 , FRONT_CONTROLLER_EVENT_INIT_COMPLETE , FRONT_CONTROLLER_EVENT_DRIVE_REQUEST , FRONT_CONTROLLER_EVENT_NEUTRAL_REQUEST , FRONT_CONTROLLER_EVENT_FAULT , FRONT_CONTROLLER_EVENT_RESET } |
| enum | OnePedalDriveState { STATE_DRIVING , STATE_BRAKING } |
| 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 , IDLE_GROUP , LEFT_LIGHTS_GROUP , RIGHT_LIGHTS_GROUP , HAZARD_LIGHTS_GROUP , BPS_LIGHTS_GROUP , BRAKE_LIGHTS_GROUP , HORN_GROUP , 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 | 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 | horn_run () |
| Reads the horn CAN status and sets the enable pin. 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 | 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. | |
| 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 | 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 (uint32_t 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 0x400U |
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 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 horn_init | ( | ) |
Initializes the horn pin.
| StatusCode horn_run | ( | ) |
Reads the horn CAN status and sets the enable 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_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 | ( | uint32_t | 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.