Midnight Sun Firmware
Loading...
Searching...
No Matches
front_controller.h
1#pragma once
2
3/************************************************************************************************
4 * @file front_controller.h
5 *
6 * @brief Header file for front_controller
7 *
8 * @date 2025-07-19
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdbool.h>
14#include <stdint.h>
15
16/* Inter-component Headers */
17#include "global_enums.h"
18#include "persist.h"
19#include "status.h"
20#include "ws22_motor_can.h"
21
22/* Intra-component Headers */
23
30/* Forward declarations */
31struct PowerSenseStorage;
35
37#define FRONT_CONTROLLER_ACCEL_INPUT_DEADZONE 0.05f
38
40#define FRONT_CONTROLLER_ACCEL_REMAP_MIN 0.10f
41
43#define FRONT_CONTROLLER_ACCEL_CURVE_EXPONENT 2.0f
44
46#define FRONT_CONTROLLER_ACCEL_LPF_ALPHA 0.20f
47
49#define FRONT_CONTROLLER_ACCEL_CC_OVERRIDE_DEADZONE 0.10f
50
52#define FRONT_CONTROLLER_BRAKE_LPF_ALPHA 0.20f
53
55#define FRONT_CONTROLLER_BRAKE_INPUT_DEADZONE 0.15f
56
58#define WS22_CONTROLLER_MAX_VELOCITY 12000
59
61#define MAX_VEHICLE_SPEED_KPH 50
62
64#define FRONT_CONTROLLER_ACCEL_PEDAL_UPPER_VALUE_AMPLIFIED_DEFAULT 1120
65#define FRONT_CONTROLLER_ACCEL_PEDAL_LOWER_VALUE_AMPLIFIED_DEFAULT 286
66
67#define FRONT_CONTROLLER_ACCEL_PEDAL_OPAMP_THRESHOLD_DEFAULT 535
68#define FRONT_CONTROLLER_ACCEL_PEDAL_REVERSED_DEFAULT true
69
70#define FRONT_CONTROLLER_BRAKE_PEDAL_UPPER_VALUE_DEFAULT 1230
71#define FRONT_CONTROLLER_BRAKE_PEDAL_LOWER_VALUE_DEFAULT 960
72
76typedef struct {
86
90typedef enum {
91 BRAKE_STATE_DISABLED = 0,
92 BRAKE_STATE_BRAKING,
94
98typedef struct {
103 float brake_percentage;
115 PersistStorage *persist_storage;
116 PedalPersistData *pedal_persist_data;
118
BrakeState
Front Controller brake states.
Definition: front_controller.h:90
StatusCode front_controller_init(FrontControllerStorage *storage, FrontControllerConfig *config, Ws22MotorCanConfig *motor_can_config)
Initialize the front controller interface.
Definition: front_controller.c:61
VehicleDriveState
Vehicle drive states.
Definition: global_enums.h:33
StatusCode
StatusCodes for various errors.
Definition: status.h:27
Definition: accel_pedal.h:34
Definition: brake_pedal.h:31
Front Controller configuration data.
Definition: front_controller.h:76
float brake_low_pass_filter_alpha
Definition: front_controller.h:84
float brake_pedal_activation_zone
Definition: front_controller.h:83
float accel_low_pass_filter_alpha
Definition: front_controller.h:80
float accel_input_deadzone
Definition: front_controller.h:77
float accel_input_curve_exponent
Definition: front_controller.h:79
float accel_input_remap_min
Definition: front_controller.h:78
float brake_pedal_deadzone
Definition: front_controller.h:82
float accel_cc_override_deadzone
Definition: front_controller.h:81
Front Controller storage.
Definition: front_controller.h:98
struct AccelPedalStorage * accel_pedal_storage
Definition: front_controller.h:108
struct OpdStorage * opd_storage
Definition: front_controller.h:111
struct Ws22MotorCanStorage * ws22_motor_can_storage
Definition: front_controller.h:110
struct BrakePedalStorage * brake_pedal_storage
Definition: front_controller.h:109
Ws22MotorCanConfig * ws22_motor_can_config
Definition: front_controller.h:114
FrontControllerConfig * config
Definition: front_controller.h:113
struct PowerManagerStorage * power_manager_storage
Definition: front_controller.h:107
VehicleDriveState current_drive_state
Definition: front_controller.h:105
float accel_percentage
Definition: front_controller.h:104
BrakeState brake_state
Definition: front_controller.h:99
uint32_t vehicle_speed_kph
Definition: front_controller.h:101
Definition: opd.h:27
Definition: persist.h:31
Definition: power_manager.h:28
Definition: ws22_motor_can.h:95
WS22 motor CAN interface storage structure.
Definition: ws22_motor_can.h:111