33
44/* Local includes */
55#include " VehicleStateMachine.h"
6- #include " DrivetrainSystem.h"
7- #include " SafetySystem.h"
8- #include " Buzzer.h"
9- #include " VCR_Globals.h"
106
11- void VehicleStateMachine::tick_state_machine (unsigned long current_millis)
7+ void VehicleStateMachine::tick_state_machine (unsigned long current_millis, const VCRSystemData_s &system_data )
128{
13- // TODO: Make this NOT uint32_t (it was only specified to allow compilation)
14- DrivetrainSystem<uint32_t > &drivetrain = DrivetrainSystem<uint32_t >::getInstance ();
15- BuzzerController &buzzer = BuzzerController::getInstance ();
169
1710 switch (_current_state)
1811 {
@@ -27,8 +20,8 @@ void VehicleStateMachine::tick_state_machine(unsigned long current_millis)
2720 case CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE:
2821 {
2922 // if TS is above HV threshold, move to Tractive System Active
30- drivetrain .disable_no_pins ();
31- if (drivetrain .hv_over_threshold_on_drivetrain ())
23+ _drivetrain .disable_no_pins ();
24+ if (_drivetrain .hv_over_threshold_on_drivetrain ())
3225 {
3326 set_state_ (CAR_STATE::TRACTIVE_SYSTEM_ACTIVE, current_millis);
3427 }
@@ -37,14 +30,14 @@ void VehicleStateMachine::tick_state_machine(unsigned long current_millis)
3730
3831 case CAR_STATE::TRACTIVE_SYSTEM_ACTIVE:
3932 {
40- if (buzzer .buzzer_is_active (current_millis))
33+ if (_buzzer .buzzer_is_active (current_millis))
4134 {
42- buzzer .deactivate ();
35+ _buzzer .deactivate ();
4336 }
4437
45- drivetrain .disable_no_pins ();
38+ _drivetrain .disable_no_pins ();
4639
47- if (!drivetrain .hv_over_threshold_on_drivetrain ())
40+ if (!_drivetrain .hv_over_threshold_on_drivetrain ())
4841 {
4942 set_state_ (CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE, current_millis);
5043 break ;
@@ -62,19 +55,19 @@ void VehicleStateMachine::tick_state_machine(unsigned long current_millis)
6255 {
6356
6457 // If HV is not active, go to TRACTIVE_SYSTEM_NOT_ACTIVE
65- if (drivetrain .hv_over_threshold_on_drivetrain ())
58+ if (_drivetrain .hv_over_threshold_on_drivetrain ())
6659 {
6760 set_state_ (CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE, current_millis);
6861 break ;
6962 }
7063
7164 // If motor controllers have error, but HV still active
72- if (drivetrain .drivetrain_error_occured ())
65+ if (_drivetrain .drivetrain_error_occured ())
7366 {
7467 set_state_ (CAR_STATE::TRACTIVE_SYSTEM_ACTIVE, current_millis);
7568 }
7669
77- if (drivetrain .handle_inverter_startup (current_millis))
70+ if (_drivetrain .handle_inverter_startup (current_millis))
7871 {
7972 set_state_ (CAR_STATE::WAITING_READY_TO_DRIVE_SOUND, current_millis);
8073 break ;
@@ -86,16 +79,16 @@ void VehicleStateMachine::tick_state_machine(unsigned long current_millis)
8679 {
8780
8881 // If HV is no longer active, return to TRACTIVE_SYSTEM_NOT_ACTIVE
89- if (drivetrain .hv_over_threshold_on_drivetrain ())
82+ if (_drivetrain .hv_over_threshold_on_drivetrain ())
9083 {
9184 set_state_ (CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE, current_millis);
9285 break ;
9386 }
9487
95- drivetrain .command_drivetrain_no_torque (); // While waiting for RTD sound to complete, always command 0 torque
88+ _drivetrain .command_drivetrain_no_torque (); // While waiting for RTD sound to complete, always command 0 torque
9689
9790 // If the ready-to-drive sound is done playing, move to ready to drive mode
98- if (!buzzer .buzzer_is_active (current_millis))
91+ if (!_buzzer .buzzer_is_active (current_millis))
9992 {
10093 set_state_ (CAR_STATE::READY_TO_DRIVE, current_millis);
10194 }
@@ -107,29 +100,29 @@ void VehicleStateMachine::tick_state_machine(unsigned long current_millis)
107100 {
108101
109102 // If HV is no longer active, return to TRACTIVE_SYSTEM_NOT_ACTIVE
110- if (!drivetrain .hv_over_threshold_on_drivetrain ())
103+ if (!_drivetrain .hv_over_threshold_on_drivetrain ())
111104 {
112105 hal_println (" Drivetrain not over threshold while in READY_TO_DRIVE" );
113106 set_state_ (CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE, current_millis);
114107 break ;
115108 }
116109
117- if (drivetrain .drivetrain_error_occured ())
110+ if (_drivetrain .drivetrain_error_occured ())
118111 {
119112 hal_println (" Drivetrain error occurred while in READY_TO_DRIVE" );
120113 set_state_ (CAR_STATE::TRACTIVE_SYSTEM_ACTIVE, current_millis);
121114 break ;
122115 }
123116
124- if (SafetySystem::getInstance (). get_software_is_ok () && !system_data.pedals_system_data .implausibility_has_exceeded_max_duration )
117+ if (/* _ams_system.ams_ok () && */ !system_data.pedals_system_data .implausibility_has_exceeded_max_duration )
125118 {
126119 // TODO: Fix with all references to singleton classes
127120 // drivetrain.command_drivetrain(controller_mux_->getDrivetrainCommand(dashboard_->getDialMode(), dashboard_->getTorqueLimitMode(), current_car_state));
128121 }
129122 else
130123 {
131124 // If software is not OK or some implausibility has exceeded max duration, command 0 torque (but stay in RTD mode)
132- drivetrain .command_drivetrain_no_torque ();
125+ _drivetrain .command_drivetrain_no_torque ();
133126 }
134127
135128 break ;
@@ -180,7 +173,7 @@ void VehicleStateMachine::handle_entry_logic_(CAR_STATE new_state, unsigned long
180173 break ;
181174 case CAR_STATE::WAITING_READY_TO_DRIVE_SOUND:
182175 {
183- BuzzerController::getInstance () .activate (curr_millis);
176+ _buzzer .activate (curr_millis);
184177 break ;
185178 }
186179 case CAR_STATE::READY_TO_DRIVE:
0 commit comments