MCU
Loading...
Searching...
No Matches
MCUStateMachine.h
Go to the documentation of this file.
1#ifndef __MCU_STATE_MACHINE__
2#define __MCU_STATE_MACHINE__
3
4#include "SysClock.h"
5#include "Logger.h"
6
7#include "PedalsSystem.h"
8#include "DrivetrainSystem.h"
9#include "Buzzer.h"
10#include "TorqueControllerMux.h"
11#include "SafetySystem.h"
12#include "DashboardInterface.h"
13#include "AMSInterface.h"
14
15enum class CAR_STATE
16{
17 STARTUP = 0,
23};
24
25template <typename DrivetrainSysType>
27{
28public:
30 DrivetrainSysType *drivetrain,
31 DashboardInterface *dashboard,
32 PedalsSystem *pedals,
33 TCMuxType *mux,
34 SafetySystem *safety_system)
35 {
36 current_state_ = CAR_STATE::STARTUP;
39 dashboard_ = dashboard;
40 pedals_ = pedals;
41 controller_mux_ = mux;
42 safety_system_ = safety_system;
43 }
44
45 // TODO update this to just use the car_state struct instead of having to pass in cm
49 void tick_state_machine(unsigned long cm, const SharedCarState_s &current_car_state);
50
52 bool car_in_ready_to_drive() { return current_state_ == CAR_STATE::READY_TO_DRIVE; };
53
54private:
55 void set_state_(CAR_STATE new_state, unsigned long curr_time);
56
59 void handle_entry_logic_(CAR_STATE new_state, unsigned long curr_time);
60
63 void handle_exit_logic_(CAR_STATE prev_state, unsigned long curr_time);
65
68 DrivetrainSysType *drivetrain_;
70
73 // IMDInterface *imd_;
76};
77#include "MCUStateMachine.tpp"
78#endif /* MCUSTATEMACHINE */
CAR_STATE
@ WAITING_READY_TO_DRIVE_SOUND
@ TRACTIVE_SYSTEM_NOT_ACTIVE
@ TRACTIVE_SYSTEM_ACTIVE
@ ENABLING_INVERTERS
PedalsSystem * pedals_
void tick_state_machine(unsigned long cm, const SharedCarState_s &current_car_state)
function to tick the state machine.
void handle_exit_logic_(CAR_STATE prev_state, unsigned long curr_time)
function run upon the exit of a state
MCUStateMachine(BuzzerController *buzzer, DrivetrainSysType *drivetrain, DashboardInterface *dashboard, PedalsSystem *pedals, TCMuxType *mux, SafetySystem *safety_system)
void set_state_(CAR_STATE new_state, unsigned long curr_time)
CAR_STATE get_state()
TCMuxType * controller_mux_
CAR_STATE current_state_
BuzzerController * buzzer_
components within state machine
DashboardInterface * dashboard_
drivers within state machine
SafetySystem * safety_system_
DrivetrainSysType * drivetrain_
bool car_in_ready_to_drive()
void handle_entry_logic_(CAR_STATE new_state, unsigned long curr_time)
the function run upon the entry of the car into a new state
DriveSys_t drivetrain
Definition: main.cpp:223
BuzzerController buzzer(BUZZER_ON_INTERVAL)
Definition: main.cpp:325
car state struct that contains state of everything about the car including