Skip to content

Commit

Permalink
Tests and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
walkermburns committed Feb 9, 2024
1 parent a1d60c7 commit 3b914a6
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 28 deletions.
27 changes: 14 additions & 13 deletions lib/interfaces/include/MCUInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class MCUInterface

/* Outbound CAN message */
MCU_status mcu_status_;
/* CAN Tx buffer */

/* Shutdown circuit input */
bool bms_ok_high;
Expand All @@ -50,21 +49,24 @@ class MCUInterface


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):


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),
// PLEASE replace these long lists of parameters with structs
// and put initialization in constructor body instead of initializer list
// my retinas are in pain
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)
// Member initialization list
: 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);
};
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){};

MCUInterface(CANBufferType *msg_output_queue)
// Overloading constructor
: 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();
Expand Down Expand Up @@ -102,8 +104,7 @@ class MCUInterface
bool software_is_ok,
bool buzzer_is_on,
bool pack_charge_is_critical,
bool button_is_pressed
);
bool button_is_pressed);
};

#endif /* __MCU_INTERFACE_H__ */
2 changes: 1 addition & 1 deletion lib/interfaces/src/MCUInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void MCUInterface::init() {
// Should be called from drivetrain
}

/* Read shutdown system values */
/* Read shutdown system values (Not ticked, just in main loop)*/
void MCUInterface::read_mcu_status() {

measure_shutdown_circuit_input();
Expand Down
18 changes: 14 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,27 @@
/* State machine */
#include "MCUStateMachine.h"

/* External info sources */
/*
DATA SOURCES
*/

/* Two CAN lines on Main ECU rev15 */
FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> INV_CAN; // Inverter CAN (now both are on same line)
FlexCAN_T4<CAN3, RX_SIZE_256, TX_SIZE_16> TELEM_CAN; // telemetry CAN (basically everything except inverters)

/* Set up CAN circular buffer */
using CircularBufferType = Circular_Buffer<uint8_t, (uint32_t)16, sizeof(CAN_message_t)>;

/* Sensors */
MCP_ADC<8> ADC1(ADC1_CS);
MCP_ADC<4> ADC2(ADC2_CS);
MCP_ADC<4> ADC3(ADC3_CS);
OrbisBR10 steering1(STEERING_SERIAL);

/* Declare interfaces */
/*
INTERFACES
*/

DashboardInterface dashboard(&CAN2_txBuffer);
AMSInterface ams_interface(SOFTWARE_OK);
WatchdogInterface wd_interface(WATCHDOG_INPUT);
Expand All @@ -55,12 +62,15 @@ InverterInterfaceType fr_inv(&CAN2_txBuffer, ID_MC2_SETPOINTS_COMMAND, 9, 8);
InverterInterfaceType rl_inv(&CAN2_txBuffer, ID_MC3_SETPOINTS_COMMAND, 9, 8);
InverterInterfaceType rr_inv(&CAN2_txBuffer, ID_MC4_SETPOINTS_COMMAND, 9, 8);

/* Declare systems */
/*
SYSTEMS
*/

SysClock sys_clock;
SteeringSystem steering_system(&steering1); // Unify member reference and pointers? tied by reference in this case
BuzzerController buzzer(BUZZER_ON_INTERVAL);
SafetySystem safety_system(&ams_interface, &wd_interface); // Tie ams and wd interface to safety system (by pointers)
PedalsSystem pedals_system({100, 100, 3000, 3000, 0.1}, {100, 100, 3000, 3000, 0.05});
SteeringSystem steering_system(&steering1); // Unify member reference and pointers? tied by reference in this case
using DrivetrainSystemType = DrivetrainSystem<InverterInterfaceType>;
auto drivetrain = DrivetrainSystemType({&fl_inv, &fr_inv, &rl_inv, &rr_inv}, INVERTER_ENABLING_TIMEOUT_INTERVAL); // Tie inverter interfaces to drivetrain system (by pointers)
/*
Expand Down
7 changes: 7 additions & 0 deletions test/test_interfaces/AMS_interface_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ void test_AMS_heartbeat()
TEST_ASSERT_EQUAL(true, ams_interface.heartbeat_received(millis()));
delay(20);
TEST_ASSERT_EQUAL(false, ams_interface.heartbeat_received(millis()));

ams_interface.set_heartbeat(millis());
TEST_ASSERT_EQUAL(true, ams_interface.heartbeat_received(millis()));
delay(19);
TEST_ASSERT_EQUAL(true, ams_interface.heartbeat_received(millis()));
delay(1);
TEST_ASSERT_EQUAL(false, ams_interface.heartbeat_received(millis()));
}
16 changes: 16 additions & 0 deletions test/test_interfaces/MCU_interface_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,19 @@

#include "MCUInterface.h"

Circular_Buffer <uint8_t, (uint32_t)16, sizeof(CAN_message_t)> mcu_CAN_buffer;

MCUInterface mcu_interface(&mcu_CAN_buffer);

void test_set_brake_light(void)
{
mcu_interface.set_brake_light(true);
TEST_ASSERT_EQUAL(HIGH, digitalRead(7));
mcu_interface.set_brake_light(false);
TEST_ASSERT_EQUAL(LOW, digitalRead(7));
}

void test_mcu_circular_buffer(void)
{

}
10 changes: 5 additions & 5 deletions test/test_interfaces/dashboard_interface_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "hytech.h"
#include "DashboardInterface.h"

Circular_Buffer <uint8_t, (uint32_t)16, sizeof(CAN_message_t)> CAN_buffer;
Circular_Buffer <uint8_t, (uint32_t)16, sizeof(CAN_message_t)> dash_CAN_buffer;

/* CHAT GPT FUNCTIONS */
void printMemoryHex(void* ptr, size_t length) {
Expand All @@ -22,7 +22,7 @@ void printMemoryHex(void* ptr, size_t length) {

void test_dashboard_unpacking_can_message(void)
{
DashboardInterface dash_interface(&CAN_buffer);
DashboardInterface dash_interface(&dash_CAN_buffer);

// Chat GPT code that iterates through a truth table
for (int i = 0; i < (1 << 10); ++i) { // 2^10 possible combinations
Expand Down Expand Up @@ -63,8 +63,8 @@ void test_dashboard_unpacking_can_message(void)
void test_dashboard_circular_buffer(void)
{

Circular_Buffer <uint8_t, (uint32_t)16, sizeof(CAN_message_t)> CAN_buffer_2;
DashboardInterface dash_interface(&CAN_buffer_2);
Circular_Buffer <uint8_t, (uint32_t)16, sizeof(CAN_message_t)> dash_CAN_buffer_2;
DashboardInterface dash_interface(&dash_CAN_buffer_2);

uint8_t LED[12] = {};

Expand Down Expand Up @@ -110,7 +110,7 @@ void test_dashboard_circular_buffer(void)
CAN_message_t packed_message = dash_interface.write();

uint8_t buffer[sizeof(CAN_message_t)];
CAN_buffer_2.pop_front(buffer, sizeof(CAN_message_t));
dash_CAN_buffer_2.pop_front(buffer, sizeof(CAN_message_t));

delay(1000);

Expand Down
13 changes: 8 additions & 5 deletions test/test_interfaces/run_embedded_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
#include "AMS_interface_test.h"
#include "dashboard_interface_test.h"
#include "Watchdog_interface_test.h"
#include "can_interface_test.h"
#include "MCU_interface_test.h"
// #include "can_interface_test.h"

void setUp(void)
{
init_can_interface();
// init_can_interface();
}

void tearDown(void)
Expand All @@ -26,9 +27,11 @@ int runUnityTests(void)
RUN_TEST(test_AMS_heartbeat);
/* TEST WATCHDOG */
RUN_TEST(test_watchdog_kick);
// testing can interface
RUN_TEST(test_can_interface_send)
RUN_TEST(test_can_interface_send_and_receive_raw)
/* TEST CAN INTERFACE */
// RUN_TEST(test_can_interface_send)
// RUN_TEST(test_can_interface_send_and_receive_raw)
/* TEST MCU */
RUN_TEST(test_set_brake_light);

return UNITY_END();
}
Expand Down

0 comments on commit 3b914a6

Please sign in to comment.