MCU
Loading...
Searching...
No Matches
lib
state_machine
include
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
15
enum class
CAR_STATE
16
{
17
STARTUP
= 0,
18
TRACTIVE_SYSTEM_NOT_ACTIVE
= 1,
19
TRACTIVE_SYSTEM_ACTIVE
= 2,
20
ENABLING_INVERTERS
= 3,
21
WAITING_READY_TO_DRIVE_SOUND
= 4,
22
READY_TO_DRIVE
= 5
23
};
24
25
template
<
typename
DrivetrainSysType>
26
class
MCUStateMachine
27
{
28
public
:
29
MCUStateMachine
(
BuzzerController
*
buzzer
,
30
DrivetrainSysType *
drivetrain
,
31
DashboardInterface
*dashboard,
32
PedalsSystem
*pedals,
33
TCMuxType
*mux,
34
SafetySystem
*safety_system)
35
{
36
current_state_
= CAR_STATE::STARTUP;
37
buzzer_
=
buzzer
;
38
drivetrain_
=
drivetrain
;
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
¤t_car_state);
50
51
CAR_STATE
get_state
() {
return
current_state_
; }
52
bool
car_in_ready_to_drive
() {
return
current_state_
== CAR_STATE::READY_TO_DRIVE; };
53
54
private
:
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);
64
CAR_STATE
current_state_
;
65
67
BuzzerController
*
buzzer_
;
68
DrivetrainSysType *
drivetrain_
;
69
PedalsSystem
*
pedals_
;
70
72
DashboardInterface
*
dashboard_
;
73
// IMDInterface *imd_;
74
SafetySystem
*
safety_system_
;
75
TCMuxType
*
controller_mux_
;
76
};
77
#include "MCUStateMachine.tpp"
78
#endif
/* MCUSTATEMACHINE */
Buzzer.h
DrivetrainSystem.h
CAR_STATE
CAR_STATE
Definition:
MCUStateMachine.h:16
CAR_STATE::WAITING_READY_TO_DRIVE_SOUND
@ WAITING_READY_TO_DRIVE_SOUND
CAR_STATE::STARTUP
@ STARTUP
CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE
@ TRACTIVE_SYSTEM_NOT_ACTIVE
CAR_STATE::READY_TO_DRIVE
@ READY_TO_DRIVE
CAR_STATE::TRACTIVE_SYSTEM_ACTIVE
@ TRACTIVE_SYSTEM_ACTIVE
CAR_STATE::ENABLING_INVERTERS
@ ENABLING_INVERTERS
PedalsSystem.h
SafetySystem.h
TorqueControllerMux.h
BuzzerController
Definition:
Buzzer.h:7
DashboardInterface
Definition:
DashboardInterface.h:83
MCUStateMachine
Definition:
MCUStateMachine.h:27
MCUStateMachine::pedals_
PedalsSystem * pedals_
Definition:
MCUStateMachine.h:69
MCUStateMachine::tick_state_machine
void tick_state_machine(unsigned long cm, const SharedCarState_s ¤t_car_state)
function to tick the state machine.
MCUStateMachine::handle_exit_logic_
void handle_exit_logic_(CAR_STATE prev_state, unsigned long curr_time)
function run upon the exit of a state
MCUStateMachine::MCUStateMachine
MCUStateMachine(BuzzerController *buzzer, DrivetrainSysType *drivetrain, DashboardInterface *dashboard, PedalsSystem *pedals, TCMuxType *mux, SafetySystem *safety_system)
Definition:
MCUStateMachine.h:29
MCUStateMachine::set_state_
void set_state_(CAR_STATE new_state, unsigned long curr_time)
MCUStateMachine::get_state
CAR_STATE get_state()
Definition:
MCUStateMachine.h:51
MCUStateMachine::controller_mux_
TCMuxType * controller_mux_
Definition:
MCUStateMachine.h:75
MCUStateMachine::current_state_
CAR_STATE current_state_
Definition:
MCUStateMachine.h:64
MCUStateMachine::buzzer_
BuzzerController * buzzer_
components within state machine
Definition:
MCUStateMachine.h:67
MCUStateMachine::dashboard_
DashboardInterface * dashboard_
drivers within state machine
Definition:
MCUStateMachine.h:72
MCUStateMachine::safety_system_
SafetySystem * safety_system_
Definition:
MCUStateMachine.h:74
MCUStateMachine::drivetrain_
DrivetrainSysType * drivetrain_
Definition:
MCUStateMachine.h:68
MCUStateMachine::car_in_ready_to_drive
bool car_in_ready_to_drive()
Definition:
MCUStateMachine.h:52
MCUStateMachine::handle_entry_logic_
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
PedalsSystem
Definition:
PedalsSystem.h:42
SafetySystem
Definition:
SafetySystem.h:9
TorqueControllerMux
Definition:
TorqueControllerMux.h:61
drivetrain
DriveSys_t drivetrain
Definition:
main.cpp:223
buzzer
BuzzerController buzzer(BUZZER_ON_INTERVAL)
Definition:
main.cpp:325
SharedCarState_s
car state struct that contains state of everything about the car including
Definition:
SharedDataTypes.h:149
Generated by
1.9.5