24#pragma GCC diagnostic push
25#pragma GCC diagnostic ignored "-Wpedantic"
27#pragma GCC diagnostic pop
30#pragma GCC diagnostic push
31#pragma GCC diagnostic ignored "-Wunused-parameter"
33#pragma GCC diagnostic pop
47#define mcp2515_motor mcp2515_DL
48#define mcp2515_BMS mcp2515_DL
136 for (uint8_t i = 0; i <
NUM_MCP; ++i)
140 MCPS[i].setNormalMode();
190 digitalWrite(
BUZZER, LOW);
191 digitalWrite(
FRG, LOW);
225 digitalWrite(
BUZZER, HIGH);
233 digitalWrite(
BUZZER, HIGH);
242 digitalWrite(
BUZZER, LOW);
243 digitalWrite(
FRG, HIGH);
Declaration of the BMS class for managing the Accumulator (Kclear BMS) via CAN bus.
Board configuration for the VCU (Vehicle Control Unit)
#define MCP2515_CRYSTAL_FREQ
Definition of the CarState structure representing the state of the car.
Definition of throttle and brake mapping tables.
constexpr TablePoint< uint16_t, int16_t > THROTTLE_TABLE[5]
Throttle mapping table (calculated), maps APPS_5V readings to torque values.
constexpr TablePoint< uint16_t, int16_t > BRAKE_TABLE[5]
Brake mapping table, negative values for regen.
Debugging macros and functions for serial and CAN output.
void DBGLN_GENERAL(const char *x)
Prints a line to the serial console for general debug.
Enumeration definitions for the VCU.
Declaration of the Pedal class for handling throttle and brake pedal inputs.
Declaration of the Scheduler class template, for scheduling tasks on multiple MCP2515 instances.
Declaration of the Telemetry class for sending telemetry data over CAN bus.
BMS class for managing the Accumulator (Kclear BMS) via CAN bus.
void checkHv()
Attempts to start HV. First check BMS is in standby(3) state, then send the HV start command....
void initFilter()
Initializes the CAN filters for reading BMS data. Call after constructing the BMS object and the MCP2...
Pedal class for managing throttle and brake pedal inputs. Handles filtering, fault detection,...
void update(uint16_t pedal_1, uint16_t pedal_2, uint16_t brake)
Updates pedal sensor readings, applies filtering, and checks for faults.
void sendFrame()
Sends the appropriate CAN frame to the motor based on pedal and car state.
bool initMotor()
Initializes the motor CAN communication by setting up cyclic reads for motor data and configuring CAN...
void initFilter()
Initializes the CAN filters for reading motor data. Call after constructing the Pedal object and the ...
void readMotor()
Reads motor data from the CAN bus and updates the CarState.
Scheduler class template for scheduling tasks on multiple MCP2515 instances Takes in function pointer...
Telemetry class for managing telemetry data transmission over CAN bus Grabs and sends telemetry frame...
void sendMotor()
Internal helper to get and send the motor telemetry frame.
void sendPedal()
Internal helper to get and send the Pedal telemetry frame.
void sendBms()
Internal helper to get and send the BMS telemetry frame.
Telemetry telem(mcp2515_DL, car)
Pedal pedal(mcp2515_DL, car, car.pedal.apps_5v)
void schedulerTelemetryPedal()
void schedulerPedalSend()
void schedulerMotorRead()
void setup()
Setup function for initializing the VCU system. Initializes MCP2515s, IO pins, as well as own modules...
constexpr uint8_t OUTPUT_COUNT
void schedulerTelemetryBms()
constexpr uint16_t BRAKE_THRESHOLD
constexpr uint8_t INPUT_COUNT
MCP2515 mcp2515_DL(CS_CAN_DL)
constexpr uint8_t NUM_MCP
constexpr uint16_t BMS_OVERRIDE_MILLIS
constexpr uint8_t pins_out[OUTPUT_COUNT]
struct CarState car
Global car state structure.
constexpr uint8_t pins_in[INPUT_COUNT]
constexpr uint16_t BUSSIN_MILLIS
void schedulerTelemetryMotor()
Scheduler< 3, NUM_MCP > scheduler(10000, 500, *micros)
void loop()
Main loop function for the VCU system. Handles car state transitions, pipes dataflow between modules.
void initialize(MCP2515 *can_interface)
Initializes the Debug_CAN interface. It should be called before using any other Debug_CAN functions.
void initialize()
Initializes the Debug_Serial interface. It should be called before using any other Debug_Serial funct...
Represents the state of the car. Holds telemetry data and status, used as central data sharing struct...
TelemetryFramePedal pedal
struct TelemetryFramePedal::StateByteStatus::Bits bits