Red Bird Racing VCU v2
 
Loading...
Searching...
No Matches
main.cpp File Reference

Main VCU program entry point. More...

#include <Arduino.h>
#include "BoardConfig.h"
#include "Pedal.hpp"
#include "BMS.hpp"
#include "Enums.hpp"
#include "CarState.hpp"
#include "Scheduler.hpp"
#include "Curves.hpp"
#include "Telemetry.hpp"
#include "Debug.hpp"
#include <mcp2515.h>
Include dependency graph for main.cpp:

Go to the source code of this file.

Macros

#define mcp2515_motor   mcp2515_DL
 
#define mcp2515_BMS   mcp2515_DL
 

Functions

MCP2515 mcp2515_motor (CS_CAN_MOTOR)
 
MCP2515 mcp2515_BMS (CS_CAN_BMS)
 
MCP2515 mcp2515_DL (CS_CAN_DL)
 
Pedal pedal (mcp2515_DL, car, car.pedal.apps_5v)
 
void schedulerMotorRead ()
 
void schedulerPedalSend ()
 
void scheduler_bms ()
 
void schedulerTelemetryPedal ()
 
void schedulerTelemetryMotor ()
 
void schedulerTelemetryBms ()
 
void setup ()
 Setup function for initializing the VCU system. Initializes MCP2515s, IO pins, as well as own modules such as Pedal and Debug.
 
void loop ()
 Main loop function for the VCU system. Handles car state transitions, pipes dataflow between modules.
 

Variables

constexpr uint8_t INPUT_COUNT = 5
 
constexpr uint8_t OUTPUT_COUNT = 3
 
constexpr uint8_t pins_in [INPUT_COUNT] = {DRIVE_MODE_BTN, BRAKE_IN, APPS_5V, APPS_3V3, HALL_SENSOR}
 
constexpr uint8_t pins_out [OUTPUT_COUNT] = {FRG, BRAKE_LIGHT, BUZZER}
 
constexpr uint8_t NUM_MCP = 3
 
MCP2515 MCPS [NUM_MCP] = { mcp2515_DL , mcp2515_DL , mcp2515_DL}
 
constexpr uint16_t BUSSIN_MILLIS = 2000
 
constexpr uint16_t BMS_OVERRIDE_MILLIS = 1000
 
constexpr uint16_t BRAKE_THRESHOLD = BRAKE_TABLE[0].in
 
bool brake_pressed = false
 
struct CarState car
 Global car state structure.
 
BMS bms (mcp2515_DL, car)
 
Telemetry telem (mcp2515_DL, car)
 
Scheduler< 3, NUM_MCPscheduler (10000, 500, *micros)
 

Detailed Description

Main VCU program entry point.

Author
Planeson, Chiho, Red Bird Racing
Version
2.2.1
Date
2026-02-25

Definition in file main.cpp.

Macro Definition Documentation

◆ mcp2515_BMS

#define mcp2515_BMS   mcp2515_DL

Definition at line 48 of file main.cpp.

◆ mcp2515_motor

#define mcp2515_motor   mcp2515_DL

Definition at line 47 of file main.cpp.

Function Documentation

◆ loop()

◆ mcp2515_BMS()

MCP2515 mcp2515_BMS ( CS_CAN_BMS  )

◆ mcp2515_DL()

MCP2515 mcp2515_DL ( CS_CAN_DL  )

Referenced by setup().

Here is the caller graph for this function:

◆ mcp2515_motor()

MCP2515 mcp2515_motor ( CS_CAN_MOTOR  )

◆ pedal()

Pedal pedal ( mcp2515_DL  ,
car  ,
car.pedal.  apps_5v 
)

Referenced by loop(), Pedal::pedalTorqueMapping(), schedulerMotorRead(), schedulerPedalSend(), and setup().

Here is the caller graph for this function:

◆ scheduler_bms()

void scheduler_bms ( )

Definition at line 86 of file main.cpp.

References bms, and BMS::checkHv().

Referenced by loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedulerMotorRead()

void schedulerMotorRead ( )

Definition at line 78 of file main.cpp.

References pedal(), and Pedal::readMotor().

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedulerPedalSend()

void schedulerPedalSend ( )

Definition at line 82 of file main.cpp.

References pedal(), and Pedal::sendFrame().

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedulerTelemetryBms()

void schedulerTelemetryBms ( )

Definition at line 98 of file main.cpp.

References Telemetry::sendBms(), and telem.

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedulerTelemetryMotor()

void schedulerTelemetryMotor ( )

Definition at line 94 of file main.cpp.

References Telemetry::sendMotor(), and telem.

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedulerTelemetryPedal()

void schedulerTelemetryPedal ( )

Definition at line 90 of file main.cpp.

References Telemetry::sendPedal(), and telem.

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup()

void setup ( )

Setup function for initializing the VCU system. Initializes MCP2515s, IO pins, as well as own modules such as Pedal and Debug.

Definition at line 113 of file main.cpp.

References bms, CAN_RATE, Datalogger, DBGLN_GENERAL(), BMS::initFilter(), Pedal::initFilter(), Debug_Serial::initialize(), Debug_CAN::initialize(), Pedal::initMotor(), INPUT_COUNT, MCP2515_CRYSTAL_FREQ, mcp2515_DL(), MCPS, Motor, NUM_MCP, OUTPUT_COUNT, pedal(), pins_in, pins_out, scheduler, schedulerMotorRead(), schedulerPedalSend(), schedulerTelemetryBms(), schedulerTelemetryMotor(), and schedulerTelemetryPedal().

Here is the call graph for this function:

Variable Documentation

◆ bms

BMS bms(mcp2515_DL, car) ( mcp2515_DL  ,
car   
)

Referenced by scheduler_bms(), and setup().

◆ BMS_OVERRIDE_MILLIS

constexpr uint16_t BMS_OVERRIDE_MILLIS = 1000
constexpr

Definition at line 55 of file main.cpp.

Referenced by loop().

◆ brake_pressed

bool brake_pressed = false

Definition at line 59 of file main.cpp.

Referenced by loop().

◆ BRAKE_THRESHOLD

constexpr uint16_t BRAKE_THRESHOLD = BRAKE_TABLE[0].in
constexpr

Definition at line 57 of file main.cpp.

Referenced by loop().

◆ BUSSIN_MILLIS

constexpr uint16_t BUSSIN_MILLIS = 2000
constexpr

Definition at line 54 of file main.cpp.

Referenced by loop().

◆ car

struct CarState car
Initial value:
= {
{},
{},
{},
0,
0
}

Global car state structure.

See also
CarState

Definition at line 65 of file main.cpp.

Referenced by loop().

◆ INPUT_COUNT

constexpr uint8_t INPUT_COUNT = 5
constexpr

Definition at line 37 of file main.cpp.

Referenced by setup().

◆ MCPS

MCP2515 MCPS[NUM_MCP] = { mcp2515_DL , mcp2515_DL , mcp2515_DL}

Definition at line 52 of file main.cpp.

Referenced by setup().

◆ NUM_MCP

constexpr uint8_t NUM_MCP = 3
constexpr

Definition at line 51 of file main.cpp.

Referenced by setup().

◆ OUTPUT_COUNT

constexpr uint8_t OUTPUT_COUNT = 3
constexpr

Definition at line 38 of file main.cpp.

Referenced by setup().

◆ pins_in

constexpr uint8_t pins_in[INPUT_COUNT] = {DRIVE_MODE_BTN, BRAKE_IN, APPS_5V, APPS_3V3, HALL_SENSOR}
constexpr

Definition at line 39 of file main.cpp.

Referenced by setup().

◆ pins_out

constexpr uint8_t pins_out[OUTPUT_COUNT] = {FRG, BRAKE_LIGHT, BUZZER}
constexpr

Definition at line 40 of file main.cpp.

Referenced by setup().

◆ scheduler

Scheduler< 3, NUM_MCP > scheduler(10000, 500, *micros) ( 10000  ,
500  ,
micros 
)

Referenced by loop(), and setup().

◆ telem