Skip to content

Commit 5f7bcbc

Browse files
committed
merged with main again
2 parents f36b41c + d5e8ba9 commit 5f7bcbc

20 files changed

+244
-115
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.pio
22
.vscode/*
33
compile_commands.json
4-
.cache/
4+
.cache/
5+
**.DS_Store

getcompilecommands.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -o pipefail
3+
pio run -e teensy41
4+
pio run -t compiledb -e teensy41

include/VCR_Constants.h

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,49 @@ const int ADC1_CS = 11; // MCP3208. ADC1 in VCR schematic. Used for extra thermi
1616
/* -------------------------------------------------- */
1717

1818
/* Channels on adc_0 */
19-
const int GLV_SENSE_CHANNEL = 0;
20-
const int CURRENT_SENSE_CHANNEL = 1;
21-
const int REFERENCE_SENSE_CHANNEL = 2;
22-
const int RL_LOADCELL_CHANNEL = 3;
23-
const int RR_LOADCELL_CHANNEL = 4;
24-
const int RL_SUS_POT_CHANNEL = 5;
25-
const int RR_SUS_POT_CHANNEL = 6;
19+
constexpr int GLV_SENSE_CHANNEL = 0;
20+
constexpr int CURRENT_SENSE_CHANNEL = 1;
21+
constexpr int REFERENCE_SENSE_CHANNEL = 2;
22+
constexpr int RL_LOADCELL_CHANNEL = 3;
23+
constexpr int RR_LOADCELL_CHANNEL = 4;
24+
constexpr int RL_SUS_POT_CHANNEL = 5;
25+
constexpr int RR_SUS_POT_CHANNEL = 6;
2626
// const int UNUSED_CHANNEL = 7;
2727

2828
/* Channels on ADC_1 */
29-
const int THERMISTOR_0 = 0;
30-
const int THERMISTOR_1 = 1;
31-
const int THERMISTOR_2 = 2;
32-
const int THERMISTOR_3 = 3;
33-
const int THERMISTOR_4 = 4;
34-
const int THERMISTOR_5 = 5;
35-
const int THERMISTOR_6 = 6;
36-
const int THERMISTOR_7 = 7;
29+
constexpr int THERMISTOR_0 = 0;
30+
constexpr int THERMISTOR_1 = 1;
31+
constexpr int THERMISTOR_2 = 2;
32+
constexpr int THERMISTOR_3 = 3;
33+
constexpr int THERMISTOR_4 = 4;
34+
constexpr int THERMISTOR_5 = 5;
35+
constexpr int THERMISTOR_6 = 6;
36+
constexpr int THERMISTOR_7 = 7;
3737

3838
/* Scaling and offset */
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
39+
constexpr float GLV_SENSE_SCALE = (float)(24.0/((2.77149877/3.3)*4096.0)); //unsure about the multiplication by 4.0865
40+
constexpr int GLV_SENSE_OFFSET = 0; //No offset for GLV
41+
constexpr float CURRENT_SENSE_SCALE = (float)(24/((2.77149877/3.3)*4096)); //unsure about the multiplication by 4.0865
42+
constexpr int CURRENT_SENSE_OFFSET = 0; //No offset for CURRENT_SENSE
43+
constexpr float REFERENCE_SENSE_SCALE = (float)(24/((2.77149877/3.3)*4096)); //unsure about the multiplication by 4.0865
44+
constexpr int REFERENCE_SENSE_OFFSET = 0; //No offset for REFERENCE_SENSE
4545

4646
//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;
47+
constexpr float RL_LOADCELL_SCALE = 0.1149f;
48+
constexpr float RL_LOADCELL_OFFSET = 13.526f / RL_LOADCELL_SCALE;
49+
constexpr float RR_LOADCELL_SCALE = 0.118f;
50+
constexpr float RR_LOADCELL_OFFSET = 25.721f / RR_LOADCELL_SCALE;
5151

5252
//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-
53+
constexpr float RL_SUS_POT_SCALE = 1;
54+
constexpr int RL_SUS_POT_OFFSET = 1;
55+
constexpr float RR_SUS_POT_SCALE = 1;
56+
constexpr int RR_SUS_POT_OFFSET = 1;
5857

58+
constexpr int WATCHDOG_PIN = 36;
5959

60+
namespace default_system_params
61+
{
62+
constexpr unsigned long KICK_INTERVAL_MS = 10UL;
63+
}
6064
#endif /* VCR_CONSTANTS */

include/VCR_Globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ constexpr unsigned int channels_within_mcp_adc = 8;
1919
extern MCP_ADC<channels_within_mcp_adc> adc_0; // MCP3208. ADC0 in VCR schematic. Used for valuable telem data.
2020
extern MCP_ADC<channels_within_mcp_adc> adc_1; // MCP3208. ADC1 in VCR schematic. Used for extra thermistors or extra sensors while testing.
2121

22+
2223
#endif /* VCR_GLOBALS */

include/VCR_Tasks.h

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

35-
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"
3641

3742
/**
3843
* The "tick state machine" task will simply call the state machine's tick function with the current
@@ -76,4 +81,12 @@ extern HT_TASK::Task read_adc1_task;
7681
bool run_update_buzzer_controller_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
7782
extern HT_TASK::Task update_buzzer_controller_task;
7883

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+
7992
#endif /* VCR_TASKS */

lib/state_machine/include/VehicleStateMachine.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
/* From local systems library */
55
#include "DrivetrainSystem.h"
6-
#include "SafetySystem.h"
76
#include "BuzzerController.h"
87

98
/**
@@ -42,8 +41,7 @@ class VehicleStateMachine
4241
VehicleStateMachine(DrivetrainSystem & drivetrain_system) :
4342
_current_state(CAR_STATE::STARTUP),
4443
_drivetrain(drivetrain_system),
45-
_buzzer(BuzzerController::getInstance()),
46-
_safetysystem(SafetySystem::getInstance()) {};
44+
_buzzer(BuzzerController::getInstance()) {};
4745

4846

4947
/**
@@ -59,6 +57,7 @@ class VehicleStateMachine
5957
CAR_STATE get_state() { return _current_state; }
6058

6159
private:
60+
6261
void set_state_(CAR_STATE new_state, unsigned long curr_time);
6362

6463
/**
@@ -78,8 +77,7 @@ class VehicleStateMachine
7877
/* System references to show dependence on systems library */
7978
DrivetrainSystem &_drivetrain; //TODO: Make this InverterInterface instead of uint32_t
8079
BuzzerController &_buzzer;
81-
SafetySystem &_safetysystem;
82-
80+
// AMSSystem &_ams_system;
8381
};
8482

8583
#endif /* VEHICLE_STATE_MACHINE */

lib/state_machine/src/VehicleStateMachine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void VehicleStateMachine::tick_state_machine(unsigned long current_millis, const
117117
break;
118118
}
119119

120-
if (_safetysystem.get_software_is_ok() && !system_data.pedals_system_data.implausibility_has_exceeded_max_duration)
120+
if (/* _ams_system.ams_ok() && */ !system_data.pedals_system_data.implausibility_has_exceeded_max_duration)
121121
{
122122
// TODO: Fix with all references to singleton classes
123123
// TODO: need to also handle request to mode switch via drivetrain init (?)

lib/systems/include/Buzzer.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#ifndef BUZZER
2+
#define BUZZER
3+
4+
/**
5+
* This class controls the car's buzzer. It is a singleton class (since we only have one buzzer).
6+
*
7+
* NOTE: This class does NOT directly control the buzzer. Rather, it does the calculations of whether
8+
* or not the buzzer SHOULD be active. The output of this system then goes to the Dashboard,
9+
* who will activate the buzzer when this system outputs HIGH.
10+
*/
11+
class BuzzerController
12+
{
13+
public:
14+
static BuzzerController& getInstance()
15+
{
16+
static BuzzerController instance;
17+
return instance;
18+
}
19+
20+
/**
21+
* Calling this command will activate the buzzer for BUZZER_PERIOD_MS milliseconds.
22+
*/
23+
void activate(unsigned long curr_millis)
24+
{
25+
_last_activation_time_ms = curr_millis;
26+
}
27+
28+
/**
29+
* Immediately kill the buzzer.
30+
*/
31+
void deactivate()
32+
{
33+
_last_activation_time_ms = 0;
34+
}
35+
36+
/**
37+
* Returns whether or not the buzzer should currently be active, according to the system.
38+
*/
39+
bool buzzer_is_active(unsigned long millis)
40+
{
41+
return (millis - _last_activation_time_ms) < BUZZER_PERIOD_MS;
42+
}
43+
44+
private:
45+
46+
BuzzerController()
47+
{
48+
_last_activation_time_ms = 0;
49+
}
50+
51+
const unsigned long BUZZER_PERIOD_MS = 2000; // Default buzzer period is 2000ms
52+
53+
unsigned long _last_activation_time_ms;
54+
55+
};
56+
57+
#endif /* BUZZER */

lib/systems/include/SafetySystem.h

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef WATCHDOG_SYSTEM_H
2+
#define WATCHDOG_SYSTEM_H
3+
4+
#include <etl/singleton.h>
5+
6+
/**
7+
* This class controls the boolean _watchdog_state, but does not directly control the watchdog.
8+
* WatchdogSystem provides functionality to initialize, monitor, and "kick" the watchdog to prevent system resets.
9+
*
10+
* NOTE: To ensure system responsiveness, WatchdogSystem requires periodic updates by calling the `get_watchdog_state()` method.
11+
* This toggles the _watchdog_state (if the interval has passed) and returns the new state, which must then be sent to the watchdog.
12+
*/
13+
14+
15+
class WatchdogSystem
16+
{
17+
public:
18+
19+
WatchdogSystem(const unsigned long kick_interval_ms = 10UL) : _watchdog_time(0), _watchdog_state(false), _watchdog_kick_interval(kick_interval_ms) {};
20+
private:
21+
22+
/*Private constructor*/
23+
24+
/* Watchdog last kicked time */
25+
unsigned long _watchdog_time;
26+
bool _watchdog_state;
27+
unsigned long _watchdog_kick_interval;
28+
/* Watchdog output state */
29+
30+
public:
31+
32+
/* Get/update watchdog state */
33+
bool get_watchdog_state(unsigned long curr_millis);
34+
35+
};
36+
37+
using WatchdogInstance = etl::singleton<WatchdogSystem>;
38+
39+
#endif /* WATCHDOG_SYSTEM_H */

0 commit comments

Comments
 (0)