The Steering system serves as an hub for all the controls that the driver can toggle during the driving. It is fundamental as it allows to change different settings such as Controls and Power
-
stm32f446 32-bit MCU based on ARM Cortex-M4, 512Kb of Flash and 128Kb of SRAM
-
5 Buttons working with interrupts in falling mode and configured with pullup
-
3 Rotary Dip Switch 10 positions, already implementing digital signals to avoid using adc channel of the MCU
-
CAN Communication to send the status of buttons and switches
contains the function to be run in the main, it call the sample of buttons and switches and send CAN messages.
typedef struct {
BTN_handleTypedef hbtn[BTN_Device_NUM];
RSW_handleTypedef hrsw[RSW_Device_NUM];
} Steering_Board;
void Steering_Init(void);
void Steering_Run(void);starting from an analog filter define the structure and implements a low pass IIR filter of the first order. Used to sample and debounce buttons and rotary DIP switches.
typedef struct {
float alpha; //alpha = RC/(Ts + RC)
float out;
} IIR_filter;
void IIR_Init(IIR_filter *filter, float alpha);
float IIR_Update(IIR_filter *filter, float in);some math:
% first-order IIR recursive difference equation:
y(n) = (1 - alpha) * x(n) + alpha * y(n-1) % where 0 <= alpha <= 1
% from the differential equation of a LP filter and discretization:
Vout(n) = (Ts / (Ts + RC)) * Vin(n) + (RC / (Ts + RC)) * Vout(n-1) % (RC / (Ts + RC)) = alpha
handle the buttons and define the functions for sampling their state.
- BTN_1: Traction control
- BTN_2: Torque vectoring
- BTN_3: Launch control
- BTN_4: Ready to drive
- BTN_5: Additional button
typedef struct {
enum BTN_Device id;
struct GPIO_Tuple gpio_tuple;
uint8_t value;
uint8_t prev_value;
enum BTN_State state;
IIR_filter filter;
} BTN_handleTypedef;
void BTN_Devices_Init(BTN_handleTypedef *hbtn, float btn_IIR_alpha);
void BTN_Device_Sample(BTN_handleTypedef *hbtn);
void BTN_Device_SampleALL(BTN_handleTypedef *hbtn);
enum BTN_State BTN_Device_GetState(BTN_handleTypedef *hbtn);handle the 3 rotary DIP switches and define the functions for sample their position.
- RSW1: Power regulation
- RSW2: Control incidence
- RSW3: Additional rotary
enum RSW_Device {
RSW_Device1,
RSW_Device2,
RSW_Device3,
RSW_Device_NUM
};
typedef struct {
enum RSW_Device id;
struct GPIO_Quad gpio_quad;
uint8_t value[4];
uint8_t state;
IIR_filter filters[4];
} RSW_handleTypedef;
void RSW_Devices_Init(RSW_handleTypedef *hrsw, float rsw_IIR_alpha);
void RSW_Device_Sample(RSW_handleTypedef *hrsw);
void RSW_Device_SampleALL(RSW_handleTypedef *hrsw);
uint8_t RSW_Device_GetState(RSW_handleTypedef *hrsw);Implements all the function needed for the CAN transmission.
void CAN_build_payload(uint8_t *payload, btnStateHandleTypedef *hbtn, rswStateHandleTypedef *hrsw);
void CAN_steering_Msg_send(CAN_HandleTypeDef *hcan, uint8_t *buffer, uint8_t len);When it will be available, integrate the upcoming version of the CAN system into the Steering project by doing the following
The following is the current version modified by me, but in sc26 it will have at least different names and id since it is no more included in the dash control unit
BO_ 357 DASH__hmiDevicesState : 3 DASH
SG_ BTN_1_isPressed : 0|1@1+ (1,0) [0|1] "" DSPACE, SCANNER
SG_ BTN_2_isPressed : 1|1@1+ (1,0) [0|1] "" DSPACE, SCANNER
SG_ BTN_3_isPressed : 2|1@1+ (1,0) [0|1] "" DSPACE, SCANNER
SG_ BTN_4_isPressed : 3|1@1+ (1,0) [0|1] "" DSPACE, SCANNER
SG_ BTN_5_isPressed : 4|1@1+ (1,0) [0|1] "" DSPACE, SCANNER
SG_ ROT_SW_1_state : 8|4@1+ (1,0) [0|9] "" DSPACE, SCANNER
SG_ ROT_SW_2_state : 12|4@1+ (1,0) [0|9] "" DSPACE, SCANNER
SG_ ROT_SW_3_state : 16|4@1+ (1,0) [0|9] "" DSPACE, SCANNER
add the sCan module as a Git submodule inside the Lib directory:
git submodule add https://github.com/squadracorsepolito/SCan.gitgit submodule update --init copy and paste it from other projects that you can find on the github and update it by looking at which files are in this project and select ONLY the current year sCan folder to don't encounter any trouble while building and flashing.