Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hytech-racing/MCU
Browse files Browse the repository at this point in the history
  • Loading branch information
walkermburns committed Feb 8, 2024
2 parents 162f5a1 + 0a744bf commit d42f059
Show file tree
Hide file tree
Showing 26 changed files with 2,408 additions and 2,046 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ stateDiagram-v2
trac_sys_na : TRACTIVE_SYSTEM_NOT_ACTIVE
trac_sys_a : TRACTIVE_SYSTEM_ACTIVE
inv_en : ENABLING_INVERTERS
dt_q_dc_on : WAITING_DRIVETRAIN_QUIT_DC_ON
dt_en : WAITING_DRIVETRAIN_ENABLED
rtd_s : WAITING_READY_TO_DRIVE_SOUND
rtd : READY_TO_DRIVE
Expand All @@ -157,11 +155,7 @@ stateDiagram-v2
trac_sys_a --> trac_sys_na: drivetrain voltage _not_ over threshold
trac_sys_a --> inv_en: brake and start button pressed
inv_en --> trac_sys_na: drivetrain voltage _not_ over threshold
inv_en --> dt_q_dc_on: drivetrain ready
dt_q_dc_on --> trac_sys_a: drivetrain init timeout
dt_q_dc_on --> dt_en: drivetrain quit dc statuses on
dt_en --> trac_sys_a: drivetrain initialization timeout
dt_en --> rtd_s: drivetrain enabled
inv_en --> rtd_s: drivetrain enabled
rtd_s --> trac_sys_na: drivetrain voltage _not_ over threshold
rtd_s --> rtd: buzzer done buzzing
rtd --> trac_sys_na: drivetrain voltage _not_ over threshold
Expand Down
10 changes: 9 additions & 1 deletion lib/interfaces/include/InverterInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include "MC_temps.h"

#include "FlexCAN_T4.h"
#include "MCUInterface.h"

#include <Arduino.h>
struct InverterCommand
{
float torque_setpoint_nm;
Expand All @@ -19,10 +21,15 @@ template <typename message_queue>
class InverterInterface
{
public:
InverterInterface(message_queue *msg_output_queue, uint32_t can_id)
InverterInterface(message_queue *msg_output_queue, uint32_t can_id, int inverter_enable_pin, int inverter_24v_enable_pin)
{

msg_queue_ = msg_output_queue;
can_id_ = can_id;
pin_inv_en_ = inverter_enable_pin;
pin_inv_24V_en_ = inverter_24v_enable_pin;
pinMode(pin_inv_en_, OUTPUT);
pinMode(pin_inv_24V_en_, OUTPUT);
}

uint32_t get_id() { return can_id_; };
Expand Down Expand Up @@ -64,6 +71,7 @@ class InverterInterface
}

private:
int pin_inv_en_, pin_inv_24V_en_;
void write_cmd_msg_to_queue_(const MC_setpoints_command &msg);
int16_t speed_;
uint16_t dc_bus_voltage_;
Expand Down
7 changes: 4 additions & 3 deletions lib/interfaces/include/InverterInterface.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ void InverterInterface<message_queue>::write_cmd_msg_to_queue_(const MC_setpoint
msg.id = can_id_;
msg.len = sizeof(msg_in);
uint8_t buf[sizeof(CAN_message_t)];
memmove(buf, &msg, sizeof(msg_in));
msg_in.write(msg.buf);
msg_queue_->push_back(msg, sizeof(CAN_message_t));
memmove(buf, &msg, sizeof(msg_in));
msg_queue_->push_back(buf, sizeof(CAN_message_t));
}

template <typename message_queue>
void InverterInterface<message_queue>::request_enable_hv()
{

digitalWrite(pin_inv_en_, HIGH);
digitalWrite(pin_inv_24V_en_, HIGH);
MC_setpoints_command mc_setpoints_command{};
mc_setpoints_command.set_hv_enable(true);
write_cmd_msg_to_queue_(mc_setpoints_command);
Expand Down
59 changes: 24 additions & 35 deletions lib/interfaces/include/MCUInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@
#include "SysClock.h"
// #include "MCUStateMachine.h"

const int DEFAULT_BMS_OK_READ = 5; // SHDN_D_READ
const int DEFAULT_IMD_OK_READ = 4; // SHDN_C_READ
const int DEFAULT_BSPD_OK_READ = 6; // SHDN_E_READ
const int DEFAULT_SOFTWARE_OK_READ = 25; // SHDN_F_READ Watchdog Combined
const int DEFAULT_BOTS_OK_READ = 3; // SHDN_B_READ
const int DEFAULT_BRAKE_LIGHT_CTRL = 7;
const int DEFAULT_INVERTER_EN = 9;
const int DEFAULT_INVERTER_24V_EN = 8;
const int DEFAULT_BMS_OK_READ = 5; // SHDN_D_READ
const int DEFAULT_IMD_OK_READ = 4; // SHDN_C_READ
const int DEFAULT_BSPD_OK_READ = 6; // SHDN_E_READ
const int DEFAULT_SOFTWARE_OK_READ = 25; // SHDN_F_READ Watchdog Combined
const int DEFAULT_BOTS_OK_READ = 3; // SHDN_B_READ
const int DEFAULT_BRAKE_LIGHT_CTRL = 7;

class MCUInterface
{
private:

CANBufferType *msg_queue_;
int pin_bms_ok_read_;
int pin_imd_ok_read_;
int pin_bspd_ok_read_;
int pin_software_ok_read_;
int pin_bots_ok_read_;
int pin_brake_light_ctrl_;
/* Private utility functions */
void measure_shutdown_circuit_input();
void measure_shutdown_circuit_voltage();
Expand All @@ -29,7 +35,6 @@ class MCUInterface
/* Outbound CAN message */
MCU_status mcu_status_;
/* CAN Tx buffer */
CANBufferType *msg_queue_;

/* Shutdown circuit input */
bool bms_ok_high;
Expand All @@ -43,44 +48,29 @@ class MCUInterface
bool shutdown_e_above_threshold;

/* Hardware interface pins */
int pin_bms_ok_read_;
int pin_imd_ok_read_;
int pin_bspd_ok_read_;
int pin_software_ok_read_;
int pin_bots_ok_read_;
int pin_brake_light_ctrl_;
int pin_inv_en_;
int pin_inv_24V_en_;


public:
MCUInterface(CANBufferType *msg_output_queue, int bms_pin, int imd_pin, int bspd_pin, int sw_ok_pin, int bots_ok_pin, int brake_light_pin, int inv_pin, int inv_24V_pin):
msg_queue_(msg_output_queue),
pin_bms_ok_read_(bms_pin),
pin_imd_ok_read_(imd_pin),
pin_bspd_ok_read_(bspd_pin),
pin_software_ok_read_(sw_ok_pin),
pin_bots_ok_read_(bots_ok_pin),
pin_brake_light_ctrl_(brake_light_pin),
pin_inv_en_(inv_pin),
pin_inv_24V_en_(inv_24V_pin)
MCUInterface(CANBufferType *msg_output_queue, int bms_pin, int imd_pin, int bspd_pin, int sw_ok_pin, int bots_ok_pin, int brake_light_pin): msg_queue_(msg_output_queue),
pin_bms_ok_read_(bms_pin),
pin_imd_ok_read_(imd_pin),
pin_bspd_ok_read_(bspd_pin),
pin_software_ok_read_(sw_ok_pin),
pin_bots_ok_read_(bots_ok_pin),
pin_brake_light_ctrl_(brake_light_pin)
{
// Set pin mode
pinMode(pin_brake_light_ctrl_, OUTPUT);
pinMode(pin_inv_en_, OUTPUT);
pinMode(pin_inv_24V_en_, OUTPUT);
};
MCUInterface(CANBufferType *msg_output_queue):
MCUInterface(msg_output_queue, DEFAULT_BMS_OK_READ, DEFAULT_IMD_OK_READ, DEFAULT_BSPD_OK_READ, DEFAULT_SOFTWARE_OK_READ, DEFAULT_BOTS_OK_READ, DEFAULT_BRAKE_LIGHT_CTRL, DEFAULT_INVERTER_EN, DEFAULT_INVERTER_24V_EN) {};
MCUInterface(CANBufferType *msg_output_queue) : MCUInterface(msg_output_queue, DEFAULT_BMS_OK_READ, DEFAULT_IMD_OK_READ, DEFAULT_BSPD_OK_READ, DEFAULT_SOFTWARE_OK_READ, DEFAULT_BOTS_OK_READ, DEFAULT_BRAKE_LIGHT_CTRL){};

/* Initialize shutdown circuit input readings */
void init();

/* Read from Main ECU */
void read_mcu_status();
/* Write to Main ECU */
void set_inverter_enable(bool enable); // Called from DrivetrainSystem
void set_inverter_24V_enable(bool enable_24V); // Called from DrivetrainSystem
void set_brake_light(bool brake_pedal_is_active); // Called from PedalInterface/System
void set_brake_light(bool brake_pedal_is_active); // Called from PedalInterface/System

/* Feed to state machine */
bool bms_ok_is_high();
Expand Down Expand Up @@ -114,7 +104,6 @@ class MCUInterface
// bool pack_charge_is_critical,
// bool button_is_pressed
// );

};

#endif /* __MCU_INTERFACE_H__ */
6 changes: 3 additions & 3 deletions lib/interfaces/include/SysClock.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ struct TriggerBits_s

struct SysTick_s
{
long millis;
long micros;
unsigned long millis;
unsigned long micros;
TriggerBits_s triggers;
};

class SysClock
{
private:
enum TriggerIndices_s
enum TriggerIndices_e
{
TRIG_1000 = 0,
TRIG_500 = 1,
Expand Down
16 changes: 0 additions & 16 deletions lib/interfaces/src/MCUInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ void MCUInterface::init() {

// Enable inverters (?)
// Should be called from drivetrain
digitalWrite(pin_inv_en_, HIGH);
digitalWrite(pin_inv_24V_en_, HIGH);
}

/* Read shutdown system values */
Expand Down Expand Up @@ -43,20 +41,6 @@ void MCUInterface::measure_shutdown_circuit_voltage() {

}

/* Write inverter enable */
void MCUInterface::set_inverter_enable(bool enable) {

digitalWrite(pin_inv_en_, enable);

}

/* Write inverter 24V enable */
void MCUInterface::set_inverter_24V_enable(bool enable_24V) {

digitalWrite(pin_inv_24V_en_, enable_24V);

}

/* Write brake light */
void MCUInterface::set_brake_light(bool brake_pedal_is_active) {

Expand Down
17 changes: 10 additions & 7 deletions lib/state_machine/include/MCUStateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,26 @@ enum class CAR_STATE
TRACTIVE_SYSTEM_NOT_ACTIVE = 1,
TRACTIVE_SYSTEM_ACTIVE = 2,
ENABLING_INVERTERS = 3,
WAITING_DRIVETRAIN_QUIT_DC_ON = 4,
WAITING_DRIVETRAIN_ENABLED = 5,
WAITING_READY_TO_DRIVE_SOUND = 6,
READY_TO_DRIVE = 7
WAITING_READY_TO_DRIVE_SOUND = 4,
READY_TO_DRIVE = 5
};

template <typename DrivetrainSysType>
class MCUStateMachine
{
public:
MCUStateMachine(BuzzerController *buzzer, DrivetrainSysType *drivetrain, DashboardInterface *dashboard, PedalsSystem *pedals)
MCUStateMachine(BuzzerController *buzzer,
DrivetrainSysType *drivetrain,
DashboardInterface *dashboard,
PedalsSystem *pedals,
TorqueControllerMux *mux)
{
current_state_ = CAR_STATE::STARTUP;
buzzer_ = buzzer;
drivetrain_ = drivetrain;
dashboard_ = dashboard;
pedals_ = pedals;
controller_mux_ = mux;
}

/// @brief our components can use this time to tell when to do things. We can set this ourselves for testing purposes instead of using metro timers
Expand Down Expand Up @@ -65,8 +69,7 @@ class MCUStateMachine
AMSInterface *bms_;
// IMDInterface *imd_;

TorqueControllerMux* controller_mux_;

TorqueControllerMux *controller_mux_;
};
#include "MCUStateMachine.tpp"
#endif /* MCUSTATEMACHINE */
Loading

0 comments on commit d42f059

Please sign in to comment.