Skip to content

Commit fd2c0cf

Browse files
committed
Merged main into ams_interface
2 parents 149fe20 + 47d3357 commit fd2c0cf

27 files changed

+1082
-133
lines changed

.clang-tidy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Checks: 'bugprone-*, cppcoreguidelines-*, readability-identifier-naming, -cppcoreguidelines-avoid-non-const-global-variables, -bugprone-branch-clone, -cppcoreguidelines-pro-type-vararg, -bugprone-easily-swappable-parameters'
2+
WarningsAsErrors: 'cppcoreguidelines-*, bugprone-*, readability-identifier-naming'
3+
FormatStyle: 'file'
4+
CheckOptions:
5+
- { key: readability-identifier-naming.ClassMemberCase, value: 'lower_case' }
6+
- { key: readability-identifier-naming.ClassMemberPrefix, value: '_' }
7+
- { key: readability-identifier-naming.FunctionCase, value: 'lower_case' }

.clangd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CompileFlags:
2+
CompilationDatabase: .

.github/workflows/platformio.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ jobs:
2424
run: pio run -e teensy41
2525

2626
- name: Run Tests
27-
run: pio test -e test_systems_env
27+
run: pio test -e test_systems_env
28+
29+
- name: run checks
30+
run: pio check -e teensy41 --fail-on-defect high

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.pio
22
.vscode/*
33
compile_commands.json
4+
.cache/

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@ If you are not already familiar with PlatformIO, please read [Module 4](https://
1616

1717
To TEST code, open a PlatformIO terminal (CTRL-SHIFT-P, then `PlatformIO: New Terminal`). Then, to test systems (non hardware-specific logic), call `pio test -e test_systems_env`. This will run all unit tests in the `test/test_systems` directory.
1818

19+
## Check code
20+
21+
in the PlatformIO terminal:
22+
23+
`pio check -e teensy41 --fail-on-defect high`
24+
1925
## FAQ: Why red squiggles?
2026
See [this](https://wiki.hytechracing.org/books/hytech-racing-general-info/page/vscode-setup-for-auto-completion-and-code-navigation) page on our BookStack for help configuring VSCode for auto completion and code navigation within external library dependencies.

include/VCR_Constants.h

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,26 @@ const int THERMISTOR_6 = 6;
3636
const int THERMISTOR_7 = 7;
3737

3838
/* Scaling and offset */
39-
const float GLV_SENSE_SCALE = -1; //TODO: FIGURE THIS OUT
40-
const int GLV_SENSE_OFFSET = -1; //TODO: FIGURE THIS OUT
41-
const float CURRENT_SENSE_SCALE = -1; //TODO: FIGURE THIS OUT
42-
const int CURRENT_SENSE_OFFSET = -1; //TODO: FIGURE THIS OUT
43-
const float REFERENCE_SENSE_SCALE = -1; //TODO: FIGURE THIS OUT
44-
const int REFERENCE_SENSE_OFFSET = -1; //TODO: FIGURE THIS OUT
45-
const float RL_LOADCELL_SCALE = -1; //TODO: FIGURE THIS OUT
46-
const int RL_LOADCELL_OFFSET = -1; //TODO: FIGURE THIS OUT
47-
const float RR_LOADCELL_SCALE = -1; //TODO: FIGURE THIS OUT
48-
const int RR_LOADCELL_OFFSET = -1; //TODO: FIGURE THIS OUT
49-
const float RL_SUS_POT_SCALE = -1; //TODO: FIGURE THIS OUT
50-
const int RL_SUS_POT_OFFSET = -1; //TODO: FIGURE THIS OUT
51-
const float RR_SUS_POT_SCALE = -1; //TODO: FIGURE THIS OUT
52-
const int RR_SUS_POT_OFFSET = -1; //TODO: FIGURE THIS OUT
53-
39+
const float GLV_SENSE_SCALE = (float)(24.0/((2.77149877/3.3)*4096.0)); //unsure about the multiplication by 4.0865
40+
const int GLV_SENSE_OFFSET = 0; //No offset for GLV
41+
const float CURRENT_SENSE_SCALE = (float)(24/((2.77149877/3.3)*4096)); //unsure about the multiplication by 4.0865
42+
const int CURRENT_SENSE_OFFSET = 0; //No offset for CURRENT_SENSE
43+
const float REFERENCE_SENSE_SCALE = (float)(24/((2.77149877/3.3)*4096)); //unsure about the multiplication by 4.0865
44+
const int REFERENCE_SENSE_OFFSET = 0; //No offset for REFERENCE_SENSE
45+
46+
//Values are from the old MCU rev15
47+
const float RL_LOADCELL_SCALE = 0.1149f;
48+
const float RL_LOADCELL_OFFSET = 13.526f / RL_LOADCELL_SCALE;
49+
const float RR_LOADCELL_SCALE = 0.118f;
50+
const float RR_LOADCELL_OFFSET = 25.721f / RR_LOADCELL_SCALE;
51+
52+
//does not matter that much
53+
const float RL_SUS_POT_SCALE = 1;
54+
const int RL_SUS_POT_OFFSET = 1;
55+
const float RR_SUS_POT_SCALE = 1;
56+
const int RR_SUS_POT_OFFSET = 1;
57+
58+
const int WATCHDOG_PIN = 36;
5459

5560

5661
#endif /* VCR_CONSTANTS */

include/VCR_Globals.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
#include "VCR_Constants.h"
1212

1313
/* Interface and system data structs */
14-
extern VCRInterfaceData_s interface_data;
15-
extern VCRSystemData_s system_data;
14+
extern VCRInterfaceData_s interface_data; // NOLINT
15+
extern VCRSystemData_s system_data; // NOLINT
1616

1717
/* ADC setup */
18-
extern MCP_ADC<8> adc_0; // MCP3208. ADC0 in VCR schematic. Used for valuable telem data.
19-
extern MCP_ADC<8> adc_1; // MCP3208. ADC1 in VCR schematic. Used for extra thermistors or extra sensors while testing.
18+
constexpr unsigned int channels_within_mcp_adc = 8;
19+
extern MCP_ADC<channels_within_mcp_adc> adc_0; // MCP3208. ADC0 in VCR schematic. Used for valuable telem data.
20+
extern MCP_ADC<channels_within_mcp_adc> adc_1; // MCP3208. ADC1 in VCR schematic. Used for extra thermistors or extra sensors while testing.
21+
22+
/* Watchdog pin */
23+
extern const int watchdog_pin;
2024

2125
#endif /* VCR_GLOBALS */

include/VCR_Tasks.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@
3232
/* From shared_firmware_types library */
3333
#include "SharedFirmwareTypes.h"
3434

35-
/**
36-
* This "Test" function is purely for validation of the HT_SCHED dependency. This is intended to be removed when
37-
* further development occurs.
38-
*/
39-
bool init_test_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
40-
bool run_test_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
41-
extern HT_TASK::Task test_task;
42-
35+
/* Local includes */
36+
#include "WatchdogSystem.h"
37+
#include "VCR_Constants.h"
38+
#include "VehicleStateMachine.h"
39+
#include "VCR_Globals.h"
40+
#include "Buzzer.h"
4341

4442
/**
4543
* The "tick state machine" task will simply call the state machine's tick function with the current
@@ -54,7 +52,7 @@ extern HT_TASK::Task tick_state_machine_task;
5452
/**
5553
* The read_adc0 task will command adc0 to sample all eight channels, convert the outputs, and
5654
* store them in structs defined in shared_firmware_types. This function relies on adc_0 being
57-
* defined in ADC_interface.h.
55+
* defined in VCRGlobals.h.
5856
*/
5957
bool init_read_adc0_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
6058
bool run_read_adc0_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
@@ -66,9 +64,9 @@ extern HT_TASK::Task read_adc0_task;
6664
* NOTE: These channels are UNUSED BY DEFAULT and exist ONLY FOR TESTING. You may edit this
6765
* manually to add sensors.
6866
*
69-
* The read_adc1 task will command adc0 to sample all eight channels, convert the outputs, and
67+
* The read_adc1 task will command adc1 to sample all eight channels, convert the outputs, and
7068
* store them in a struct defined in shared_firmware_types. This function relies on adc_1 being
71-
* defined in ADC_interface.h.
69+
* defined in VCRGlobals.h.
7270
*/
7371
bool init_read_adc1_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
7472
bool run_read_adc1_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
@@ -83,4 +81,12 @@ extern HT_TASK::Task read_adc1_task;
8381
bool run_update_buzzer_controller_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
8482
extern HT_TASK::Task update_buzzer_controller_task;
8583

84+
85+
86+
/**
87+
* This task will fetch the watchdog state from WatchdogSystem and write it to the watchdog pin
88+
*/
89+
bool run_kick_watchdog(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
90+
extern HT_TASK::Task kick_watchdog_task;
91+
8692
#endif /* VCR_TASKS */

lib/state_machine/include/VehicleStateMachine.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#ifndef VEHICLE_STATE_MACHINE
22
#define VEHICLE_STATE_MACHINE
33

4+
/* From local systems library */
5+
#include "DrivetrainSystem.h"
6+
#include "BuzzerController.h"
7+
48
/**
59
* Enum representing possible states for the vehicle's state machine.
610
*
@@ -46,16 +50,17 @@ class VehicleStateMachine
4650
* @pre Other systems are updated properly
4751
* @pre All relevant data exists in the data structs (VCRInterfaceData, VCRSystemData, etc.)
4852
* @param current_millis The system time, in millis. Passed in by the scheduler.
53+
* @param system_data A reference to the global system data struct.
4954
*/
50-
void tick_state_machine(unsigned long current_millis);
55+
void tick_state_machine(unsigned long current_millis, const VCRSystemData_s &system_data);
5156

5257
CAR_STATE get_state() { return _current_state; }
5358

5459
private:
55-
VehicleStateMachine()
56-
{
57-
_current_state = CAR_STATE::STARTUP;
58-
}
60+
VehicleStateMachine() :
61+
_current_state(CAR_STATE::STARTUP),
62+
_drivetrain(DrivetrainSystem<uint32_t>::getInstance()),
63+
_buzzer(BuzzerController::getInstance()) {};
5964

6065
void set_state_(CAR_STATE new_state, unsigned long curr_time);
6166

@@ -73,6 +78,10 @@ class VehicleStateMachine
7378

7479
CAR_STATE _current_state;
7580

81+
/* System references to show dependence on systems library */
82+
DrivetrainSystem<uint32_t> &_drivetrain; //TODO: Make this InverterInterface instead of uint32_t
83+
BuzzerController &_buzzer;
84+
// AMSSystem &_ams_system;
7685
};
7786

7887
#endif /* VEHICLE_STATE_MACHINE */

lib/state_machine/src/VehicleStateMachine.cpp

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,9 @@
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

Comments
 (0)