From 8959b573d99d60637218a1d23f768f811083a4de Mon Sep 17 00:00:00 2001 From: Lucas Plant Date: Sun, 14 Jan 2024 18:40:44 -0600 Subject: [PATCH 01/19] Initial draft of the pedal unit testing structure --- test/test_yo/pedals_system_test.cpp | 120 ++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 test/test_yo/pedals_system_test.cpp diff --git a/test/test_yo/pedals_system_test.cpp b/test/test_yo/pedals_system_test.cpp new file mode 100644 index 000000000..2baf99e66 --- /dev/null +++ b/test/test_yo/pedals_system_test.cpp @@ -0,0 +1,120 @@ +/* +basic test cases for the pedals component class +version 1.0 +rough draft +author: Lucas Plant +*/ +#include +#include +#include + +/* +ToDo: + edit pedals system file to accommodate friend wrapper + methods to test: + constructor + evaluate pedals + linearize_accel_pedal_values_ + evaluate pedal_implausibilities_ + evaluate_brake_and_accel_pressed_ + pedal_is_active + + +*/ + +class PedalsFriend { + //friend class to allow access to private fields of Pedals system + public: + static std::tuple access_linearize_accel_pedal_values_(PedalsComponent& pedals_component, int accel1, int accel2) + { + return pedals_component.linearize_accel_pedal_values_(accel1, accel2) + } + + static bool access_evaluate_pedal_implausibilities_(PedalsComponent& pedals_component, int sense_1, int sense_2, const PedalsParams ¶ms, float max_percent_differnce) + { + return pedals_component.evaluate_pedal_implausibilities_(sense_1, sense_2, params, max_percent_differnce) + } + + static bool access_evaluate_brake_and_accel_pressed_(PedalsComponent& pedals_component, const PedalsDriverInterface &data) + { + return pedals_component.evaluate_brake_and_accel_pressed_(data) + } + + static bool access_pedal_is_active_(PedalsComponent& pedalsComponent pedals_component, int sense1, int sense_2, const PedalsParams& pedalParams, float percent_threshold) + { + return pedal_is_active(PedalsComponent pedalsComponent pedals_component, int sense1, int sense_2, const PedalsParams& pedalParams, percent_threshold) + } + + static PedalsParams access_accel_pedals_params(PedalsComponent& pedals_component) + { + return pedals_component.accelParams_ + } + + static PedalsParams access_brake_pedals_params(PedalsComponent& pedals_component) + { + return pedals_component.brakeParams_ + } +} + +void setUp(void) +{ + //declare a component obj + //possibly make temp class that is a freind class of PedalsComponent to access private members + //possibly modify the + + PedalsComponent pedals_component; + +} + +void tearDown(void) +{ + +} + +struct PedalIsActiveTestCase { + //defines input and output params + + //input params + int sense1; + int sense2; + //for now the pedalsparams will be kept constant however this can become a part of the tests as well + float percent_threshold; + + //expected output + bool expect_active; +} +void test_pedal_is_active_(void) +{ + //define the test cases in a vector + std::vector test_cases = { + {1, 1, 1, true} + //add more test cases later on + }; + + PedalsParams params_for_test = {1, 1, 10, 10, 5, 5, 7, 7} + + for (const auto& test_case : test_cases) { + out = pedal_activePedalsFriend::access_pedal_is_active_(pedals_component, test_case.sense1, test_case.sense2, params_for_test, test_case.percent_threshold); + TEST_ASSERT_EQUAL(test_case.expect_active, out) + } +} + +/* +void test_evaluate_brake_and_accel_pressed(void) +{ + PedalsDriverInterface data = {} + PedalsFriend(pedal_component, data) +} +*/ + + + +int main() { + + UNITY_BEGIN(); + + //tests go here + + + UNITY_END(); +} \ No newline at end of file From b29547c44b2cc0be93ca5db4f13b022ebce2bdfb Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Fri, 26 Jan 2024 02:40:33 -0500 Subject: [PATCH 02/19] adding in beginnings of the test environment --- README.md | 30 +++++++++++++++++++ lib/mock_interfaces/AMSInterface.h | 5 ++++ lib/mock_interfaces/DashboardInterface.h | 5 ++++ lib/mock_interfaces/IMDInterface.h | 5 ++++ lib/mock_interfaces/InverterInterface.h | 5 ++++ lib/state_machine/include/MCUStateMachine.h | 2 +- lib/state_machine/include/MCUStateMachine.tpp | 28 ++++++++++------- platformio.ini | 11 ++++--- src/main.cpp | 1 - test/DashboardInterface.h | 5 ++++ test/InverterInterface.h | 5 ++++ .../test_str.cpp => state_machine_test.cpp} | 14 ++++----- 12 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 lib/mock_interfaces/AMSInterface.h create mode 100644 lib/mock_interfaces/DashboardInterface.h create mode 100644 lib/mock_interfaces/IMDInterface.h create mode 100644 lib/mock_interfaces/InverterInterface.h create mode 100644 test/DashboardInterface.h create mode 100644 test/InverterInterface.h rename test/{test_yo/test_str.cpp => state_machine_test.cpp} (55%) diff --git a/README.md b/README.md index ce2776979..edfa087fd 100644 --- a/README.md +++ b/README.md @@ -159,4 +159,34 @@ classDiagram Sensor <|-- SteeringSensor : implements Sensor <|-- CurrentSensor : implements +``` + + +### state machine documentation + +```mermaid +stateDiagram-v2 + startup : STARTUP + 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 + + startup --> trac_sys_na: first tick of state machine + trac_sys_na --> trac_sys_a: drivetrain voltage over threshold + 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 + 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 + rtd --> trac_sys_a: drivetrain error occured ``` \ No newline at end of file diff --git a/lib/mock_interfaces/AMSInterface.h b/lib/mock_interfaces/AMSInterface.h new file mode 100644 index 000000000..fda7b19b7 --- /dev/null +++ b/lib/mock_interfaces/AMSInterface.h @@ -0,0 +1,5 @@ +#ifndef AMSINTERFACE +#define AMSINTERFACE + + +#endif /* AMSINTERFACE */ diff --git a/lib/mock_interfaces/DashboardInterface.h b/lib/mock_interfaces/DashboardInterface.h new file mode 100644 index 000000000..2a0d21278 --- /dev/null +++ b/lib/mock_interfaces/DashboardInterface.h @@ -0,0 +1,5 @@ +#ifndef DASHBOARDINTERFACE +#define DASHBOARDINTERFACE + + +#endif /* DASHBOARDINTERFACE */ diff --git a/lib/mock_interfaces/IMDInterface.h b/lib/mock_interfaces/IMDInterface.h new file mode 100644 index 000000000..938918129 --- /dev/null +++ b/lib/mock_interfaces/IMDInterface.h @@ -0,0 +1,5 @@ +#ifndef IMDINTERFACE +#define IMDINTERFACE + + +#endif /* IMDINTERFACE */ diff --git a/lib/mock_interfaces/InverterInterface.h b/lib/mock_interfaces/InverterInterface.h new file mode 100644 index 000000000..92073b460 --- /dev/null +++ b/lib/mock_interfaces/InverterInterface.h @@ -0,0 +1,5 @@ +#ifndef INVERTERINTERFACE +#define INVERTERINTERFACE + + +#endif /* INVERTERINTERFACE */ diff --git a/lib/state_machine/include/MCUStateMachine.h b/lib/state_machine/include/MCUStateMachine.h index 289aa15bd..883541e53 100644 --- a/lib/state_machine/include/MCUStateMachine.h +++ b/lib/state_machine/include/MCUStateMachine.h @@ -16,7 +16,7 @@ enum class CAR_STATE STARTUP = 0, TRACTIVE_SYSTEM_NOT_ACTIVE = 1, TRACTIVE_SYSTEM_ACTIVE = 2, - ENABLING_INVERTER = 3, + ENABLING_INVERTERS = 3, WAITING_DRIVETRAIN_QUIT_DC_ON = 4, WAITING_DRIVETRAIN_ENABLED = 5, WAITING_READY_TO_DRIVE_SOUND = 6, diff --git a/lib/state_machine/include/MCUStateMachine.tpp b/lib/state_machine/include/MCUStateMachine.tpp index dc06f208a..81181efe4 100644 --- a/lib/state_machine/include/MCUStateMachine.tpp +++ b/lib/state_machine/include/MCUStateMachine.tpp @@ -6,6 +6,7 @@ void MCUStateMachine::tick_state_machine(unsigned long cur switch (get_state()) { case CAR_STATE::STARTUP: + set_state_(CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE); break; case CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE: @@ -27,19 +28,19 @@ void MCUStateMachine::tick_state_machine(unsigned long cur } if (dashboard_->start_button_pressed() && pedals_->mech_brake_active()) { - set_state_(CAR_STATE::ENABLING_INVERTER, current_millis); + set_state_(CAR_STATE::ENABLING_INVERTERS, current_millis); break; } break; } - case CAR_STATE::ENABLING_INVERTER: + case CAR_STATE::ENABLING_INVERTERS: { // TODO handle the drivetrain state change back to startup phase 1 and/or move this into // the drivetrain state machine handling if (!drivetrain_->hv_over_threshold_on_drivetrain()) { - set_state_(CAR_STATE::TRACTIVE_SYSTEM_ACTIVE, current_millis); + set_state_(CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE, current_millis); break; } @@ -59,10 +60,12 @@ void MCUStateMachine::tick_state_machine(unsigned long cur set_state_(CAR_STATE::WAITING_DRIVETRAIN_ENABLED, current_millis); break; } - else + else if(drivetrain_->inverter_init_timeout(current_millis)) { set_state_(CAR_STATE::TRACTIVE_SYSTEM_ACTIVE, current_millis); break; + } else { + break; } break; } @@ -72,19 +75,21 @@ void MCUStateMachine::tick_state_machine(unsigned long cur { set_state_(CAR_STATE::WAITING_READY_TO_DRIVE_SOUND, current_millis); } - else + else if (drivetrain_->inverter_init_timeout(current_millis)) { set_state_(CAR_STATE::TRACTIVE_SYSTEM_ACTIVE, current_millis); break; + } else { + break; } } case CAR_STATE::WAITING_READY_TO_DRIVE_SOUND: { // TODO handle the drivetrain state change back to startup phase 1 and/or move this into // the drivetrain state machine handling - if (drivetrain_->hv_over_threshold_on_drivetrain()) + if (!drivetrain_->hv_over_threshold_on_drivetrain()) { - set_state_(CAR_STATE::TRACTIVE_SYSTEM_ACTIVE, current_millis); + set_state_(CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE, current_millis); break; } @@ -100,15 +105,16 @@ void MCUStateMachine::tick_state_machine(unsigned long cur { // TODO handle the drivetrain state change back to startup phase 1 and/or move this into // the drivetrain state machine handling - if (drivetrain_->hv_over_threshold_on_drivetrain()) + if (!drivetrain_->hv_over_threshold_on_drivetrain()) { - set_state_(CAR_STATE::TRACTIVE_SYSTEM_ACTIVE, current_millis); + set_state_(CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE, current_millis); break; } if (drivetrain_->drivetrain_error_occured()) { set_state_(CAR_STATE::TRACTIVE_SYSTEM_ACTIVE, current_millis); + break; } PedalsDriverInterface data; @@ -163,7 +169,7 @@ void MCUStateMachine::handle_exit_logic_(CAR_STATE prev_st break; case CAR_STATE::TRACTIVE_SYSTEM_ACTIVE: break; - case CAR_STATE::ENABLING_INVERTER: + case CAR_STATE::ENABLING_INVERTERS: break; case CAR_STATE::WAITING_DRIVETRAIN_QUIT_DC_ON: break; @@ -190,7 +196,7 @@ void MCUStateMachine::handle_entry_logic_(CAR_STATE new_st case CAR_STATE::TRACTIVE_SYSTEM_ACTIVE: break; - case CAR_STATE::ENABLING_INVERTER: + case CAR_STATE::ENABLING_INVERTERS: { break; } diff --git a/platformio.ini b/platformio.ini index a60ce2e20..2181a453c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,9 +1,10 @@ [env:test] platform = native - build_src_filter = -<**/*.c> -<**/*.cpp> +lib_ignore = + interfaces [env:teensy41] ; including only the current main file for compiling to keep old main still around for now while @@ -18,10 +19,12 @@ board = teensy41 framework = arduino upload_protocol = teensy-cli extra_scripts = pre:extra_script.py -lib_deps = +lib_ignore = + mock_interfaces +lib_deps = SPI - https://github.com/RCMast3r/variant.git#single-header https://github.com/tonton81/FlexCAN_T4 - https://github.com/RCMast3r/hytech_can https://github.com/RCMast3r/spi_libs + https://github.com/RCMast3r/hytech_can https://github.com/juchong/ADIS16460-Arduino-Teensy + diff --git a/src/main.cpp b/src/main.cpp index 590faf723..150b60140 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,6 @@ /* Include files */ #include - #include "MCUStateMachine.h" #include "FlexCAN_T4.h" #include "InverterInterface.h" diff --git a/test/DashboardInterface.h b/test/DashboardInterface.h new file mode 100644 index 000000000..2a0d21278 --- /dev/null +++ b/test/DashboardInterface.h @@ -0,0 +1,5 @@ +#ifndef DASHBOARDINTERFACE +#define DASHBOARDINTERFACE + + +#endif /* DASHBOARDINTERFACE */ diff --git a/test/InverterInterface.h b/test/InverterInterface.h new file mode 100644 index 000000000..92073b460 --- /dev/null +++ b/test/InverterInterface.h @@ -0,0 +1,5 @@ +#ifndef INVERTERINTERFACE +#define INVERTERINTERFACE + + +#endif /* INVERTERINTERFACE */ diff --git a/test/test_yo/test_str.cpp b/test/state_machine_test.cpp similarity index 55% rename from test/test_yo/test_str.cpp rename to test/state_machine_test.cpp index 17d99a16c..fcd5243f1 100644 --- a/test/test_yo/test_str.cpp +++ b/test/state_machine_test.cpp @@ -1,29 +1,27 @@ #include -#include +#include "MCUStateMachine.h" -std::string STR_TO_TEST; void setUp(void) { // set stuff up here - STR_TO_TEST = "Hello, world!"; + } void tearDown(void) { // clean stuff up here - STR_TO_TEST = ""; +// STR_TO_TEST = ""; } void test_string_concat(void) { - std::string hello = "Hello, "; - std::string world = "world!"; - TEST_ASSERT_EQUAL_STRING(STR_TO_TEST.c_str(), (hello + world).c_str()); +// std::string hello = "Hello, "; +// std::string world = "world!"; +// TEST_ASSERT_EQUAL_STRING(STR_TO_TEST.c_str(), (hello + world).c_str()); } - int main(){ // delay(2000); // service delay UNITY_BEGIN(); From a2f30c14d5494f1340acc29b719bba31bcfce4cb Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Fri, 26 Jan 2024 02:49:55 -0500 Subject: [PATCH 03/19] pushing up mocks and some minor updates for enabling testing --- lib/mock_interfaces/AMSInterface.h | 8 ++++++++ lib/mock_interfaces/DashboardInterface.h | 7 ++++++- lib/mock_interfaces/IMDInterface.h | 9 +++++++++ lib/mock_interfaces/InverterInterface.h | 6 +++++- lib/state_machine/include/MCUStateMachine.tpp | 1 - lib/systems/include/Logger.h | 8 +++++--- lib/systems/src/Logger.cpp | 2 +- platformio.ini | 1 + test/state_machine_test.cpp | 4 ++-- 9 files changed, 37 insertions(+), 9 deletions(-) diff --git a/lib/mock_interfaces/AMSInterface.h b/lib/mock_interfaces/AMSInterface.h index fda7b19b7..1c007ddb0 100644 --- a/lib/mock_interfaces/AMSInterface.h +++ b/lib/mock_interfaces/AMSInterface.h @@ -1,5 +1,13 @@ #ifndef AMSINTERFACE #define AMSINTERFACE +class AMSInterface +{ + public: + AMSInterface() {} + bool ok_high(); + bool heartbeat_check(unsigned long curr_time); + private: +}; #endif /* AMSINTERFACE */ diff --git a/lib/mock_interfaces/DashboardInterface.h b/lib/mock_interfaces/DashboardInterface.h index 2a0d21278..bc876a159 100644 --- a/lib/mock_interfaces/DashboardInterface.h +++ b/lib/mock_interfaces/DashboardInterface.h @@ -1,5 +1,10 @@ #ifndef DASHBOARDINTERFACE #define DASHBOARDINTERFACE - +class DashboardInterface +{ +private: +public: + bool start_button_pressed(); +}; #endif /* DASHBOARDINTERFACE */ diff --git a/lib/mock_interfaces/IMDInterface.h b/lib/mock_interfaces/IMDInterface.h index 938918129..9ecd38035 100644 --- a/lib/mock_interfaces/IMDInterface.h +++ b/lib/mock_interfaces/IMDInterface.h @@ -2,4 +2,13 @@ #define IMDINTERFACE +class IMDInterface +{ + public: + IMDInterface() {} + bool ok_high(); + private: +}; + + #endif /* IMDINTERFACE */ diff --git a/lib/mock_interfaces/InverterInterface.h b/lib/mock_interfaces/InverterInterface.h index 92073b460..de67cc30b 100644 --- a/lib/mock_interfaces/InverterInterface.h +++ b/lib/mock_interfaces/InverterInterface.h @@ -1,5 +1,9 @@ #ifndef INVERTERINTERFACE #define INVERTERINTERFACE - +struct InverterCommand +{ + float torque_setpoint_nm; + float speed_setpoint_rpm; +}; #endif /* INVERTERINTERFACE */ diff --git a/lib/state_machine/include/MCUStateMachine.tpp b/lib/state_machine/include/MCUStateMachine.tpp index 81181efe4..4df0f5d06 100644 --- a/lib/state_machine/include/MCUStateMachine.tpp +++ b/lib/state_machine/include/MCUStateMachine.tpp @@ -118,7 +118,6 @@ void MCUStateMachine::tick_state_machine(unsigned long cur } PedalsDriverInterface data; - Dashboard_status dash_data; auto pedals_data = pedals_->evaluate_pedals(data, current_millis); // auto dashboard_data = dashboard_->evaluate_dashboard(dash_data); diff --git a/lib/systems/include/Logger.h b/lib/systems/include/Logger.h index dceb0dbbb..a965462c4 100644 --- a/lib/systems/include/Logger.h +++ b/lib/systems/include/Logger.h @@ -2,8 +2,8 @@ // allows for simple switching between std::cout and Serial.println() depending on // platform -#ifndef LOGGER_H -#define LOGGER_H +#ifndef LOGGER +#define LOGGER #include #include @@ -14,7 +14,9 @@ #ifdef ARDUINO #include #else +#include #include +#include #endif @@ -22,4 +24,4 @@ void hal_print(const char s[]); void hal_println(const char s[]); void hal_printf(const char format[], ...); -#endif +#endif /* LOGGER */ diff --git a/lib/systems/src/Logger.cpp b/lib/systems/src/Logger.cpp index 6e1b2cb4a..06a4b8976 100644 --- a/lib/systems/src/Logger.cpp +++ b/lib/systems/src/Logger.cpp @@ -1,7 +1,7 @@ #include "Logger.h" #ifdef ARDUINO -#include + void hal_print(const char s[]) { Serial.print(s); } diff --git a/platformio.ini b/platformio.ini index 2181a453c..e1d04deeb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,5 +1,6 @@ [env:test] platform = native + build_src_filter = -<**/*.c> -<**/*.cpp> diff --git a/test/state_machine_test.cpp b/test/state_machine_test.cpp index fcd5243f1..1d11a95ff 100644 --- a/test/state_machine_test.cpp +++ b/test/state_machine_test.cpp @@ -15,7 +15,7 @@ void tearDown(void) // STR_TO_TEST = ""; } -void test_string_concat(void) +void test_state_machine(void) { // std::string hello = "Hello, "; // std::string world = "world!"; @@ -26,7 +26,7 @@ int main(){ // delay(2000); // service delay UNITY_BEGIN(); - RUN_TEST(test_string_concat); + RUN_TEST(test_state_machine); UNITY_END(); // stop unit testing From 624dfce0393583fe6745d957d6fb8f3e5efad8db Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Fri, 26 Jan 2024 03:18:37 -0500 Subject: [PATCH 04/19] added in more mocks and got to compiling env ready for test --- lib/mock_interfaces/AMSInterface.h | 13 ++-- lib/mock_interfaces/DashboardInterface.h | 3 +- lib/mock_interfaces/IMDInterface.h | 3 +- lib/state_machine/include/MCUStateMachine.h | 6 +- lib/state_machine/include/MCUStateMachine.tpp | 29 +++++---- lib/systems/include/PedalsSystem.h | 2 +- lib/systems/src/PedalsSystem.cpp | 6 ++ test/state_machine_test.cpp | 64 +++++++++++++++---- 8 files changed, 87 insertions(+), 39 deletions(-) diff --git a/lib/mock_interfaces/AMSInterface.h b/lib/mock_interfaces/AMSInterface.h index 1c007ddb0..c1e25375f 100644 --- a/lib/mock_interfaces/AMSInterface.h +++ b/lib/mock_interfaces/AMSInterface.h @@ -3,11 +3,14 @@ class AMSInterface { - public: - AMSInterface() {} - bool ok_high(); - bool heartbeat_check(unsigned long curr_time); - private: +public: + bool ok_high_; + bool heartbeat_status_; + AMSInterface() {} + bool ok_high() { return ok_high_; }; + bool heartbeat_check(unsigned long curr_time) { return heartbeat_status_; }; + +private: }; #endif /* AMSINTERFACE */ diff --git a/lib/mock_interfaces/DashboardInterface.h b/lib/mock_interfaces/DashboardInterface.h index bc876a159..9500b42e9 100644 --- a/lib/mock_interfaces/DashboardInterface.h +++ b/lib/mock_interfaces/DashboardInterface.h @@ -4,7 +4,8 @@ class DashboardInterface { private: public: - bool start_button_pressed(); + bool start_button; + bool start_button_pressed() { return start_button; }; }; #endif /* DASHBOARDINTERFACE */ diff --git a/lib/mock_interfaces/IMDInterface.h b/lib/mock_interfaces/IMDInterface.h index 9ecd38035..58126749b 100644 --- a/lib/mock_interfaces/IMDInterface.h +++ b/lib/mock_interfaces/IMDInterface.h @@ -6,7 +6,8 @@ class IMDInterface { public: IMDInterface() {} - bool ok_high(); + bool high; + bool ok_high() {return high;}; private: }; diff --git a/lib/state_machine/include/MCUStateMachine.h b/lib/state_machine/include/MCUStateMachine.h index 883541e53..2c70a782b 100644 --- a/lib/state_machine/include/MCUStateMachine.h +++ b/lib/state_machine/include/MCUStateMachine.h @@ -23,11 +23,11 @@ enum class CAR_STATE READY_TO_DRIVE = 7 }; -template +template class MCUStateMachine { public: - MCUStateMachine(BuzzerController *buzzer, DrivetrainSystemType *drivetrain, DashboardInterface *dashboard) + MCUStateMachine(BuzzerController *buzzer, DrivetrainSysType *drivetrain, DashboardInterface *dashboard) { buzzer_ = buzzer; drivetrain_ = drivetrain; @@ -53,7 +53,7 @@ class MCUStateMachine /// @brief components within state machine BuzzerController *buzzer_; - DrivetrainSystemType *drivetrain_; + DrivetrainSysType *drivetrain_; PedalsSystem *pedals_; /// @brief drivers within state machine diff --git a/lib/state_machine/include/MCUStateMachine.tpp b/lib/state_machine/include/MCUStateMachine.tpp index 4df0f5d06..becc3e5a1 100644 --- a/lib/state_machine/include/MCUStateMachine.tpp +++ b/lib/state_machine/include/MCUStateMachine.tpp @@ -1,12 +1,12 @@ -#include "MCUStateMachine.h" -template -void MCUStateMachine::tick_state_machine(unsigned long current_millis) +// #include "MCUStateMachine.h" +template +void MCUStateMachine::tick_state_machine(unsigned long current_millis) { switch (get_state()) { case CAR_STATE::STARTUP: - set_state_(CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE); + set_state_(CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE, current_millis); break; case CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE: @@ -21,12 +21,14 @@ void MCUStateMachine::tick_state_machine(unsigned long cur case CAR_STATE::TRACTIVE_SYSTEM_ACTIVE: { + // TODO migrate to new pedals system + PedalsDriverInterface data; if (!drivetrain_->hv_over_threshold_on_drivetrain()) { set_state_(CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE, current_millis); break; } - if (dashboard_->start_button_pressed() && pedals_->mech_brake_active()) + if (dashboard_->start_button_pressed() && pedals_->mech_brake_active(data)) { set_state_(CAR_STATE::ENABLING_INVERTERS, current_millis); break; @@ -103,8 +105,7 @@ void MCUStateMachine::tick_state_machine(unsigned long cur case CAR_STATE::READY_TO_DRIVE: { - // TODO handle the drivetrain state change back to startup phase 1 and/or move this into - // the drivetrain state machine handling + if (!drivetrain_->hv_over_threshold_on_drivetrain()) { set_state_(CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE, current_millis); @@ -116,7 +117,7 @@ void MCUStateMachine::tick_state_machine(unsigned long cur set_state_(CAR_STATE::TRACTIVE_SYSTEM_ACTIVE, current_millis); break; } - + // TODO migrate the handling of the pedals / move to the new pedals system PedalsDriverInterface data; auto pedals_data = pedals_->evaluate_pedals(data, current_millis); // auto dashboard_data = dashboard_->evaluate_dashboard(dash_data); @@ -145,8 +146,8 @@ void MCUStateMachine::tick_state_machine(unsigned long cur } } -template -void MCUStateMachine::set_state_(CAR_STATE new_state, unsigned long curr_time) +template +void MCUStateMachine::set_state_(CAR_STATE new_state, unsigned long curr_time) { hal_println("running exit logic"); handle_exit_logic_(current_state_, curr_time); @@ -157,8 +158,8 @@ void MCUStateMachine::set_state_(CAR_STATE new_state, unsi handle_entry_logic_(new_state, curr_time); } -template -void MCUStateMachine::handle_exit_logic_(CAR_STATE prev_state, unsigned long curr_time) +template +void MCUStateMachine::handle_exit_logic_(CAR_STATE prev_state, unsigned long curr_time) { switch (get_state()) { @@ -183,8 +184,8 @@ void MCUStateMachine::handle_exit_logic_(CAR_STATE prev_st } } } -template -void MCUStateMachine::handle_entry_logic_(CAR_STATE new_state, unsigned long curr_time) +template +void MCUStateMachine::handle_entry_logic_(CAR_STATE new_state, unsigned long curr_time) { switch (new_state) { diff --git a/lib/systems/include/PedalsSystem.h b/lib/systems/include/PedalsSystem.h index 8ef6df81e..143b8aa02 100644 --- a/lib/systems/include/PedalsSystem.h +++ b/lib/systems/include/PedalsSystem.h @@ -44,7 +44,7 @@ class PedalsSystem PedalsSystemInterface evaluate_pedals( const PedalsDriverInterface &pedal_data, unsigned long curr_time); bool max_duration_of_implausibility_exceeded(unsigned long curr_time); - bool mech_brake_active(); + bool mech_brake_active(const PedalsDriverInterface &data); private: std::tuple linearize_accel_pedal_values_(int accel1, int accel2); diff --git a/lib/systems/src/PedalsSystem.cpp b/lib/systems/src/PedalsSystem.cpp index d4f49ffb1..8d5b9b06a 100644 --- a/lib/systems/src/PedalsSystem.cpp +++ b/lib/systems/src/PedalsSystem.cpp @@ -63,6 +63,12 @@ bool PedalsSystem::evaluate_pedal_implausibilities_(int sense_1, int sense_2, co } } +// +bool PedalsSystem::mech_brake_active(const PedalsDriverInterface &data) +{ + return pedal_is_active_(data.brakePedalPosition1, data.brakePedalPosition2, brakeParams_, 0.05); +} + bool PedalsSystem::evaluate_brake_and_accel_pressed_(const PedalsDriverInterface &data) { diff --git a/test/state_machine_test.cpp b/test/state_machine_test.cpp index 1d11a95ff..93c9ff812 100644 --- a/test/state_machine_test.cpp +++ b/test/state_machine_test.cpp @@ -1,34 +1,70 @@ #include #include "MCUStateMachine.h" +#include "PedalsSystem.h" +class DrivetrainMock +{ +public: + + + bool drivetrain_ready_; + bool drivetrain_ready() {}; + /// @param curr_time current system tick time (millis()) that sets the init phase start time + void enable_drivetrain_hv(unsigned long curr_time){}; + + // startup phase 2 + bool check_drivetrain_quit_dc_on() {}; + + // on entry logic + void request_enable() {}; + void command_drivetrain_no_torque() {}; + + // final check for drivetrain initialization to check if quit inverter on + bool drivetrain_enabled(){}; + + // check to see if init time limit has passed + bool inverter_init_timeout(unsigned long curr_time) {}; + + bool hv_over_threshold_on_drivetrain() {}; + void disable() {}; + bool drivetrain_error_occured() {}; + + void command_drivetrain(const DrivetrainCommand &data) {}; +}; +BuzzerController buzzer(500); + + + +DrivetrainMock drivetrain; + +DashboardInterface dash_interface; + +MCUStateMachine state_machine(&buzzer, &drivetrain, &dash_interface); void setUp(void) { - // set stuff up here - + // set stuff up here } void tearDown(void) { - // clean stuff up here -// STR_TO_TEST = ""; + // clean stuff up here + // STR_TO_TEST = ""; } void test_state_machine(void) { -// std::string hello = "Hello, "; -// std::string world = "world!"; -// TEST_ASSERT_EQUAL_STRING(STR_TO_TEST.c_str(), (hello + world).c_str()); + unsigned long sys_time = 1000; + state_machine.tick_state_machine(sys_time); } -int main(){ -// delay(2000); // service delay - UNITY_BEGIN(); +int main() +{ + // delay(2000); // service delay + UNITY_BEGIN(); - RUN_TEST(test_state_machine); - + RUN_TEST(test_state_machine); - UNITY_END(); // stop unit testing + UNITY_END(); // stop unit testing } - From cd5effe096788f9f0c2266d2b27ec5413ed27acf Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Fri, 26 Jan 2024 03:32:31 -0500 Subject: [PATCH 05/19] first state machine unit test done --- test/state_machine_test.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/state_machine_test.cpp b/test/state_machine_test.cpp index 93c9ff812..23751b8fd 100644 --- a/test/state_machine_test.cpp +++ b/test/state_machine_test.cpp @@ -53,10 +53,12 @@ void tearDown(void) // STR_TO_TEST = ""; } -void test_state_machine(void) +void test_state_machine_init_tick(void) { unsigned long sys_time = 1000; + TEST_ASSERT_TRUE(state_machine.get_state() == CAR_STATE::STARTUP); state_machine.tick_state_machine(sys_time); + TEST_ASSERT_TRUE(state_machine.get_state() == CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE); } int main() @@ -64,7 +66,8 @@ int main() // delay(2000); // service delay UNITY_BEGIN(); - RUN_TEST(test_state_machine); + RUN_TEST(test_state_machine_init_tick); + UNITY_END(); // stop unit testing } From 325acb0bf0a5618206ce77767e1aab07c4fe0ebc Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Fri, 26 Jan 2024 03:38:05 -0500 Subject: [PATCH 06/19] added in github workflow for automated testing --- .github/workflows/platformio.yml | 21 +++++++++++++++++++++ platformio.ini | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/platformio.yml diff --git a/.github/workflows/platformio.yml b/.github/workflows/platformio.yml new file mode 100644 index 000000000..6f8fe9bd6 --- /dev/null +++ b/.github/workflows/platformio.yml @@ -0,0 +1,21 @@ +name: PlatformIO CI + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Check out the repository + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Install PlatformIO CLI + run: pip install platformio + + - name: Run PlatformIO Test + run: pio test -e test_env diff --git a/platformio.ini b/platformio.ini index e1d04deeb..bbadaaf6c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,4 +1,4 @@ -[env:test] +[env:test_env] platform = native build_src_filter = From e1f49d2fa931185b47d4afdac17d77a3ef4a35f9 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Fri, 26 Jan 2024 12:01:33 -0500 Subject: [PATCH 07/19] updated readme --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index edfa087fd..952fdbb79 100644 --- a/README.md +++ b/README.md @@ -189,4 +189,7 @@ stateDiagram-v2 rtd_s --> rtd: buzzer done buzzing rtd --> trac_sys_na: drivetrain voltage _not_ over threshold rtd --> trac_sys_a: drivetrain error occured -``` \ No newline at end of file +``` +### running the tests + +run the tests with `pio test -e test_env` From 4f98a102704844fa3cbb0c4c0ff341c19b33ca32 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Fri, 26 Jan 2024 12:55:36 -0500 Subject: [PATCH 08/19] adding in pedals system test --- lib/systems/include/PedalsSystem.h | 4 +- test/main.cpp | 24 ++++ test/pedals_system_test.h | 57 +++++++++ ..._machine_test.cpp => state_machine_test.h} | 22 +--- test/test_yo/pedals_system_test.cpp | 120 ------------------ 5 files changed, 87 insertions(+), 140 deletions(-) create mode 100644 test/main.cpp create mode 100644 test/pedals_system_test.h rename test/{state_machine_test.cpp => state_machine_test.h} (82%) delete mode 100644 test/test_yo/pedals_system_test.cpp diff --git a/lib/systems/include/PedalsSystem.h b/lib/systems/include/PedalsSystem.h index 143b8aa02..431a2dec0 100644 --- a/lib/systems/include/PedalsSystem.h +++ b/lib/systems/include/PedalsSystem.h @@ -37,7 +37,9 @@ struct PedalsParams class PedalsSystem { public: - PedalsSystem(){ + PedalsSystem(const PedalsParams & accelParams, const PedalsParams & brakeParams) { + accelParams_ = accelParams; + brakeParams_ = brakeParams; implausibilityStartTime_ = 0; // Setting of min and maxes for pedals via config file }; diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 000000000..b860ab9d8 --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,24 @@ +#include "state_machine_test.h" +#include "pedals_system_test.h" +void setUp(void) +{ + // declare a component obj + // possibly make temp class that is a freind class of PedalsSystem to access private members + // possibly modify the +} + +void tearDown(void) +{ +} + +int main() +{ + // delay(2000); // service delay + UNITY_BEGIN(); + + RUN_TEST(test_pedal_is_active); + RUN_TEST(test_state_machine_init_tick); + + + UNITY_END(); // stop unit testing +} diff --git a/test/pedals_system_test.h b/test/pedals_system_test.h new file mode 100644 index 000000000..b6f228d35 --- /dev/null +++ b/test/pedals_system_test.h @@ -0,0 +1,57 @@ +/* +basic test cases for the pedals component class +version 1.0 +rough draft +author: Lucas Plant +*/ + +#ifndef PEDALS_SYSTEM_TEST +#define PEDALS_SYSTEM_TEST +#include +#include +#include "PedalsSystem.h" +#include + +/* +ToDo: + edit pedals system file to accommodate friend wrapper + methods to test: + constructor + evaluate pedals + linearize_accel_pedal_values_ + evaluate pedal_implausibilities_ + evaluate_brake_and_accel_pressed_ + pedal_is_active + + +*/ +struct PedalIsActiveTestCase +{ + // defines input and output params + + // input params + PedalsDriverInterface pedalsinput; + + // expected output + bool expect_active; +}; + + + +void test_pedal_is_active(void) +{ + PedalsParams params_for_test = {1, 1, 10, 10, 1, 1, 9, 9}; + PedalsSystem pedals_system(params_for_test, params_for_test); + std::array test_cases{{{{0, 0, 3, 3}, true}}}; + + for (const auto &test_case : test_cases) + { + auto out = pedals_system.mech_brake_active(test_case.pedalsinput); + TEST_ASSERT_EQUAL(test_case.expect_active, out); + } +} + + + + +#endif /* PEDALS_SYSTEM_TEST */ diff --git a/test/state_machine_test.cpp b/test/state_machine_test.h similarity index 82% rename from test/state_machine_test.cpp rename to test/state_machine_test.h index 23751b8fd..8935b6047 100644 --- a/test/state_machine_test.cpp +++ b/test/state_machine_test.h @@ -1,3 +1,5 @@ +#ifndef STATE_MACHINE_TEST +#define STATE_MACHINE_TEST #include #include "MCUStateMachine.h" #include "PedalsSystem.h" @@ -42,17 +44,6 @@ DashboardInterface dash_interface; MCUStateMachine state_machine(&buzzer, &drivetrain, &dash_interface); -void setUp(void) -{ - // set stuff up here -} - -void tearDown(void) -{ - // clean stuff up here - // STR_TO_TEST = ""; -} - void test_state_machine_init_tick(void) { unsigned long sys_time = 1000; @@ -61,13 +52,6 @@ void test_state_machine_init_tick(void) TEST_ASSERT_TRUE(state_machine.get_state() == CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE); } -int main() -{ - // delay(2000); // service delay - UNITY_BEGIN(); - RUN_TEST(test_state_machine_init_tick); - - UNITY_END(); // stop unit testing -} +#endif /* STATE_MACHINE_TEST */ diff --git a/test/test_yo/pedals_system_test.cpp b/test/test_yo/pedals_system_test.cpp deleted file mode 100644 index 2baf99e66..000000000 --- a/test/test_yo/pedals_system_test.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* -basic test cases for the pedals component class -version 1.0 -rough draft -author: Lucas Plant -*/ -#include -#include -#include - -/* -ToDo: - edit pedals system file to accommodate friend wrapper - methods to test: - constructor - evaluate pedals - linearize_accel_pedal_values_ - evaluate pedal_implausibilities_ - evaluate_brake_and_accel_pressed_ - pedal_is_active - - -*/ - -class PedalsFriend { - //friend class to allow access to private fields of Pedals system - public: - static std::tuple access_linearize_accel_pedal_values_(PedalsComponent& pedals_component, int accel1, int accel2) - { - return pedals_component.linearize_accel_pedal_values_(accel1, accel2) - } - - static bool access_evaluate_pedal_implausibilities_(PedalsComponent& pedals_component, int sense_1, int sense_2, const PedalsParams ¶ms, float max_percent_differnce) - { - return pedals_component.evaluate_pedal_implausibilities_(sense_1, sense_2, params, max_percent_differnce) - } - - static bool access_evaluate_brake_and_accel_pressed_(PedalsComponent& pedals_component, const PedalsDriverInterface &data) - { - return pedals_component.evaluate_brake_and_accel_pressed_(data) - } - - static bool access_pedal_is_active_(PedalsComponent& pedalsComponent pedals_component, int sense1, int sense_2, const PedalsParams& pedalParams, float percent_threshold) - { - return pedal_is_active(PedalsComponent pedalsComponent pedals_component, int sense1, int sense_2, const PedalsParams& pedalParams, percent_threshold) - } - - static PedalsParams access_accel_pedals_params(PedalsComponent& pedals_component) - { - return pedals_component.accelParams_ - } - - static PedalsParams access_brake_pedals_params(PedalsComponent& pedals_component) - { - return pedals_component.brakeParams_ - } -} - -void setUp(void) -{ - //declare a component obj - //possibly make temp class that is a freind class of PedalsComponent to access private members - //possibly modify the - - PedalsComponent pedals_component; - -} - -void tearDown(void) -{ - -} - -struct PedalIsActiveTestCase { - //defines input and output params - - //input params - int sense1; - int sense2; - //for now the pedalsparams will be kept constant however this can become a part of the tests as well - float percent_threshold; - - //expected output - bool expect_active; -} -void test_pedal_is_active_(void) -{ - //define the test cases in a vector - std::vector test_cases = { - {1, 1, 1, true} - //add more test cases later on - }; - - PedalsParams params_for_test = {1, 1, 10, 10, 5, 5, 7, 7} - - for (const auto& test_case : test_cases) { - out = pedal_activePedalsFriend::access_pedal_is_active_(pedals_component, test_case.sense1, test_case.sense2, params_for_test, test_case.percent_threshold); - TEST_ASSERT_EQUAL(test_case.expect_active, out) - } -} - -/* -void test_evaluate_brake_and_accel_pressed(void) -{ - PedalsDriverInterface data = {} - PedalsFriend(pedal_component, data) -} -*/ - - - -int main() { - - UNITY_BEGIN(); - - //tests go here - - - UNITY_END(); -} \ No newline at end of file From 44616ff11e43067e2c3bfac4a31b8e9a332a5c54 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Fri, 26 Jan 2024 13:05:00 -0500 Subject: [PATCH 09/19] added in compile test step --- .github/workflows/platformio.yml | 7 +++++-- test/pedals_system_test.h | 12 ------------ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/.github/workflows/platformio.yml b/.github/workflows/platformio.yml index 6f8fe9bd6..68b91cd43 100644 --- a/.github/workflows/platformio.yml +++ b/.github/workflows/platformio.yml @@ -3,7 +3,7 @@ name: PlatformIO CI on: [push, pull_request] jobs: - test: + run_build_and_tests: runs-on: ubuntu-latest steps: - name: Check out the repository @@ -16,6 +16,9 @@ jobs: - name: Install PlatformIO CLI run: pip install platformio + + - name: Run PlatformIO build for teensy + run: pio run -e teensy41 - - name: Run PlatformIO Test + - name: Run Tests run: pio test -e test_env diff --git a/test/pedals_system_test.h b/test/pedals_system_test.h index b6f228d35..10610c334 100644 --- a/test/pedals_system_test.h +++ b/test/pedals_system_test.h @@ -12,19 +12,7 @@ author: Lucas Plant #include "PedalsSystem.h" #include -/* -ToDo: - edit pedals system file to accommodate friend wrapper - methods to test: - constructor - evaluate pedals - linearize_accel_pedal_values_ - evaluate pedal_implausibilities_ - evaluate_brake_and_accel_pressed_ - pedal_is_active - -*/ struct PedalIsActiveTestCase { // defines input and output params From bb03ae7301bf1b37260f664abf33d32e227bc328 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Fri, 26 Jan 2024 13:06:49 -0500 Subject: [PATCH 10/19] updated readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 952fdbb79..d0e3ced7d 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,6 @@ stateDiagram-v2 rtd --> trac_sys_na: drivetrain voltage _not_ over threshold rtd --> trac_sys_a: drivetrain error occured ``` -### running the tests +#### running the tests -run the tests with `pio test -e test_env` +This repo uses platformio testing for CI unit testing. these tests can be run locally with `pio test -e test_env`. The CI checks to ensure that the code both compiles for the teensy and ensures that the tests are passing. From a15d4271ff55f1c954ec38cbd6d9fd5990631389 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Fri, 26 Jan 2024 13:20:26 -0500 Subject: [PATCH 11/19] updating readme again with corrected terminology --- README.md | 89 +++++++++++++++++++-------------------- test/main.cpp | 2 +- test/state_machine_test.h | 2 - 3 files changed, 45 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index d0e3ced7d..c35f7923b 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,3 @@ -new MCU code: -- component definition: - an abstract sub-system of the physical car or the code that requires logic to be evaluated by the MCU to determine what input to give it or logic required to handle output from. -- driver definition: - - code required to purely unpack / pack data into internal structs / classes for use by components or logic - - I think the best way to handle the driver level is that all the drivers - -- architecture: - - - over-arching state machine - - components level - - inverters (multiple) - - pedals - - torque / speed controller - - driver dashboard - - - driver level: - - hytech_can driver - - spi drivers: SPI adcs for load cells, steering input, glv, etc. - ### outline Levels represent the layer of abstraction they are on. The reason for keeping track of this is to minimize the layers of abstraction for ease of understanding while also creating logical structure and getting maximum benefit per abstraction. @@ -29,23 +9,23 @@ Levels represent the layer of abstraction they are on. The reason for keeping tr #### level 1: state machine goals for interface design and implementation -- __Reason for abstraction__: allows for easy swapping and adding of different portable components and better [separation of concerns](https://en.wikipedia.org/wiki/Separation_of_concerns) from [business logic](https://www.techtarget.com/whatis/definition/business-logic) of the car to the business logic of the component. +- __Reason for abstraction__: allows for easy swapping and adding of different portable systems and better [separation of concerns](https://en.wikipedia.org/wiki/Separation_of_concerns) from [business logic](https://www.techtarget.com/whatis/definition/business-logic) of the car to the business logic of the system. -Any firmware project that needs to have different states needs each component that creates outputs and / or controls real components of the car needs can be thought of as each component being controlled by the state machine. What I am thinking is that in a similar fashion to the shared bus, each component can contain a shared pointer to the state machine. The component can know what state the car is in and based on the state it can determine how to behave. Obviously the state machine also needs to know about what the component is doing as well to determine the state, so the component also needs to be able to pass back data to the state machine. +Any firmware project that needs to have different states needs each system that creates outputs and / or controls real systems of the car needs can be thought of as each system being controlled by the state machine. What I am thinking is that in a similar fashion to the shared bus, each system can contain a shared pointer to the state machine. The system can know what state the car is in and based on the state it can determine how to behave. Obviously the state machine also needs to know about what the system is doing as well to determine the state, so the system also needs to be able to pass back data to the state machine. -For example, our state machine needs to handle understand the state of the pedals component. The pedals dont know about the state of the car, but it does know whether or not the pedals are outputting valid data. Each component can manage their own state and the abstract component base class could contain the set of component-agnostic states through which the statemachine evaluates. +For example, our state machine needs to handle understand the state of the pedals system. The pedals dont know about the state of the car, but it does know whether or not the pedals are outputting valid data. Each system can manage their own state and the abstract system base class could contain the set of system-agnostic states through which the statemachine evaluates. -It is only within the logic of our state machine that the components are allowed to communicate with one another. +It is only within the logic of our state machine that the systems are allowed to communicate with one another. -The main idea is that each firmware project has a specific implementation of a state machine, however the components are portable between firmware projects. Additionally, the components remain as concrete +The main idea is that each firmware project has a specific implementation of a state machine, however the systems are portable between firmware projects. Additionally, the systems remain as concrete ```mermaid --- -title: state machine and component state abstraction +title: state machine and system state abstraction --- classDiagram @@ -59,19 +39,16 @@ classDiagram } class StateMachine { - BMSComponent* bms - VectornavComponent* vectornav - PedalsComponent* pedals - DashComponent* dashboard + + VectornavSystem* vectornav + PedalsSystem* pedals + DashSystem* dashboard - InverterComponent* left_front - InverterComponent* right_front - InverterComponent* left_rear - InverterComponent* right_rear + DrivetrainSystem* drivetrain - TorqueVectoringControllerComponent* tvc - LaunchControlComponent* launch_control + TorqueVectoringControllerSystem* tvc + LaunchControlSystem* launch_control car_state state void init() @@ -86,19 +63,19 @@ classDiagram -#### level 2 portable components: interfaces, logic and structure +#### level 2 portable Systems: interfaces, logic and structure -- __Reason for abstraction__: these components allow us to have board portable pieces so that when newer iterations of boards are made, the same components that the previous iteration handled can be kept while only the hardware specific code changes. +- __Reason for abstraction__: these Systems allow us to have board portable pieces so that when newer iterations of boards are made, the same systems that the previous iteration handled can be kept while only the hardware specific code changes. -For instance, when a new MCU board is created with a new steering sensor input, code within the controller components will not need to change, only that a new sensor component will be used within the state machine to feed the controller input. +For instance, when a new MCU board is created with a new steering sensor input, code within the controller systems will not need to change, only that a new sensor system will be used within the state machine to feed the controller input. -below are some hypothetical component class definitions. +below are some hypothetical system class definitions. ```mermaid --- -title: components +title: systems --- classDiagram - class PedalsComponent{ + class PedalsSystem{ -void validate_accel_pedals() -void validate_brake_pedals() @@ -107,7 +84,7 @@ classDiagram +float get_desired_throttle() +void validate() } - class TorqueVectoringControllerComponent{ + class TorqueVectoringControllerSystem{ +void init(torque_vectoring_params params) +void set_state_estimate(car_state state) @@ -117,7 +94,7 @@ classDiagram -void run_pid() } - class LaunchControlComponent{ + class LaunchControlSystem{ +void init(launch_control_params params) +void set_state_estimate(car_state state) @@ -130,7 +107,7 @@ classDiagram #### level 2 SPI / i2c data bus abstraction from hardware specific implementations -- __Reason for abstraction__: this allows us to create a specific type of component that uses a shared resource, for example multiple sensors on a SPI bus, that each have their own scaling to produce data for feeding other components. +- __Reason for abstraction__: this allows us to create a specific type of system that uses a shared resource, for example multiple sensors on a SPI bus, that each have their own scaling to produce data for feeding other systems. This is currently aimed at our use of a SPI bus. The read data functions are what convert the data gotten from the shared bus to the real-world values for each one of the sensors. This was being attempted with ADC_SPI versus STEERING_SPI using just copies of the class. @@ -193,3 +170,25 @@ stateDiagram-v2 #### running the tests This repo uses platformio testing for CI unit testing. these tests can be run locally with `pio test -e test_env`. The CI checks to ensure that the code both compiles for the teensy and ensures that the tests are passing. + + + +#### notes +new MCU code: +- system definition: + an abstract sub-system of the physical car or the code that requires logic to be evaluated by the MCU to determine what input to give it or logic required to handle output from. +- interface definition: + - code required to purely unpack / pack data into internal structs / classes for use by systems or logic + +- architecture: + + - over-arching state machine + - systems level + - inverters (multiple) + - pedals + - torque / speed controller + - dashboard interface + + - interface level: + - hytech_can interface + - spi interfaces: SPI adcs for load cells, steering input, glv, etc. diff --git a/test/main.cpp b/test/main.cpp index b860ab9d8..0d7092853 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -13,7 +13,7 @@ void tearDown(void) int main() { - // delay(2000); // service delay + UNITY_BEGIN(); RUN_TEST(test_pedal_is_active); diff --git a/test/state_machine_test.h b/test/state_machine_test.h index 8935b6047..b9c5a6e86 100644 --- a/test/state_machine_test.h +++ b/test/state_machine_test.h @@ -36,8 +36,6 @@ class DrivetrainMock BuzzerController buzzer(500); - - DrivetrainMock drivetrain; DashboardInterface dash_interface; From c99f7eef3038f3bf723479b9aeaa11cd0e303e0f Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Sun, 28 Jan 2024 17:41:59 -0500 Subject: [PATCH 12/19] adding more tests for the state machine --- TESTING.md | 11 +++ TODO.md | 0 lib/mock_interfaces/DashboardInterface.h | 4 +- lib/state_machine/include/MCUStateMachine.h | 4 +- platformio.ini | 3 +- test/DashboardInterface.h | 5 -- test/main.cpp | 27 +++--- test/pedals_system_test.h | 1 - test/state_machine_test.h | 97 +++++++++++++++++---- 9 files changed, 107 insertions(+), 45 deletions(-) create mode 100644 TESTING.md create mode 100644 TODO.md delete mode 100644 test/DashboardInterface.h diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 000000000..f6ba0daaf --- /dev/null +++ b/TESTING.md @@ -0,0 +1,11 @@ +testing strategy: +- using GTest for mocking systems +- custom re-definitions of interfaces (for now) + - cant use GTest mocking easily for this I dont think + +- the mock interfaces will just be empty classes p much to have something that the systems classes can have pointers to if they own a pointer to an interface + +- the mock systems will use the gmock lib for better mocking of systems for system to system interaction in the test env + + + diff --git a/TODO.md b/TODO.md new file mode 100644 index 000000000..e69de29bb diff --git a/lib/mock_interfaces/DashboardInterface.h b/lib/mock_interfaces/DashboardInterface.h index 9500b42e9..ab5523031 100644 --- a/lib/mock_interfaces/DashboardInterface.h +++ b/lib/mock_interfaces/DashboardInterface.h @@ -4,8 +4,8 @@ class DashboardInterface { private: public: - bool start_button; - bool start_button_pressed() { return start_button; }; + bool start_button_status_; + bool start_button_pressed() { return start_button_status_; }; }; #endif /* DASHBOARDINTERFACE */ diff --git a/lib/state_machine/include/MCUStateMachine.h b/lib/state_machine/include/MCUStateMachine.h index 2c70a782b..2abdc38a1 100644 --- a/lib/state_machine/include/MCUStateMachine.h +++ b/lib/state_machine/include/MCUStateMachine.h @@ -2,6 +2,7 @@ #define __MCU_STATE_MACHINE__ #include "Logger.h" + #include "PedalsSystem.h" #include "DrivetrainSystem.h" #include "Buzzer.h" @@ -27,11 +28,12 @@ template class MCUStateMachine { public: - MCUStateMachine(BuzzerController *buzzer, DrivetrainSysType *drivetrain, DashboardInterface *dashboard) + MCUStateMachine(BuzzerController *buzzer, DrivetrainSysType *drivetrain, DashboardInterface *dashboard, PedalsSystem *pedals) { buzzer_ = buzzer; drivetrain_ = drivetrain; dashboard_ = dashboard; + pedals_ = pedals; } /// @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 diff --git a/platformio.ini b/platformio.ini index bbadaaf6c..c50157d91 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,6 +1,6 @@ [env:test_env] platform = native - +test_framework = googletest build_src_filter = -<**/*.c> -<**/*.cpp> @@ -22,6 +22,7 @@ upload_protocol = teensy-cli extra_scripts = pre:extra_script.py lib_ignore = mock_interfaces + mock_systems lib_deps = SPI https://github.com/tonton81/FlexCAN_T4 diff --git a/test/DashboardInterface.h b/test/DashboardInterface.h deleted file mode 100644 index 2a0d21278..000000000 --- a/test/DashboardInterface.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef DASHBOARDINTERFACE -#define DASHBOARDINTERFACE - - -#endif /* DASHBOARDINTERFACE */ diff --git a/test/main.cpp b/test/main.cpp index 0d7092853..975ce0cc2 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,24 +1,17 @@ +#include + #include "state_machine_test.h" -#include "pedals_system_test.h" -void setUp(void) -{ - // declare a component obj - // possibly make temp class that is a freind class of PedalsSystem to access private members - // possibly modify the -} +// #include "pedals_system_test.h" -void tearDown(void) -{ -} -int main() -{ - UNITY_BEGIN(); +int main(int argc, char **argv) +{ - RUN_TEST(test_pedal_is_active); - RUN_TEST(test_state_machine_init_tick); - - UNITY_END(); // stop unit testing + testing::InitGoogleMock(&argc, argv); + if (RUN_ALL_TESTS()) + ; + // Always return zero-code and allow PlatformIO to parse results + return 0; } diff --git a/test/pedals_system_test.h b/test/pedals_system_test.h index 10610c334..960345a07 100644 --- a/test/pedals_system_test.h +++ b/test/pedals_system_test.h @@ -7,7 +7,6 @@ author: Lucas Plant #ifndef PEDALS_SYSTEM_TEST #define PEDALS_SYSTEM_TEST -#include #include #include "PedalsSystem.h" #include diff --git a/test/state_machine_test.h b/test/state_machine_test.h index b9c5a6e86..a7d87f5c8 100644 --- a/test/state_machine_test.h +++ b/test/state_machine_test.h @@ -1,55 +1,116 @@ #ifndef STATE_MACHINE_TEST #define STATE_MACHINE_TEST -#include +#include +#include #include "MCUStateMachine.h" -#include "PedalsSystem.h" + + + + class DrivetrainMock { public: - - bool drivetrain_ready_; - bool drivetrain_ready() {}; + bool hv_thresh_; + bool drivetrain_ready(){}; /// @param curr_time current system tick time (millis()) that sets the init phase start time void enable_drivetrain_hv(unsigned long curr_time){}; // startup phase 2 - bool check_drivetrain_quit_dc_on() {}; + bool check_drivetrain_quit_dc_on(){}; // on entry logic - void request_enable() {}; - void command_drivetrain_no_torque() {}; + void request_enable(){}; + void command_drivetrain_no_torque(){}; // final check for drivetrain initialization to check if quit inverter on bool drivetrain_enabled(){}; // check to see if init time limit has passed - bool inverter_init_timeout(unsigned long curr_time) {}; + bool inverter_init_timeout(unsigned long curr_time){}; - bool hv_over_threshold_on_drivetrain() {}; - void disable() {}; - bool drivetrain_error_occured() {}; + bool hv_over_threshold_on_drivetrain() { return hv_thresh_; }; + void disable(){}; + bool drivetrain_error_occured(){}; - void command_drivetrain(const DrivetrainCommand &data) {}; + void command_drivetrain(const DrivetrainCommand &data){}; }; - BuzzerController buzzer(500); DrivetrainMock drivetrain; + +PedalsParams params_for_test = {1, 1, 10, 10, 1, 1, 9, 9}; +PedalsSystem pedals(params_for_test, params_for_test); + DashboardInterface dash_interface; -MCUStateMachine state_machine(&buzzer, &drivetrain, &dash_interface); +MCUStateMachine state_machine(&buzzer, &drivetrain, &dash_interface, &pedals); -void test_state_machine_init_tick(void) +TEST(MCUStateMachineTesting, test_state_machine_init_tick) { unsigned long sys_time = 1000; - TEST_ASSERT_TRUE(state_machine.get_state() == CAR_STATE::STARTUP); + EXPECT_EQ(state_machine.get_state(), CAR_STATE::STARTUP); state_machine.tick_state_machine(sys_time); - TEST_ASSERT_TRUE(state_machine.get_state() == CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE); + EXPECT_EQ(state_machine.get_state(), CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE); } +TEST(MCUStateMachineTesting, test_state_machine_tractive_system_activation) +{ + unsigned long sys_time = 1000; + + // ticking without hv over threshold testing and ensuring the tractive system not active still + state_machine.tick_state_machine(sys_time); + sys_time += 1; + drivetrain.hv_thresh_ = false; + state_machine.tick_state_machine(sys_time); + sys_time += 1; + EXPECT_EQ(state_machine.get_state(), CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE); + + // hv going over threshold -> tractive system + drivetrain.hv_thresh_ = true; + sys_time +=1; + state_machine.tick_state_machine(sys_time); + EXPECT_EQ(state_machine.get_state(), CAR_STATE::TRACTIVE_SYSTEM_ACTIVE); + + + // hv going under thresh -> tractive system not active + drivetrain.hv_thresh_ =false; + sys_time +=1; + state_machine.tick_state_machine(sys_time); + EXPECT_EQ(state_machine.get_state(), CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE); +} + +TEST(MCUStateMachineTesting, test_state_machine_tractive_system_enabling) +{ + unsigned long sys_time = 1000; + + // ticking without hv over threshold testing and ensuring the tractive system not active still + state_machine.tick_state_machine(sys_time); + sys_time += 1; + drivetrain.hv_thresh_ = false; + state_machine.tick_state_machine(sys_time); + sys_time += 1; + EXPECT_EQ(state_machine.get_state(), CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE); + + // hv going over threshold -> tractive system + drivetrain.hv_thresh_ = true; + sys_time +=1; + state_machine.tick_state_machine(sys_time); + EXPECT_EQ(state_machine.get_state(), CAR_STATE::TRACTIVE_SYSTEM_ACTIVE); + + + sys_time +=1; + dash_interface.start_button_status_ = true; + auto pedals_brake_active_res = pedals.evaluate_pedals({0,0,3,3}, sys_time); + state_machine.tick_state_machine(sys_time); + EXPECT_EQ(state_machine.get_state(), CAR_STATE::ENABLING_INVERTERS); + + +} + + #endif /* STATE_MACHINE_TEST */ From 229c40ff944ee659c5f147e353b58435d6fa5bd3 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Mon, 29 Jan 2024 23:57:18 -0500 Subject: [PATCH 13/19] adding in test stubs for state machine --- test/state_machine_test.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/state_machine_test.h b/test/state_machine_test.h index a7d87f5c8..ffeb38642 100644 --- a/test/state_machine_test.h +++ b/test/state_machine_test.h @@ -112,5 +112,24 @@ TEST(MCUStateMachineTesting, test_state_machine_tractive_system_enabling) } +TEST(MCUStateMachineTesting, test_state_machine_drivetrain_quit_test) +{ + +} + +TEST(MCUStateMachineTesting, test_state_machine_drivetrain_enable) +{ + +} + +TEST(MCUStateMachineTesting, test_state_machine_rtd_sound) +{ + +} + +TEST(MCUStateMachineTesting, test_state_machine_rtd_state_transitions) +{ + +} #endif /* STATE_MACHINE_TEST */ From 343e8061b998eba9faac0d34e02cbabdad1f64ea Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Tue, 30 Jan 2024 00:02:24 -0500 Subject: [PATCH 14/19] added test files --- test/controller_mux_test.h | 5 +++++ test/drivetrain_system_test.h | 5 +++++ test/main.cpp | 2 +- test/pedals_system_test.h | 5 +++-- 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 test/controller_mux_test.h create mode 100644 test/drivetrain_system_test.h diff --git a/test/controller_mux_test.h b/test/controller_mux_test.h new file mode 100644 index 000000000..40a8ee3c5 --- /dev/null +++ b/test/controller_mux_test.h @@ -0,0 +1,5 @@ +#ifndef CONTROLLER_MUX_TEST +#define CONTROLLER_MUX_TEST + + +#endif /* CONTROLLER_MUX_TEST */ diff --git a/test/drivetrain_system_test.h b/test/drivetrain_system_test.h new file mode 100644 index 000000000..3d32d4a93 --- /dev/null +++ b/test/drivetrain_system_test.h @@ -0,0 +1,5 @@ +#ifndef DRIVETRAIN_SYSTEM_TEST +#define DRIVETRAIN_SYSTEM_TEST + + +#endif /* DRIVETRAIN_SYSTEM_TEST */ diff --git a/test/main.cpp b/test/main.cpp index 975ce0cc2..2b93feab9 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,7 +1,7 @@ #include #include "state_machine_test.h" -// #include "pedals_system_test.h" +#include "pedals_system_test.h" diff --git a/test/pedals_system_test.h b/test/pedals_system_test.h index 960345a07..221e1f419 100644 --- a/test/pedals_system_test.h +++ b/test/pedals_system_test.h @@ -7,6 +7,7 @@ author: Lucas Plant #ifndef PEDALS_SYSTEM_TEST #define PEDALS_SYSTEM_TEST +#include #include #include "PedalsSystem.h" #include @@ -25,7 +26,7 @@ struct PedalIsActiveTestCase -void test_pedal_is_active(void) +TEST(PedalsSystemTesting, test_pedal_is_active) { PedalsParams params_for_test = {1, 1, 10, 10, 1, 1, 9, 9}; PedalsSystem pedals_system(params_for_test, params_for_test); @@ -34,7 +35,7 @@ void test_pedal_is_active(void) for (const auto &test_case : test_cases) { auto out = pedals_system.mech_brake_active(test_case.pedalsinput); - TEST_ASSERT_EQUAL(test_case.expect_active, out); + EXPECT_EQ(test_case.expect_active, out); } } From ac31941c76fbcac50a1a611a37a541c305847c29 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Tue, 30 Jan 2024 00:03:46 -0500 Subject: [PATCH 15/19] added todos --- test/drivetrain_system_test.h | 2 +- test/pedals_system_test.h | 2 ++ test/state_machine_test.h | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/drivetrain_system_test.h b/test/drivetrain_system_test.h index 3d32d4a93..a9f82ff5e 100644 --- a/test/drivetrain_system_test.h +++ b/test/drivetrain_system_test.h @@ -1,5 +1,5 @@ #ifndef DRIVETRAIN_SYSTEM_TEST #define DRIVETRAIN_SYSTEM_TEST - +// TODO @ben #endif /* DRIVETRAIN_SYSTEM_TEST */ diff --git a/test/pedals_system_test.h b/test/pedals_system_test.h index 221e1f419..442bf7d01 100644 --- a/test/pedals_system_test.h +++ b/test/pedals_system_test.h @@ -5,6 +5,8 @@ rough draft author: Lucas Plant */ +// TODO @ben + #ifndef PEDALS_SYSTEM_TEST #define PEDALS_SYSTEM_TEST #include diff --git a/test/state_machine_test.h b/test/state_machine_test.h index ffeb38642..ef72fd552 100644 --- a/test/state_machine_test.h +++ b/test/state_machine_test.h @@ -5,7 +5,7 @@ #include "MCUStateMachine.h" - +// TODO @ben class DrivetrainMock { From fd0cb51192ad17bde27955ec44e871a40a5f9d99 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Tue, 30 Jan 2024 00:06:05 -0500 Subject: [PATCH 16/19] updated main --- src/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 150b60140..5df8f68c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include "ADC_SPI.h" #include "MessageHandler.h" #include "DrivetrainSystem.h" +#include "PedalsSystem.h" #include "HytechCANInterface.h" @@ -31,7 +32,10 @@ CANInterfaces can_interfaces = {&fl_inv, &fr_inv, &rl_inv, & using DrivetrainSystemType = DrivetrainSystem; auto drivetrain = DrivetrainSystemType({&fl_inv, &fr_inv, &rl_inv, &rr_inv}, 5000); -MCUStateMachine state_machine(&buzzer, &drivetrain, &dash_interface); +PedalsParams params_for_test = {1, 1, 10, 10, 1, 1, 9, 9}; +PedalsSystem pedals(params_for_test, params_for_test); + +MCUStateMachine state_machine(&buzzer, &drivetrain, &dash_interface, &pedals); FlexCAN_T4 FRONT_INV_CAN; From 3d1cfc3608f1d8b04b26ffe85b5db8dd31722158 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Mon, 5 Feb 2024 15:37:46 -0500 Subject: [PATCH 17/19] continuing work on making compile --- lib/interfaces/include/DashboardInterface.h | 6 ++-- lib/interfaces/src/DashboardInterface.cpp | 12 ++++--- src/main.cpp | 40 ++++++++++----------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/lib/interfaces/include/DashboardInterface.h b/lib/interfaces/include/DashboardInterface.h index 3e56c4e6a..e2c0965a8 100644 --- a/lib/interfaces/include/DashboardInterface.h +++ b/lib/interfaces/include/DashboardInterface.h @@ -37,7 +37,7 @@ enum DashLED_e MC_ERROR_LED, IMD_LED, AMS_LED, -} +}; struct DashButtons_s { @@ -78,7 +78,7 @@ class DashboardInterface public: - Dashboard(CANBufferType *msg_output_queue) + DashboardInterface(CANBufferType *msg_output_queue) { msg_queue_ = msg_output_queue; }; @@ -98,7 +98,7 @@ class DashboardInterface bool torqueLoadingButtonPressed(); bool nightModeButtonPressed(); bool torqueVectoringOffButtonPressed(); - + bool shutdownHAboveThreshold(); void soundBuzzer(bool s); bool checkBuzzer(); diff --git a/lib/interfaces/src/DashboardInterface.cpp b/lib/interfaces/src/DashboardInterface.cpp index 6b2063804..70deebc40 100644 --- a/lib/interfaces/src/DashboardInterface.cpp +++ b/lib/interfaces/src/DashboardInterface.cpp @@ -8,7 +8,7 @@ void DashboardInterface::read(const CAN_message_t &can_msg) _data.dial_mode = static_cast(msg.dial_state); - _data.ssok = msg.ssok_above_threshold + _data.ssok = msg.ssok_above_threshold; _data.shutdown = msg.shutdown_h_above_threshold; _data.button.start = msg.start_btn; @@ -44,16 +44,18 @@ void DashboardInterface::write() msg.ams_led = _data.LED[DashLED_e::AMS_LED]; CAN_message_t can_msg; - can_msg.id = Pack_DASHBOARD_MCU_STATE_ht_can(&msg, can_msg.buf, &can_msg.len, NULL); - - msg_queue_->push_back(can_msg, sizeof(CAN_message_t)); + can_msg.id = Pack_DASHBOARD_MCU_STATE_hytech(&msg, can_msg.buf, &can_msg.len, NULL); + + // TODO fix + // msg_queue_->push_back(can_msg, sizeof(CAN_message_t)); } //figure out how to set enumed led colors or send (0,255 value) void DashboardInterface::setLED(DashLED_e led, LEDColors_e color) { - _data.LED[static_cast(led)] = static_cast color; + // TODO this no worky + // _data.LED[static_cast(led)] = static_cast color; } DialMode_e DashboardInterface::getDialMode() {return _data.dial_mode;} diff --git a/src/main.cpp b/src/main.cpp index fe7c28591..dbd02cf9b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -147,7 +147,7 @@ void loop() { void init_all_CAN() { // Inverter CAN line INV_CAN.begin(); - INV_CAN.setBaudRate(INV_CAN_SPEED); + INV_CAN.setBaudRate(500000); INV_CAN.setMaxMB(16); INV_CAN.enableFIFO(); INV_CAN.enableFIFOInterrupt(); @@ -156,7 +156,7 @@ void init_all_CAN() { // Telemetry CAN line TELEM_CAN.begin(); - TELEM_CAN.setBaudRate(TELEM_CAN_SPEED); + TELEM_CAN.setBaudRate(500000); TELEM_CAN.setMaxMB(16); TELEM_CAN.enableFIFO(); TELEM_CAN.enableFIFOInterrupt(); @@ -211,7 +211,7 @@ void dispatch_telem_CAN() { { // AMS CAN case ID_BMS_COULOMB_COUNTS: - ams_interface.retrieve_coulomb_count_CAN(recvd_msg); + // ams_interface.retrieve_coulomb_count_CAN(recvd_msg); break; case ID_BMS_STATUS: ams_interface.retrieve_status_CAN(recvd_msg, curr_tick); @@ -236,35 +236,35 @@ void update_and_enqueue_all_CAN() { // Drivetrain system // probably here as well // MCU interface - main_ecu.tick(curr_tick, - fsm.get_state(), - drivetrain.drive_error_occured(), - safety_system.get_software_is_ok(), + // main_ecu.tick(curr_tick, + // fsm.get_state(), + // drivetrain.drivetrain_error_occured(), + // safety_system.get_software_is_ok(), // TCMux return - buzzer.buzzer_is_on(), + // buzzer.buzzer_is_on(), // Pedal system return - ams_interface.pack_charge_is_critical(), - dash.lauchControlButtonPressed()); + // ams_interface.pack_charge_is_critical(), + // dash.lauchControlButtonPressed()); // Telemetry - telem_interface.tick(curr_tick, - ADC1.get(), - ADC2.get(), - ADC3.get(), - steering1.convert()); + // telem_interface.tick(curr_tick, + // ADC1.get(), + // ADC2.get(), + // ADC3.get(), + // steering1.convert()); } void sample_all_external_readings() { // Tick all adcs - ADC1.tick(); - ADC2.tick(); - ADC3.tick(); + // ADC1.tick(); + // ADC2.tick(); + // ADC3.tick(); // Tick steering system - steering1.tick(); + // steering1.tick(); // Read shutdown circuits main_ecu.read_mcu_status(); } void process_all_value_readings() { - pedals.tick(); + // pedals.tick(); } From f13e030c3bf6b27aab68c036f5bb0eabbe5847ed Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Mon, 5 Feb 2024 17:48:19 -0500 Subject: [PATCH 18/19] building in the teensy environment --- lib/interfaces/src/DashboardInterface.cpp | 40 +++---- lib/state_machine/include/MCUStateMachine.h | 5 +- lib/state_machine/include/MCUStateMachine.tpp | 40 +++---- lib/systems/include/PedalsSystem.h | 2 + src/main.cpp | 101 +++--------------- 5 files changed, 57 insertions(+), 131 deletions(-) diff --git a/lib/interfaces/src/DashboardInterface.cpp b/lib/interfaces/src/DashboardInterface.cpp index 70deebc40..5cba1cdd2 100644 --- a/lib/interfaces/src/DashboardInterface.cpp +++ b/lib/interfaces/src/DashboardInterface.cpp @@ -4,20 +4,20 @@ void DashboardInterface::read(const CAN_message_t &can_msg) { DASHBOARD_STATE_t msg; - Unpack_DASHBOARD_STATE_ht_can(&msg, can_msg.buf, NULL); + Unpack_DASHBOARD_STATE_hytech(&msg, can_msg.buf, NULL); _data.dial_mode = static_cast(msg.dial_state); _data.ssok = msg.ssok_above_threshold; _data.shutdown = msg.shutdown_h_above_threshold; - _data.button.start = msg.start_btn; - _data.button.mark = msg.mark_btn; - _data.button.mode = msg.mode_btn; - _data.button.mc_cycle = msg.mc_cycle_btn; - _data.button.launch_ctrl = msg.launch_ctrl_btn; - _data.button.torque_mode = msg.torque_mode_btn; - _data.button.led_dimmer = msg.led_dimmer_btn; + // _data.button.start = msg.start_btn; + // _data.button.mark = msg.mark_btn; + // _data.button.mode = msg.mode_btn; + // _data.button.mc_cycle = msg.mc_cycle_btn; + // _data.button.launch_ctrl = msg.launch_ctrl_btn; + // _data.button.torque_mode = msg.torque_mode_btn; + // _data.button.led_dimmer = msg.led_dimmer_btn; _data.buzzer_state = msg.drive_buzzer; @@ -30,18 +30,18 @@ void DashboardInterface::write() msg.drive_buzzer = _data.buzzer_cmd; // TODO: use logic as to not write data for LEDs that have not changed - msg.bots_led = _data.LED[DashLED_e::BOTS_LED]; - msg.launch_control_led = _data.LED[DashLED_e::LAUNCH_CONTROL_LED]; - msg.mode_led = _data.LED[DashLED_e::MODE_LED]; - msg.mech_brake_led = _data.LED[DashLED_e::MECH_BRAKE_LED]; - msg.cockpit_brb_led = _data.LED[DashLED_e::COCKPIT_BRB_LED]; - msg.inertia_led = _data.LED[DashLED_e::INERTIA_LED]; - msg.glv_led = _data.LED[DashLED_e::GLV_LED]; - msg.crit_charge_led = _data.LED[DashLED_e::CRIT_CHARGE_LED]; - msg.start_led = _data.LED[DashLED_e::START_LED]; - msg.mc_error_led = _data.LED[DashLED_e::MC_ERROR_LED]; - msg.imd_led = _data.LED[DashLED_e::IMD_LED]; - msg.ams_led = _data.LED[DashLED_e::AMS_LED]; + // msg.bots_led = _data.LED[DashLED_e::BOTS_LED]; + // msg.launch_control_led = _data.LED[DashLED_e::LAUNCH_CONTROL_LED]; + // msg.mode_led = _data.LED[DashLED_e::MODE_LED]; + // msg.mech_brake_led = _data.LED[DashLED_e::MECH_BRAKE_LED]; + // msg.cockpit_brb_led = _data.LED[DashLED_e::COCKPIT_BRB_LED]; + // msg.inertia_led = _data.LED[DashLED_e::INERTIA_LED]; + // msg.glv_led = _data.LED[DashLED_e::GLV_LED]; + // msg.crit_charge_led = _data.LED[DashLED_e::CRIT_CHARGE_LED]; + // msg.start_led = _data.LED[DashLED_e::START_LED]; + // msg.mc_error_led = _data.LED[DashLED_e::MC_ERROR_LED]; + // msg.imd_led = _data.LED[DashLED_e::IMD_LED]; + // msg.ams_led = _data.LED[DashLED_e::AMS_LED]; CAN_message_t can_msg; can_msg.id = Pack_DASHBOARD_MCU_STATE_hytech(&msg, can_msg.buf, &can_msg.len, NULL); diff --git a/lib/state_machine/include/MCUStateMachine.h b/lib/state_machine/include/MCUStateMachine.h index 35d32a433..e78052cd1 100644 --- a/lib/state_machine/include/MCUStateMachine.h +++ b/lib/state_machine/include/MCUStateMachine.h @@ -39,7 +39,8 @@ class MCUStateMachine /// @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 /// @param current_millis the current millis() call - void tick_state_machine(const SysTick_s &tick); + // void tick_state_machine(const SysTick_s &tick); + void tick_state_machine(unsigned long cm); CAR_STATE get_state() { return current_state_; } private: @@ -62,7 +63,7 @@ class MCUStateMachine /// @brief drivers within state machine DashboardInterface *dashboard_; AMSInterface *bms_; - IMDInterface *imd_; + // IMDInterface *imd_; TorqueControllerMux* controller_mux_; diff --git a/lib/state_machine/include/MCUStateMachine.tpp b/lib/state_machine/include/MCUStateMachine.tpp index becc3e5a1..1709da4a5 100644 --- a/lib/state_machine/include/MCUStateMachine.tpp +++ b/lib/state_machine/include/MCUStateMachine.tpp @@ -22,17 +22,17 @@ void MCUStateMachine::tick_state_machine(unsigned long curren case CAR_STATE::TRACTIVE_SYSTEM_ACTIVE: { // TODO migrate to new pedals system - PedalsDriverInterface data; - if (!drivetrain_->hv_over_threshold_on_drivetrain()) - { - set_state_(CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE, current_millis); - break; - } - if (dashboard_->start_button_pressed() && pedals_->mech_brake_active(data)) - { - set_state_(CAR_STATE::ENABLING_INVERTERS, current_millis); - break; - } + PedalsSystemData_s data; + // if (!drivetrain_->hv_over_threshold_on_drivetrain()) + // { + // set_state_(CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE, current_millis); + // break; + // } + // if (dashboard_->start_button_pressed() && pedals_->mech_brake_active(data)) + // { + // set_state_(CAR_STATE::ENABLING_INVERTERS, current_millis); + // break; + // } break; } @@ -118,14 +118,14 @@ void MCUStateMachine::tick_state_machine(unsigned long curren break; } // TODO migrate the handling of the pedals / move to the new pedals system - PedalsDriverInterface data; - auto pedals_data = pedals_->evaluate_pedals(data, current_millis); + // PedalsDriverInterface data; + // auto pedals_data = pedals_->evaluate_pedals(data, current_millis); // auto dashboard_data = dashboard_->evaluate_dashboard(dash_data); // TODO: below in the scope of this function if ( - bms_->ok_high() && - imd_->ok_high() && + // bms_->ok_high() && + // imd_->ok_high() && !pedals_->max_duration_of_implausibility_exceeded(current_millis)) { // drivetrain_->command_drivetrain(controller_mux_->get_drivetrain_input(pedals_data, dashboard_data)); @@ -134,11 +134,11 @@ void MCUStateMachine::tick_state_machine(unsigned long curren { drivetrain_->command_drivetrain_no_torque(); hal_println("not calculating torque"); - hal_printf("no brake implausibility: %d\n", pedals_data.brakeImplausible); - hal_printf("no accel implausibility: %d\n", pedals_data.accelImplausible); - hal_printf("bms heartbeat: %d\n", bms_->heartbeat_check(current_millis)); - hal_printf("get bms ok high: %d\n", bms_->ok_high()); - hal_printf("get imd ok high: %d\n", imd_->ok_high()); + // hal_printf("no brake implausibility: %d\n", pedals_data.brakeImplausible); + // hal_printf("no accel implausibility: %d\n", pedals_data.accelImplausible); + // hal_printf("bms heartbeat: %d\n", bms_->heartbeat_check(current_millis)); + // hal_printf("get bms ok high: %d\n", bms_->ok_high()); + // hal_printf("get imd ok high: %d\n", imd_->ok_high()); } break; diff --git a/lib/systems/include/PedalsSystem.h b/lib/systems/include/PedalsSystem.h index aa9105a7b..d6ea839cd 100644 --- a/lib/systems/include/PedalsSystem.h +++ b/lib/systems/include/PedalsSystem.h @@ -78,6 +78,8 @@ class PedalsSystem } // Functions + + bool max_duration_of_implausibility_exceeded(unsigned long t); void tick( const SysTick_s &sysClock, const AnalogConversion_s &accel1, diff --git a/src/main.cpp b/src/main.cpp index dbd02cf9b..2a2d62a8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,7 +46,7 @@ MCP3208 ADC3(ADC3_CS); OrbisBR10 steering1(STEERING_SERIAL); /* Declare interfaces */ -DashboardInterface dashboard; +// DashboardInterface dashboard; AMSInterface ams_interface(SOFTWARE_OK); WatchdogInterface wd_interface(WATCHDOG_INPUT); MCUInterface main_ecu(&CAN3_txBuffer); @@ -61,29 +61,24 @@ SysClock sys_clock; BuzzerController buzzer(BUZZER_ON_INTERVAL); SafetySystem safety_system(&ams_interface, &wd_interface); // Tie ams and wd interface to safety system (by pointers) PedalsSystem pedals; -SteeringSystem steering_system(steering1); // Unify member reference and pointers? tied by reference in this case +// SteeringSystem steering_system(steering1); // Unify member reference and pointers? tied by reference in this case using DrivetrainSystemType = DrivetrainSystem; auto drivetrain = DrivetrainSystemType({&fl_inv, &fr_inv, &rl_inv, &rr_inv}, INVERTER_ENABLING_TIMEOUT_INTERVAL); // Tie inverter interfaces to drivetrain system (by pointers) // Hypothetical controllers, need more implementation details -TorqueControllerSimple simple_mode; -TorqueControllerSimple normal_force_mode; -TorqueControllerSimple endurance_derating_mode; -TorqueControllerSimple launch_control_mode; -TorqueControllerSimple torque_vectoring_mode; +// TorqueControllerSimple simple_mode; +// TorqueControllerSimple normal_force_mode; +// TorqueControllerSimple endurance_derating_mode; +// TorqueControllerSimple launch_control_mode; +// TorqueControllerSimple torque_vectoring_mode; TorqueControllerMux torque_controller_mux; // would prob need to tie controllers to mux as well? /* Declare state machine */ -MCUStateMachine fsm(&buzzer, &drivetrain, &dashboard); // need more implemetation details. associated interfaces and systems tied by pointers +// MCUStateMachine fsm(&buzzer, &drivetrain, &dashboard); // need more implemetation details. associated interfaces and systems tied by pointers /* Global instantiations */ SysTick_s curr_tick; /* Function declarations */ /* CAN functions */ -void init_all_CAN(); -void dispatch_all_CAN(); -void dispatch_inv_CAN(); -void dispatch_telem_CAN(); -void update_and_enqueue_all_CAN(); /* External value readings */ void sample_all_external_readings(); /* Process all readings */ @@ -94,11 +89,8 @@ void setup() { /* Tick system clock */ curr_tick = sys_clock.tick(micros()); - /* Initialize CAN communication */ - init_all_CAN(); - /* Initialize interface */ - main_ecu.init(); // pin mode, initial shutdown circuit readings, + // main_ecu.init(); // pin mode, initial shutdown circuit readings, wd_interface.init(curr_tick); // pin mode, initialize wd kick time ams_interface.init(curr_tick); // pin mode, initialize last heartbeat time @@ -121,9 +113,6 @@ void loop() { /* Tick system clock */ curr_tick = sys_clock.tick(micros()); - /* Interfaaces retrieve values */ - // Distribute incoming CAN messages - dispatch_all_CAN(); // Sensors sample and cache sample_all_external_readings(); @@ -131,14 +120,14 @@ void loop() { process_all_value_readings(); /* Update and enqueue CAN messages */ - update_and_enqueue_all_CAN(); + // update_and_enqueue_all_CAN(); /* Inverter procedure before entering state machine */ // Drivetrain check if inverters have error // Drivetrain reset inverters /* Tick state machine */ - fsm.tick_state_machine(curr_tick); + // fsm.tick_state_machine(curr_tick); /* Tick safety system */ safety_system.software_shutdown(curr_tick); @@ -166,72 +155,6 @@ void init_all_CAN() { delay(500); } -void dispatch_all_CAN() { - dispatch_inv_CAN(); - dispatch_telem_CAN(); -} - -void dispatch_inv_CAN() { - while (CAN2_rxBuffer.available()) - { - CAN_message_t recvd_msg; - uint8_t buf[sizeof(CAN_message_t)]; - CAN2_rxBuffer.pop_front(buf, sizeof(CAN_message_t)); - memmove(&recvd_msg, buf, sizeof(recvd_msg)); - switch (recvd_msg.id) - { - // Motor status - case ID_MC1_STATUS: fl_inv.receive_status_msg(recvd_msg); break; - case ID_MC2_STATUS: fr_inv.receive_status_msg(recvd_msg); break; - case ID_MC3_STATUS: rl_inv.receive_status_msg(recvd_msg); break; - case ID_MC3_STATUS: rr_inv.receive_status_msg(recvd_msg); break; - // Motor temperature - case ID_MC1_TEMPS: fl_inv.receive_temp_msg(recvd_msg); break; - case ID_MC2_TEMPS: fr_inv.receive_temp_msg(recvd_msg); break; - case ID_MC3_TEMPS: rl_inv.receive_temp_msg(recvd_msg); break; - case ID_MC4_TEMPS: rr_inv.receive_temp_msg(recvd_msg); break; - // Motor energy - case ID_MC1_ENERGY: fl_inv.receive_energy_msg(recvd_msg); break; - case ID_MC2_ENERGY: fr_inv.receive_energy_msg(recvd_msg); break; - case ID_MC3_ENERGY: rl_inv.receive_energy_msg(recvd_msg); break; - case ID_MC4_ENERGY: rr_inv.receive_energy_msg(recvd_msg); break; - default: break; - } - } -} - -void dispatch_telem_CAN() { - while (CAN3_rxBuffer.available()) - { - CAN_message_t recvd_msg; - uint8_t buf[sizeof(CAN_message_t)]; - CAN3_rxBuffer.pop_front(buf, sizeof(CAN_message_t)); - memmove(&recvd_msg, buf, sizeof(recvd_msg)); - switch (recvd_msg.id) - { - // AMS CAN - case ID_BMS_COULOMB_COUNTS: - // ams_interface.retrieve_coulomb_count_CAN(recvd_msg); - break; - case ID_BMS_STATUS: - ams_interface.retrieve_status_CAN(recvd_msg, curr_tick); - break; - case ID_BMS_TEMPERATURES: - ams_interface.retrieve_temp_CAN(recvd_msg); - break; - case ID_BMS_VOLTAGES: - ams_interface.retrieve_voltage_CAN(recvd_msg); - break; - // Dashboard status - case ID_DASHBOARD_STATUS: - dashboard.read(recvd_msg); - break; - default: - break; - } - } -} - void update_and_enqueue_all_CAN() { // Drivetrain system // probably here as well @@ -261,7 +184,7 @@ void sample_all_external_readings() { // Tick steering system // steering1.tick(); // Read shutdown circuits - main_ecu.read_mcu_status(); + // main_ecu.read_mcu_status(); } void process_all_value_readings() { From 7c53659bbf18fdab7904d37f293568207ec5a28a Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Mon, 5 Feb 2024 17:53:52 -0500 Subject: [PATCH 19/19] commented out broken stuff --- lib/interfaces/include/MCUInterface.h | 39 +++++------ lib/interfaces/include/TelemetryInterface.h | 9 +-- lib/interfaces/src/MCUInterface.cpp | 74 ++++++++++----------- lib/interfaces/src/TelemetryInterface.cpp | 10 +-- src/main.cpp | 4 +- 5 files changed, 69 insertions(+), 67 deletions(-) diff --git a/lib/interfaces/include/MCUInterface.h b/lib/interfaces/include/MCUInterface.h index e716174f2..9a8637356 100644 --- a/lib/interfaces/include/MCUInterface.h +++ b/lib/interfaces/include/MCUInterface.h @@ -4,7 +4,7 @@ #include #include "FlexCAN_T4.h" #include "HyTech_CAN.h" -#include "ht_can.h" +#include "hytech.h" #include "SysClock.h" #include "MCUStateMachine.h" @@ -52,24 +52,25 @@ class MCUInterface int pin_inv_24V_en_; public: - MCUInterface(message_queue *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) - { - // Set pin mode - pinMode(pin_brake_light_ctrl_, OUTPUT); - pinMode(pin_inv_en_, OUTPUT); - pinMode(pin_inv_24V_en_, OUTPUT); - }; - MCUInterface(message_queue *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(){}; + // MCUInterface(message_queue *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) + // { + // // Set pin mode + // pinMode(pin_brake_light_ctrl_, OUTPUT); + // pinMode(pin_inv_en_, OUTPUT); + // pinMode(pin_inv_24V_en_, OUTPUT); + // }; + // MCUInterface(message_queue *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) {}; /* Initialize shutdown circuit input readings */ void init(); diff --git a/lib/interfaces/include/TelemetryInterface.h b/lib/interfaces/include/TelemetryInterface.h index 4d0ad44ef..717a15e6f 100644 --- a/lib/interfaces/include/TelemetryInterface.h +++ b/lib/interfaces/include/TelemetryInterface.h @@ -3,7 +3,7 @@ #include "FlexCAN_T4.h" #include "HyTech_CAN.h" -#include "ht_can.h" +#include "hytech.h" #include "SysClock.h" #include "AnalogSensorsInterface.h" #include "SteeringEncoderInterface.h" @@ -18,11 +18,12 @@ class TelemetryInterface MCU_rear_potentiometers mcu_rear_potentiometers_; MCU_analog_readings mcu_analog_readings_; /* CAN Tx buffer */ - CANBufferType *msg_queue_; + // CANBufferType *msg_queue_; public: - TelemetryInterface(message_queue *msg_output_queue): - msg_queue_(msg_output_queue) {}; + TelemetryInterface(){}; + // TelemetryInterface(message_queue *msg_output_queue): + // msg_queue_(msg_output_queue) {}; /* Update CAN messages (main loop) */ // Interfaces diff --git a/lib/interfaces/src/MCUInterface.cpp b/lib/interfaces/src/MCUInterface.cpp index bf501c5a9..cd8e8ac4e 100644 --- a/lib/interfaces/src/MCUInterface.cpp +++ b/lib/interfaces/src/MCUInterface.cpp @@ -76,15 +76,15 @@ bool MCUInterface::imd_ok_is_high() { /* Send CAN message */ // MCU status -void MCUInterface::enqueue_CAN_mcu_status() { +// void MCUInterface::enqueue_CAN_mcu_status() { - CAN_message_t msg; - mcu_status_.write(msg.buf); - msg.id = ID_MCU_STATUS; - msg.len = sizeof(mcu_status_); +// CAN_message_t msg; +// mcu_status_.write(msg.buf); +// msg.id = ID_MCU_STATUS; +// msg.len = sizeof(mcu_status_); - msg_queue_->push_back(msg, sizeof(CAN_message_t)); -} +// msg_queue_->push_back(msg, sizeof(CAN_message_t)); +// } /* Update MCU_status CAN */ // MCUInterface @@ -107,7 +107,7 @@ void MCUInterface::update_mcu_status_CAN_fsm(CAR_STATE fsm_state) { // State machine returns struct in main loop // fsm.get_state() // might not be compatible anymore, using new states - mcu_status_.set_state(fsm_state); + // mcu_status_.set_state(fsm_state); } //DriveTrain void MCUInterface::update_mcu_status_CAN_drivetrain(bool has_error) { @@ -138,7 +138,7 @@ void MCUInterface::update_mcu_status_CAN_TCMux() { void MCUInterface::update_mcu_status_CAN_dashboard(bool is_pressed) { // DashboardInterface (?) returns struct in main loop // dash.lauchControlButtonPressed() - mcu_status_.toggle_launch_ctrl_active(is_pressed); + // mcu_status_.toggle_launch_ctrl_active(is_pressed); } // BuzzerSystem void MCUInterface::update_mcu_status_CAN_buzzer(bool is_on) { @@ -158,33 +158,33 @@ void MCUInterface::update_mcu_status_CAN_pedals() { } /* Tick SysClock */ -void MCUInterface::tick(const SysTick_s &tick, - // CAR_STATE fsm_state, - bool inv_has_error, - bool software_is_ok, - // TCMux return - bool buzzer_is_on, - // Pedal system return - bool pack_charge_is_critical, - bool button_is_pressed) { - - if (tick.triggers.trigger10) { - // State machine - // update_mcu_status_CAN_fsm(fsm_state); - // Systems - update_mcu_status_CAN_drivetrain(inv_has_error); - update_mcu_status_CAN_safety(software_is_ok); - update_mcu_status_CAN_TCMux(); - update_mcu_status_CAN_buzzer(buzzer_is_on); - update_mcu_status_CAN_pedals(); - // External Interfaces - update_mcu_status_CAN_ams(pack_charge_is_critical); - update_mcu_status_CAN_dashboard(button_is_pressed); - // Internal values - update_mcu_status_CAN(); - // Push into buffer - enqueue_CAN_mcu_status(); - } -} +// void MCUInterface::tick(const SysTick_s &tick, +// // CAR_STATE fsm_state, +// bool inv_has_error, +// bool software_is_ok, +// // TCMux return +// bool buzzer_is_on, +// // Pedal system return +// bool pack_charge_is_critical, +// bool button_is_pressed) { + +// if (tick.triggers.trigger10) { +// // State machine +// // update_mcu_status_CAN_fsm(fsm_state); +// // Systems +// update_mcu_status_CAN_drivetrain(inv_has_error); +// update_mcu_status_CAN_safety(software_is_ok); +// update_mcu_status_CAN_TCMux(); +// update_mcu_status_CAN_buzzer(buzzer_is_on); +// update_mcu_status_CAN_pedals(); +// // External Interfaces +// update_mcu_status_CAN_ams(pack_charge_is_critical); +// update_mcu_status_CAN_dashboard(button_is_pressed); +// // Internal values +// update_mcu_status_CAN(); +// // Push into buffer +// enqueue_CAN_mcu_status(); +// } +// } diff --git a/lib/interfaces/src/TelemetryInterface.cpp b/lib/interfaces/src/TelemetryInterface.cpp index 91fe1eb12..8af093aea 100644 --- a/lib/interfaces/src/TelemetryInterface.cpp +++ b/lib/interfaces/src/TelemetryInterface.cpp @@ -9,7 +9,7 @@ void TelemetryInterface::enqueue_CAN_mcu_pedal_readings() { msg.id = ID_MCU_PEDAL_READINGS; msg.len = sizeof(mcu_pedal_readings_); - msg_queue_->push_back(msg, sizeof(CAN_message_t)); + // msg_queue_->push_back(msg, sizeof(CAN_message_t)); } // Loadcell readings void TelemetryInterface::enqueue_CAN_mcu_load_cells() { @@ -19,7 +19,7 @@ void TelemetryInterface::enqueue_CAN_mcu_load_cells() { msg.id = ID_MCU_LOAD_CELLS; msg.len = sizeof(mcu_load_cells_); - msg_queue_->push_back(msg, sizeof(CAN_message_t)); + // msg_queue_->push_back(msg, sizeof(CAN_message_t)); } // Suspension potentiometers // Front @@ -30,7 +30,7 @@ void TelemetryInterface::enqueue_CAN_mcu_front_potentiometers() { msg.id = ID_MCU_FRONT_POTS; msg.len = sizeof(mcu_front_potentiometers_); - msg_queue_->push_back(msg, sizeof(CAN_message_t)); + // msg_queue_->push_back(msg, sizeof(CAN_message_t)); } // Rear void TelemetryInterface::enqueue_CAN_mcu_rear_potentiometers() { @@ -40,7 +40,7 @@ void TelemetryInterface::enqueue_CAN_mcu_rear_potentiometers() { msg.id = ID_MCU_REAR_POTS; msg.len = sizeof(mcu_rear_potentiometers_); - msg_queue_->push_back(msg, sizeof(CAN_message_t)); + // msg_queue_->push_back(msg, sizeof(CAN_message_t)); } // Analog sensor readings void TelemetryInterface::enqueue_CAN_mcu_analog_readings() { @@ -50,7 +50,7 @@ void TelemetryInterface::enqueue_CAN_mcu_analog_readings() { msg.id = ID_MCU_ANALOG_READINGS; msg.len = sizeof(mcu_analog_readings_); - msg_queue_->push_back(msg, sizeof(CAN_message_t)); + // msg_queue_->push_back(msg, sizeof(CAN_message_t)); } /* Update CAN messages */ diff --git a/src/main.cpp b/src/main.cpp index 2a2d62a8e..4a56c03ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,8 +49,8 @@ OrbisBR10 steering1(STEERING_SERIAL); // DashboardInterface dashboard; AMSInterface ams_interface(SOFTWARE_OK); WatchdogInterface wd_interface(WATCHDOG_INPUT); -MCUInterface main_ecu(&CAN3_txBuffer); -TelemetryInterface telem_interface(&CAN3_txBuffer); +// MCUInterface main_ecu(&CAN3_txBuffer); +// TelemetryInterface telem_interface(&CAN3_txBuffer); using InverterInterfaceType = InverterInterface; InverterInterfaceType fl_inv(&CAN2_txBuffer, ID_MC1_SETPOINTS_COMMAND); InverterInterfaceType fr_inv(&CAN2_txBuffer, ID_MC2_SETPOINTS_COMMAND);