From b489be414848ac68c3ed25f5e42687f4cc5b1c0c Mon Sep 17 00:00:00 2001 From: Cindy Li Date: Tue, 22 Jun 2021 12:09:00 -0400 Subject: [PATCH 01/12] Create modules skeleton for new app structure (#382) * Add modules and main.cpp skeleton * Fix typos --- rover-apps/arm/include/AppConfig.h | 9 ++++ rover-apps/arm_2021/CMakeLists.txt | 7 +++ rover-apps/common/CMakeLists.txt | 0 rover-apps/common/include/Module.h | 10 +++++ rover-apps/common/src/main.cpp | 59 ++++++++++++++++++++++++++ rover-apps/gimbal/include/AppConfig.h | 9 ++++ rover-apps/gimbal_2021/CMakeLists.txt | 7 +++ rover-apps/science/include/AppConfig.h | 9 ++++ rover-apps/science_2021/CMakeLists.txt | 7 +++ 9 files changed, 117 insertions(+) create mode 100644 rover-apps/arm/include/AppConfig.h create mode 100644 rover-apps/common/CMakeLists.txt create mode 100644 rover-apps/common/include/Module.h create mode 100644 rover-apps/common/src/main.cpp create mode 100644 rover-apps/gimbal/include/AppConfig.h create mode 100644 rover-apps/science/include/AppConfig.h diff --git a/rover-apps/arm/include/AppConfig.h b/rover-apps/arm/include/AppConfig.h new file mode 100644 index 000000000..32f1383b4 --- /dev/null +++ b/rover-apps/arm/include/AppConfig.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +#include "Module.h" + +std::vector gModules = { + // put modules here +}; diff --git a/rover-apps/arm_2021/CMakeLists.txt b/rover-apps/arm_2021/CMakeLists.txt index 376fa47f3..4f56370ee 100644 --- a/rover-apps/arm_2021/CMakeLists.txt +++ b/rover-apps/arm_2021/CMakeLists.txt @@ -1,7 +1,14 @@ +<<<<<<< HEAD:rover-apps/arm_2021/CMakeLists.txt add_executable(arm_2021) target_sources(arm_2021 PRIVATE src/main.cpp) target_include_directories(arm_2021 PUBLIC include) target_link_libraries(arm_2021 +======= +add_executable(arm) +target_sources(arm PRIVATE ../common/src/main.cpp) +target_include_directories(arm PUBLIC include ../common/include) +target_link_libraries(arm +>>>>>>> Create modules skeleton for new app structure (#382):rover-apps/arm/CMakeLists.txt PRIVATE #Control OpenLoopController diff --git a/rover-apps/common/CMakeLists.txt b/rover-apps/common/CMakeLists.txt new file mode 100644 index 000000000..e69de29bb diff --git a/rover-apps/common/include/Module.h b/rover-apps/common/include/Module.h new file mode 100644 index 000000000..8df2b8cf8 --- /dev/null +++ b/rover-apps/common/include/Module.h @@ -0,0 +1,10 @@ +#pragma once + +class Module { + public: + virtual void periodic_10s(void) = 0; + virtual void periodic_1s(void) = 0; + virtual void periodic_100ms(void) = 0; + virtual void periodic_10ms(void) = 0; + virtual void periodic_1ms(void) = 0; +}; diff --git a/rover-apps/common/src/main.cpp b/rover-apps/common/src/main.cpp new file mode 100644 index 000000000..c60173cfb --- /dev/null +++ b/rover-apps/common/src/main.cpp @@ -0,0 +1,59 @@ +#include "AppConfig.h" +#include "mbed.h" + +Thread periodic_10s_thread(osPriorityNormal1); +Thread periodic_1s_thread(osPriorityNormal2); +Thread periodic_100ms_thread(osPriorityNormal3); +Thread periodic_10ms_thread(osPriorityNormal4); +Thread periodic_1ms_thread(osPriorityNormal5); + +void periodic_10s(void) { + auto startTime = Kernel::Clock::now(); + for (Module* module : gModules) { + module->periodic_10s(); + } + ThisThread::sleep_until(startTime + 10s); +} + +void periodic_1s(void) { + auto startTime = Kernel::Clock::now(); + for (Module* module : gModules) { + module->periodic_1s(); + } + ThisThread::sleep_until(startTime + 1s); +} + +void periodic_100ms(void) { + auto startTime = Kernel::Clock::now(); + for (Module* module : gModules) { + module->periodic_100ms(); + } + ThisThread::sleep_until(startTime + 100ms); +} + +void periodic_10ms(void) { + auto startTime = Kernel::Clock::now(); + for (Module* module : gModules) { + module->periodic_10ms(); + } + ThisThread::sleep_until(startTime + 10ms); +} + +void periodic_1ms(void) { + auto startTime = Kernel::Clock::now(); + for (Module* module : gModules) { + module->periodic_1ms(); + } + ThisThread::sleep_until(startTime + 1ms); +} + +int main() { + periodic_1ms_thread.start(periodic_1ms); + periodic_10ms_thread.start(periodic_10ms); + periodic_100ms_thread.start(periodic_100ms); + periodic_1s_thread.start(periodic_1s); + periodic_10s_thread.start(periodic_10s); + + while (true) { + } +} diff --git a/rover-apps/gimbal/include/AppConfig.h b/rover-apps/gimbal/include/AppConfig.h new file mode 100644 index 000000000..32f1383b4 --- /dev/null +++ b/rover-apps/gimbal/include/AppConfig.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +#include "Module.h" + +std::vector gModules = { + // put modules here +}; diff --git a/rover-apps/gimbal_2021/CMakeLists.txt b/rover-apps/gimbal_2021/CMakeLists.txt index 98296ac5c..0827366a2 100644 --- a/rover-apps/gimbal_2021/CMakeLists.txt +++ b/rover-apps/gimbal_2021/CMakeLists.txt @@ -1,7 +1,14 @@ +<<<<<<< HEAD:rover-apps/gimbal_2021/CMakeLists.txt add_executable(gimbal_2021) target_sources(gimbal_2021 PRIVATE src/main.cpp) target_include_directories(gimbal_2021 PUBLIC include) target_link_libraries(gimbal_2021 +======= +add_executable(gimbal) +target_sources(gimbal PRIVATE ../common/src/main.cpp) +target_include_directories(gimbal PUBLIC include ../common/include) +target_link_libraries(gimbal +>>>>>>> Create modules skeleton for new app structure (#382):rover-apps/gimbal/CMakeLists.txt PRIVATE #Control OpenLoopController diff --git a/rover-apps/science/include/AppConfig.h b/rover-apps/science/include/AppConfig.h new file mode 100644 index 000000000..32f1383b4 --- /dev/null +++ b/rover-apps/science/include/AppConfig.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +#include "Module.h" + +std::vector gModules = { + // put modules here +}; diff --git a/rover-apps/science_2021/CMakeLists.txt b/rover-apps/science_2021/CMakeLists.txt index 80b5d19b5..b273e1bbf 100644 --- a/rover-apps/science_2021/CMakeLists.txt +++ b/rover-apps/science_2021/CMakeLists.txt @@ -1,7 +1,14 @@ +<<<<<<< HEAD:rover-apps/science_2021/CMakeLists.txt add_executable(science_2021) target_sources(science_2021 PRIVATE src/main.cpp) target_include_directories(science_2021 PUBLIC include) target_link_libraries(science_2021 +======= +add_executable(science) +target_sources(science PRIVATE ../common/src/main.cpp) +target_include_directories(science PUBLIC include ../common/include) +target_link_libraries(science +>>>>>>> Create modules skeleton for new app structure (#382):rover-apps/science/CMakeLists.txt PRIVATE #Control OpenLoopController From 20010f141d406f60a9b41d5ecb61d99220dd9db2 Mon Sep 17 00:00:00 2001 From: jahnavithota2011 <34670246+jahnavithota2011@users.noreply.github.com> Date: Wed, 18 Aug 2021 23:17:59 +0400 Subject: [PATCH 02/12] Create watchdog module (#389) * Watchdog module * clang fix * clang fix2 * test-watchdog * Edited WatchdogWrapper.h * Fixed pure virtual function errors * fixed namespace error * Fixed error2 * Cmake * Cmake * Cmake fix * Top-level Cmake * Changes made * clang fix * Update libs/utility/src/WatchdogWrapper.cpp Co-authored-by: Cindy Li * Update test-apps/test-watchdog/src/main.cpp Co-authored-by: Cindy Li * cmake * Changed periodic function name * watchdogwrapper fix Co-authored-by: Cindy Li --- CMakeLists.txt | 1 + libs/utility/include/WatchdogWrapper.h | 9 +++----- libs/utility/src/WatchdogWrapper.cpp | 17 +++++---------- rover-apps/arm/include/AppConfig.h | 4 ++++ rover-apps/arm_2021/CMakeLists.txt | 2 ++ rover-apps/common/CMakeLists.txt | 8 ++++++++ rover-apps/common/include/WatchdogModule.h | 24 ++++++++++++++++++++++ rover-apps/common/src/WatchdogModule.cpp | 16 +++++++++++++++ rover-apps/gimbal/include/AppConfig.h | 4 ++++ rover-apps/gimbal_2021/CMakeLists.txt | 2 ++ rover-apps/science/include/AppConfig.h | 4 ++++ rover-apps/science_2021/CMakeLists.txt | 2 ++ test-apps/test-watchdog/src/main.cpp | 13 ++++++++++-- 13 files changed, 86 insertions(+), 20 deletions(-) create mode 100644 rover-apps/common/include/WatchdogModule.h create mode 100644 rover-apps/common/src/WatchdogModule.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 536525d49..b14defa08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,7 @@ add_app_subdirectory(${ROVER_APPS_DIR}/gamepad_2021) add_app_subdirectory(${ROVER_APPS_DIR}/gimbal_2021) add_app_subdirectory(${ROVER_APPS_DIR}/pdb_2021) add_app_subdirectory(${ROVER_APPS_DIR}/science_2021) +add_app_subdirectory(${ROVER_APPS_DIR}/common) # Include Test Apps add_app_subdirectory(${TEST_APPS_DIR}/test-actuator-controller) diff --git a/libs/utility/include/WatchdogWrapper.h b/libs/utility/include/WatchdogWrapper.h index f9034813f..723786ca9 100644 --- a/libs/utility/include/WatchdogWrapper.h +++ b/libs/utility/include/WatchdogWrapper.h @@ -5,11 +5,8 @@ namespace Utility { class WatchdogWrapper { public: - static void startWatchdog(std::chrono::milliseconds countdown_ms = 5000ms, std::chrono::milliseconds pet_ms = 1000ms); - static void logResetReason(); - - private: - static void petWatchdog(std::chrono::milliseconds *pet_ms); - static Thread pet_thread; + static void startWatchdog(std::chrono::milliseconds countdown_ms); + static void logResetReason(void); + static void petWatchdog(void); }; } // namespace Utility \ No newline at end of file diff --git a/libs/utility/src/WatchdogWrapper.cpp b/libs/utility/src/WatchdogWrapper.cpp index b3328074d..5e4b5b7c3 100644 --- a/libs/utility/src/WatchdogWrapper.cpp +++ b/libs/utility/src/WatchdogWrapper.cpp @@ -6,17 +6,13 @@ namespace Utility { -Thread WatchdogWrapper::pet_thread; - -void WatchdogWrapper::startWatchdog(std::chrono::milliseconds countdown_ms /*= 5000ms*/, - std::chrono::milliseconds pet_ms /*= 1000ms*/) { +void WatchdogWrapper::startWatchdog(std::chrono::milliseconds countdown_ms) { uint32_t countdown_uint32 = countdown_ms.count(); Watchdog &watchdog = Watchdog::get_instance(); watchdog.start(countdown_uint32); - pet_thread.start(callback(WatchdogWrapper::petWatchdog, &pet_ms)); } -void WatchdogWrapper::logResetReason() { +void WatchdogWrapper::logResetReason(void) { const reset_reason_t reason = ResetReason::get(); if (reason == RESET_REASON_WATCHDOG) { time_t seconds = time(NULL); @@ -26,10 +22,7 @@ void WatchdogWrapper::logResetReason() { } } -void WatchdogWrapper::petWatchdog(std::chrono::milliseconds *pet_ms) { - while (1) { - Watchdog::get_instance().kick(); - ThisThread::sleep_for(*pet_ms); - } +void WatchdogWrapper::petWatchdog(void) { + Watchdog::get_instance().kick(); } -} // namespace Utility \ No newline at end of file +} // namespace Utility diff --git a/rover-apps/arm/include/AppConfig.h b/rover-apps/arm/include/AppConfig.h index 32f1383b4..877d41d7e 100644 --- a/rover-apps/arm/include/AppConfig.h +++ b/rover-apps/arm/include/AppConfig.h @@ -3,7 +3,11 @@ #include #include "Module.h" +#include "WatchdogModule.h" + +WatchdogModule arm_watchdog; std::vector gModules = { // put modules here + &arm_watchdog, }; diff --git a/rover-apps/arm_2021/CMakeLists.txt b/rover-apps/arm_2021/CMakeLists.txt index 4f56370ee..b5e87df0d 100644 --- a/rover-apps/arm_2021/CMakeLists.txt +++ b/rover-apps/arm_2021/CMakeLists.txt @@ -28,6 +28,8 @@ target_link_libraries(arm CANMsg #Sensor CurrentSensor + #common-modules + WatchdogModule #Other uwrt-mars-rover-hw-bridge Logger diff --git a/rover-apps/common/CMakeLists.txt b/rover-apps/common/CMakeLists.txt index e69de29bb..6da4a69b8 100644 --- a/rover-apps/common/CMakeLists.txt +++ b/rover-apps/common/CMakeLists.txt @@ -0,0 +1,8 @@ +add_library(WatchdogModule STATIC) +target_sources(WatchdogModule PRIVATE src/WatchdogModule.cpp) +target_include_directories(WatchdogModule PUBLIC include) +target_link_libraries(WatchdogModule + PRIVATE + WatchdogWrapper + mbed-os + ) \ No newline at end of file diff --git a/rover-apps/common/include/WatchdogModule.h b/rover-apps/common/include/WatchdogModule.h new file mode 100644 index 000000000..3dbdfb423 --- /dev/null +++ b/rover-apps/common/include/WatchdogModule.h @@ -0,0 +1,24 @@ +#pragma once + +#include "Module.h" +#include "mbed.h" + +class WatchdogModule final : public Module { + public: + /* Initiates the watchdog with a countdown + * @param countdown - max timeout of the watchdog + * */ + WatchdogModule(); + + /* Periodic function to kick the watchdog and restart its timer every 1s + * */ + void periodic_1s(void) override; + + void periodic_10s(void) override {} + void periodic_100ms(void) override {} + void periodic_10ms(void) override {} + void periodic_1ms(void) override {} + + private: + static const std::chrono::milliseconds WATCHDOG_DEFAULT_COUNTDOWN; +}; diff --git a/rover-apps/common/src/WatchdogModule.cpp b/rover-apps/common/src/WatchdogModule.cpp new file mode 100644 index 000000000..14cac732c --- /dev/null +++ b/rover-apps/common/src/WatchdogModule.cpp @@ -0,0 +1,16 @@ +#include "WatchdogModule.h" + +#include "Module.h" +#include "WatchdogWrapper.h" +#include "mbed.h" + +const std::chrono::milliseconds WatchdogModule::WATCHDOG_DEFAULT_COUNTDOWN = 5000ms; + +WatchdogModule::WatchdogModule() { + Utility::WatchdogWrapper::logResetReason(); + Utility::WatchdogWrapper::startWatchdog(WATCHDOG_DEFAULT_COUNTDOWN); +} + +void WatchdogModule::periodic_1s(void) { + Utility::WatchdogWrapper::petWatchdog(); +} diff --git a/rover-apps/gimbal/include/AppConfig.h b/rover-apps/gimbal/include/AppConfig.h index 32f1383b4..35955ba8f 100644 --- a/rover-apps/gimbal/include/AppConfig.h +++ b/rover-apps/gimbal/include/AppConfig.h @@ -3,7 +3,11 @@ #include #include "Module.h" +#include "WatchdogModule.h" + +WatchdogModule gimbal_watchdog; std::vector gModules = { // put modules here + &gimbal_watchdog, }; diff --git a/rover-apps/gimbal_2021/CMakeLists.txt b/rover-apps/gimbal_2021/CMakeLists.txt index 0827366a2..756a260c5 100644 --- a/rover-apps/gimbal_2021/CMakeLists.txt +++ b/rover-apps/gimbal_2021/CMakeLists.txt @@ -26,6 +26,8 @@ target_link_libraries(gimbal CANMsg #Sensor CurrentSensor + #common-modules + WatchdogModule #Other Logger uwrt-mars-rover-hw-bridge diff --git a/rover-apps/science/include/AppConfig.h b/rover-apps/science/include/AppConfig.h index 32f1383b4..d196cd0bd 100644 --- a/rover-apps/science/include/AppConfig.h +++ b/rover-apps/science/include/AppConfig.h @@ -3,7 +3,11 @@ #include #include "Module.h" +#include "WatchdogModule.h" + +WatchdogModule science_watchdog; std::vector gModules = { // put modules here + &science_watchdog, }; diff --git a/rover-apps/science_2021/CMakeLists.txt b/rover-apps/science_2021/CMakeLists.txt index b273e1bbf..1f307a2ed 100644 --- a/rover-apps/science_2021/CMakeLists.txt +++ b/rover-apps/science_2021/CMakeLists.txt @@ -29,6 +29,8 @@ target_link_libraries(science #Sensor CurrentSensor AdafruitSTEMMA + #common-modules + WatchdogModule #Other uwrt-mars-rover-hw-bridge Logger diff --git a/test-apps/test-watchdog/src/main.cpp b/test-apps/test-watchdog/src/main.cpp index d6815ddbf..bcd5b38d8 100644 --- a/test-apps/test-watchdog/src/main.cpp +++ b/test-apps/test-watchdog/src/main.cpp @@ -1,12 +1,21 @@ #include "WatchdogWrapper.h" #include "mbed.h" +Thread pet_thread; std::chrono::milliseconds countdown_ms = 1000ms; std::chrono::milliseconds pet_ms = 200ms; +void pet_dog_task(std::chrono::milliseconds *pet_ms) { + while (1) { + Utility::WatchdogWrapper::petWatchdog(); + ThisThread::sleep_for(*pet_ms); + } +} + int main() { Utility::WatchdogWrapper::logResetReason(); - Utility::WatchdogWrapper::startWatchdog(countdown_ms, pet_ms); + Utility::WatchdogWrapper::startWatchdog(countdown_ms); + pet_thread.start(callback(pet_dog_task, &pet_ms)); ThisThread::sleep_for(2000ms); MBED_ASSERT(false); -} \ No newline at end of file +} From 1a488c7456321dea556f1cada98d1f8917042a5c Mon Sep 17 00:00:00 2001 From: jahnavithota2011 <34670246+jahnavithota2011@users.noreply.github.com> Date: Fri, 27 Aug 2021 01:05:36 +0400 Subject: [PATCH 03/12] Create PDB monitoring module (#392) * PDB Module added * CMake * rename include * Fixed Errors * clang fix * Changes made * Made pins config private members * clang --- rover-apps/pdb/CMakeLists.txt | 25 ++++ rover-apps/pdb/include/AppConfig.h | 13 ++ rover-apps/pdb/include/PDBMonitoring.h | 78 +++++++++++ rover-apps/pdb/src/PDBMonitoring.cpp | 132 ++++++++++++++++++ rover-apps/pdb_2021/CMakeLists.txt | 14 ++ .../TARGET_PDB_REV2_2021/include/PinNames.h | 23 +++ 6 files changed, 285 insertions(+) create mode 100644 rover-apps/pdb/CMakeLists.txt create mode 100644 rover-apps/pdb/include/AppConfig.h create mode 100644 rover-apps/pdb/include/PDBMonitoring.h create mode 100644 rover-apps/pdb/src/PDBMonitoring.cpp diff --git a/rover-apps/pdb/CMakeLists.txt b/rover-apps/pdb/CMakeLists.txt new file mode 100644 index 000000000..9d6d12523 --- /dev/null +++ b/rover-apps/pdb/CMakeLists.txt @@ -0,0 +1,25 @@ +add_library(PDB_Monitoring STATIC) +target_sources(PDB_Monitoring PRIVATE src/PDBMonitoring.cpp) +target_include_directories(PDB_Monitoring PUBLIC + include + ../common/include + ) +target_link_libraries(PDB_Monitoring + PRIVATE + Logger + mbed-os + ) + +add_executable(pdb) +target_sources(pdb PRIVATE ../common/src/main.cpp) +target_include_directories(pdb PUBLIC ../common/include) +target_link_libraries(pdb + PRIVATE + CANBus + CANMsg + Logger + uwrt-mars-rover-hw-bridge + #Modules + PDB_Monitoring + ) +mbed_set_post_build(pdb) diff --git a/rover-apps/pdb/include/AppConfig.h b/rover-apps/pdb/include/AppConfig.h new file mode 100644 index 000000000..17885fb14 --- /dev/null +++ b/rover-apps/pdb/include/AppConfig.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +#include "Module.h" +#include "PDBMonitoring.h" + +PDBMonitoring PDB; + +std::vector gModules = { + // put modules here + &PDB, +}; diff --git a/rover-apps/pdb/include/PDBMonitoring.h b/rover-apps/pdb/include/PDBMonitoring.h new file mode 100644 index 000000000..fc97ce0ba --- /dev/null +++ b/rover-apps/pdb/include/PDBMonitoring.h @@ -0,0 +1,78 @@ +#pragma once + +#include "Module.h" +#include "mbed.h" + +/*This PDB module is for load, rail and temperature monitoring.*/ + +class PDBMonitoring final : public Module { + public: + /* Sets the Load DIAG_EN pins */ + PDBMonitoring(); + + void periodic_1s(void) override; + void periodic_10s(void) override {} + void periodic_100ms(void) override {} + void periodic_10ms(void) override {} + void periodic_1ms(void) override; + + private: + void load_monitoring(); + void rail_monitoring(); + void temperature_monitoring(); + + static const float PDB_VBAT_RAIL_NOMINAL_VOLTAGE; + static const float PDB_VBAT_RAIL_MIN_THRESHOLD; + static const float PDB_VBAT_RAIL_MAX_THRESHOLD; + + static const float PDB_24V_RAIL_NOMINAL_VOLTAGE; + static const float PDB_24V_RAIL_MIN_THRESHOLD; + static const float PDB_24V_RAIL_MAX_THRESHOLD; + + static const float PDB_17V_RAIL_NOMINAL_VOLTAGE; + static const float PDB_17V_RAIL_MIN_THRESHOLD; + static const float PDB_17V_RAIL_MAX_THRESHOLD; + + static const float PDB_5V_RAIL_NOMINAL_VOLTAGE; + static const float PDB_5V_RAIL_MIN_THRESHOLD; + static const float PDB_5V_RAIL_MAX_THRESHOLD; + + static const float PDB_TEMPERATURE_MIN_THRESHOLD; + static const float PDB_TEMPERATURE_MAX_THRESHOLD; + + static const bool PDB_5V_LOAD1_DIAG_EN; + static const bool PDB_5V_LOAD2_DIAG_EN; + static const bool PDB_5V_LOAD3_DIAG_EN; + static const bool PDB_5V_LOAD4_DIAG_EN; + static const bool PDB_5V_LOAD5_DIAG_EN; + static const bool PDB_17V_LOAD_DIAG_EN; + + /* Pins configuration for Load Monitoring */ + DigitalOut load1_5V_diag_en; + DigitalIn load1_5V_fault_n; + + DigitalOut load2_5V_diag_en; + DigitalIn load2_5V_fault_n; + + DigitalOut load3_5V_diag_en; + DigitalIn load3_5V_fault_n; + + DigitalOut load4_5V_diag_en; + DigitalIn load4_5V_fault_n; + + DigitalOut load5_5V_diag_en; + DigitalIn load5_5V_fault_n; + + DigitalOut load_17V_diag_en; + DigitalIn load_17V_fault_n; + + /* Pins configuration for Rail Monitoring */ + AnalogIn railBattery; + AnalogIn rail5V; + AnalogIn rail17V; + AnalogIn rail24V; + DigitalIn rail24V_pgood_n; + + /* Pins configuration for Temperature Monitoring */ + AnalogIn temperatureADC; +}; \ No newline at end of file diff --git a/rover-apps/pdb/src/PDBMonitoring.cpp b/rover-apps/pdb/src/PDBMonitoring.cpp new file mode 100644 index 000000000..21fc5a824 --- /dev/null +++ b/rover-apps/pdb/src/PDBMonitoring.cpp @@ -0,0 +1,132 @@ +#include "PDBMonitoring.h" + +#include + +#include "Logger.h" + +const float PDBMonitoring::PDB_VBAT_RAIL_NOMINAL_VOLTAGE = 24.0; +const float PDBMonitoring::PDB_VBAT_RAIL_MIN_THRESHOLD = 18.0; +const float PDBMonitoring::PDB_VBAT_RAIL_MAX_THRESHOLD = 25.2; + +const float PDBMonitoring::PDB_24V_RAIL_NOMINAL_VOLTAGE = 24.0; +const float PDBMonitoring::PDB_24V_RAIL_MIN_THRESHOLD = 22.0; +const float PDBMonitoring::PDB_24V_RAIL_MAX_THRESHOLD = 26.0; + +const float PDBMonitoring::PDB_17V_RAIL_NOMINAL_VOLTAGE = 17.0; +const float PDBMonitoring::PDB_17V_RAIL_MIN_THRESHOLD = 16.0; +const float PDBMonitoring::PDB_17V_RAIL_MAX_THRESHOLD = 18.0; + +const float PDBMonitoring::PDB_5V_RAIL_NOMINAL_VOLTAGE = 5.0; +const float PDBMonitoring::PDB_5V_RAIL_MIN_THRESHOLD = 4.8; +const float PDBMonitoring::PDB_5V_RAIL_MAX_THRESHOLD = 6.0; + +const float PDBMonitoring::PDB_TEMPERATURE_MIN_THRESHOLD = 10.0; +const float PDBMonitoring::PDB_TEMPERATURE_MAX_THRESHOLD = 50.0; + +const bool PDBMonitoring::PDB_5V_LOAD1_DIAG_EN = 1; +const bool PDBMonitoring::PDB_5V_LOAD2_DIAG_EN = 0; +const bool PDBMonitoring::PDB_5V_LOAD3_DIAG_EN = 0; +const bool PDBMonitoring::PDB_5V_LOAD4_DIAG_EN = 0; +const bool PDBMonitoring::PDB_5V_LOAD5_DIAG_EN = 0; +const bool PDBMonitoring::PDB_17V_LOAD_DIAG_EN = 1; + +PDBMonitoring::PDBMonitoring() + : load1_5V_diag_en(LOAD1_5V_DIAG_EN), + load1_5V_fault_n(LOAD1_5V_FAULT), + load2_5V_diag_en(LOAD2_5V_DIAG_EN), + load2_5V_fault_n(LOAD2_5V_FAULT), + load3_5V_diag_en(LOAD3_5V_DIAG_EN), + load3_5V_fault_n(LOAD3_5V_FAULT), + load4_5V_diag_en(LOAD4_5V_DIAG_EN), + load4_5V_fault_n(LOAD4_5V_FAULT), + load5_5V_diag_en(LOAD5_5V_DIAG_EN), + load5_5V_fault_n(LOAD5_5V_FAULT), + load_17V_diag_en(LOAD_17V_DIAG_EN), + load_17V_fault_n(LOAD_17V_FAULT), + railBattery(RAIL_BATTERY_ANLG_IN), + rail5V(RAIL_5V_ANLG_IN), + rail17V(RAIL_17V_ANLG_IN), + rail24V(RAIL_24V_ANLG_IN), + rail24V_pgood_n(RAIL_24V_PGOOD_N), + temperatureADC(TEMPERATURE_ADC_IN) { + load1_5V_diag_en = PDB_5V_LOAD1_DIAG_EN; + load2_5V_diag_en = PDB_5V_LOAD2_DIAG_EN; + load3_5V_diag_en = PDB_5V_LOAD3_DIAG_EN; + load4_5V_diag_en = PDB_5V_LOAD4_DIAG_EN; + load5_5V_diag_en = PDB_5V_LOAD5_DIAG_EN; + load_17V_diag_en = PDB_17V_LOAD_DIAG_EN; +} + +/*TODO:Replace the logger statements with CAN logs + * after CAN Module is ready */ + +void PDBMonitoring::load_monitoring() { + if (load1_5V_diag_en && !load1_5V_fault_n) { + Utility::logger << "Fault on 5V load 1\n"; + } + if (load2_5V_diag_en && !load2_5V_fault_n) { + Utility::logger << "Fault on 5V load 2\n"; + } + if (load3_5V_diag_en && !load3_5V_fault_n) { + Utility::logger << "Fault on 5V load 3\n"; + } + if (load4_5V_diag_en && !load4_5V_fault_n) { + Utility::logger << "Fault on 5V load 4\n"; + } + if (load5_5V_diag_en && !load5_5V_fault_n) { + Utility::logger << "Fault on 5V load 5\n"; + } + if (load_17V_diag_en && !load_17V_fault_n) { + Utility::logger << "Fault on 17V load\n"; + } +} + +void PDBMonitoring::rail_monitoring() { + float rail_vbat_voltage = railBattery.read_voltage() / 3 * PDB_VBAT_RAIL_NOMINAL_VOLTAGE; + float rail_24V_voltage = rail24V.read_voltage() / 3 * PDB_24V_RAIL_NOMINAL_VOLTAGE; + float rail_17V_voltage = rail17V.read_voltage() / 3 * PDB_17V_RAIL_NOMINAL_VOLTAGE; + float rail_5V_voltage = rail5V.read_voltage() / 3 * PDB_5V_RAIL_NOMINAL_VOLTAGE; + + if (rail_vbat_voltage < PDB_VBAT_RAIL_MIN_THRESHOLD || rail_vbat_voltage > PDB_VBAT_RAIL_MAX_THRESHOLD) { + Utility::logger << "!!! VBAT RAIL VOLTAGE: %.3fV !!!\n", rail_vbat_voltage; + } + if (rail_24V_voltage < PDB_24V_RAIL_MIN_THRESHOLD || rail_24V_voltage > PDB_24V_RAIL_MAX_THRESHOLD) { + Utility::logger << "!!! 24V RAIL VOLTAGE: %.3fV !!!\n", rail_24V_voltage; + } + if (rail_17V_voltage < PDB_17V_RAIL_MIN_THRESHOLD || rail_17V_voltage > PDB_17V_RAIL_MAX_THRESHOLD) { + Utility::logger << "!!! 17V RAIL VOLTAGE: %.3fV !!!\n", rail_17V_voltage; + } + if (rail_5V_voltage < PDB_5V_RAIL_MIN_THRESHOLD || rail_5V_voltage > PDB_5V_RAIL_MAX_THRESHOLD) { + Utility::logger << "!!! 5V RAIL VOLTAGE: %.3fV !!!\n", rail_5V_voltage; + } +} + +/*https://www.ti.com/lit/ds/symlink/lmt87-q1.pdf?ts=1627158177761&ref_url=https%253A%252F%252Fwww.google.com%252F*/ + +void PDBMonitoring::temperature_monitoring() { + float temperature_celsius = + (13.582 - sqrt(pow(-13.582, 2) + 4 * 0.00433 * (2230.8 - temperatureADC.read_voltage() * 1000))) / + (2 * (-0.00433)) + + 30; + + if (temperature_celsius < PDB_TEMPERATURE_MIN_THRESHOLD || temperature_celsius > PDB_TEMPERATURE_MAX_THRESHOLD) { + Utility::logger << "!!! TEMPERATURE FAULT:" << temperature_celsius << "degrees Celsius\n"; + } +} + +void PDBMonitoring::periodic_1s() { + temperature_monitoring(); + load_monitoring(); +} + +void PDBMonitoring::periodic_1ms() { + /*Monitoring Period = 500ms*/ + int rail_counter = 0; + + if (rail_counter % 5 == 0) { + rail_monitoring(); + rail_counter = 0; + } + + rail_counter++; +} diff --git a/rover-apps/pdb_2021/CMakeLists.txt b/rover-apps/pdb_2021/CMakeLists.txt index 27d4cca70..4fde6c619 100644 --- a/rover-apps/pdb_2021/CMakeLists.txt +++ b/rover-apps/pdb_2021/CMakeLists.txt @@ -1,3 +1,15 @@ +add_library(PDB_Monitoring STATIC) +target_sources(PDB_Monitoring PRIVATE src/PDBMonitoring.cpp) +target_include_directories(PDB_Monitoring PUBLIC + include + ../common/include + ) +target_link_libraries(PDB_Monitoring + PRIVATE + Logger + mbed-os + ) + add_executable(pdb_2021) target_sources(pdb_2021 PRIVATE src/main.cpp) target_include_directories(pdb_2021 PUBLIC include) @@ -7,5 +19,7 @@ target_link_libraries(pdb_2021 CANMsg Logger uwrt-mars-rover-hw-bridge + #Modules + PDB_Monitoring ) mbed_set_post_build(pdb_2021) diff --git a/targets/TARGET_PDB_REV2_2021/include/PinNames.h b/targets/TARGET_PDB_REV2_2021/include/PinNames.h index ab8f8232d..94e25d908 100644 --- a/targets/TARGET_PDB_REV2_2021/include/PinNames.h +++ b/targets/TARGET_PDB_REV2_2021/include/PinNames.h @@ -171,6 +171,29 @@ typedef enum { RAIL_17V_ANLG_IN = PA_5, RAIL_24V_ANLG_IN = PB_0, RAIL_BATTERY_ANLG_IN = PB_1, + RAIL_24V_PGOOD_N = PC_6, + + /**** Temperature Sensor ****/ + TEMPERATURE_ADC_IN = PA_3, + + /**** Load Monitor ****/ + LOAD1_5V_DIAG_EN = PA_6, + LOAD1_5V_FAULT = PA_7, + + LOAD2_5V_DIAG_EN = PC_2, + LOAD2_5V_FAULT = PC_3, + + LOAD3_5V_DIAG_EN = PC_0, + LOAD3_5V_FAULT = PC_1, + + LOAD4_5V_DIAG_EN = PC_13, + LOAD4_5V_FAULT = PC_14, + + LOAD5_5V_DIAG_EN = PB_8, + LOAD5_5V_FAULT = PB_9, + + LOAD_17V_DIAG_EN = PC_4, + LOAD_17V_FAULT = PC_5, /**** LED Matrix ****/ LED_MATRIX_R_CHANNEL = PB_4, From 4de2cffcc52d14cdd4899f3162a696ae0a07511f Mon Sep 17 00:00:00 2001 From: Cindy Li Date: Sun, 17 Oct 2021 11:30:40 -0700 Subject: [PATCH 04/12] fix folder structure --- rover-apps/arm_2021/CMakeLists.txt | 11 ++------ .../{arm => arm_2021}/include/AppConfig.h | 0 rover-apps/gimbal_2021/CMakeLists.txt | 11 ++------ .../include/AppConfig.h | 0 rover-apps/pdb/CMakeLists.txt | 25 ------------------- rover-apps/pdb_2021/CMakeLists.txt | 4 +-- .../{pdb => pdb_2021}/include/AppConfig.h | 4 +-- .../{pdb => pdb_2021}/include/PDBMonitoring.h | 0 .../{pdb => pdb_2021}/src/PDBMonitoring.cpp | 0 rover-apps/science_2021/CMakeLists.txt | 11 ++------ .../include/AppConfig.h | 0 11 files changed, 10 insertions(+), 56 deletions(-) rename rover-apps/{arm => arm_2021}/include/AppConfig.h (100%) rename rover-apps/{gimbal => gimbal_2021}/include/AppConfig.h (100%) delete mode 100644 rover-apps/pdb/CMakeLists.txt rename rover-apps/{pdb => pdb_2021}/include/AppConfig.h (73%) rename rover-apps/{pdb => pdb_2021}/include/PDBMonitoring.h (100%) rename rover-apps/{pdb => pdb_2021}/src/PDBMonitoring.cpp (100%) rename rover-apps/{science => science_2021}/include/AppConfig.h (100%) diff --git a/rover-apps/arm_2021/CMakeLists.txt b/rover-apps/arm_2021/CMakeLists.txt index b5e87df0d..223a5681f 100644 --- a/rover-apps/arm_2021/CMakeLists.txt +++ b/rover-apps/arm_2021/CMakeLists.txt @@ -1,14 +1,7 @@ -<<<<<<< HEAD:rover-apps/arm_2021/CMakeLists.txt add_executable(arm_2021) -target_sources(arm_2021 PRIVATE src/main.cpp) -target_include_directories(arm_2021 PUBLIC include) +target_sources(arm_2021 PRIVATE ../common/src/main.cpp) +target_include_directories(arm_2021 PUBLIC include ../common/include) target_link_libraries(arm_2021 -======= -add_executable(arm) -target_sources(arm PRIVATE ../common/src/main.cpp) -target_include_directories(arm PUBLIC include ../common/include) -target_link_libraries(arm ->>>>>>> Create modules skeleton for new app structure (#382):rover-apps/arm/CMakeLists.txt PRIVATE #Control OpenLoopController diff --git a/rover-apps/arm/include/AppConfig.h b/rover-apps/arm_2021/include/AppConfig.h similarity index 100% rename from rover-apps/arm/include/AppConfig.h rename to rover-apps/arm_2021/include/AppConfig.h diff --git a/rover-apps/gimbal_2021/CMakeLists.txt b/rover-apps/gimbal_2021/CMakeLists.txt index 756a260c5..f03ee9221 100644 --- a/rover-apps/gimbal_2021/CMakeLists.txt +++ b/rover-apps/gimbal_2021/CMakeLists.txt @@ -1,14 +1,7 @@ -<<<<<<< HEAD:rover-apps/gimbal_2021/CMakeLists.txt add_executable(gimbal_2021) -target_sources(gimbal_2021 PRIVATE src/main.cpp) -target_include_directories(gimbal_2021 PUBLIC include) +target_sources(gimbal_2021 PRIVATE ../common/src/main.cpp) +target_include_directories(gimbal_2021 PUBLIC include ../common/include) target_link_libraries(gimbal_2021 -======= -add_executable(gimbal) -target_sources(gimbal PRIVATE ../common/src/main.cpp) -target_include_directories(gimbal PUBLIC include ../common/include) -target_link_libraries(gimbal ->>>>>>> Create modules skeleton for new app structure (#382):rover-apps/gimbal/CMakeLists.txt PRIVATE #Control OpenLoopController diff --git a/rover-apps/gimbal/include/AppConfig.h b/rover-apps/gimbal_2021/include/AppConfig.h similarity index 100% rename from rover-apps/gimbal/include/AppConfig.h rename to rover-apps/gimbal_2021/include/AppConfig.h diff --git a/rover-apps/pdb/CMakeLists.txt b/rover-apps/pdb/CMakeLists.txt deleted file mode 100644 index 9d6d12523..000000000 --- a/rover-apps/pdb/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -add_library(PDB_Monitoring STATIC) -target_sources(PDB_Monitoring PRIVATE src/PDBMonitoring.cpp) -target_include_directories(PDB_Monitoring PUBLIC - include - ../common/include - ) -target_link_libraries(PDB_Monitoring - PRIVATE - Logger - mbed-os - ) - -add_executable(pdb) -target_sources(pdb PRIVATE ../common/src/main.cpp) -target_include_directories(pdb PUBLIC ../common/include) -target_link_libraries(pdb - PRIVATE - CANBus - CANMsg - Logger - uwrt-mars-rover-hw-bridge - #Modules - PDB_Monitoring - ) -mbed_set_post_build(pdb) diff --git a/rover-apps/pdb_2021/CMakeLists.txt b/rover-apps/pdb_2021/CMakeLists.txt index 4fde6c619..241157b60 100644 --- a/rover-apps/pdb_2021/CMakeLists.txt +++ b/rover-apps/pdb_2021/CMakeLists.txt @@ -11,8 +11,8 @@ target_link_libraries(PDB_Monitoring ) add_executable(pdb_2021) -target_sources(pdb_2021 PRIVATE src/main.cpp) -target_include_directories(pdb_2021 PUBLIC include) +target_sources(pdb_2021 PRIVATE ../common/src/main.cpp) +target_include_directories(pdb_2021 PUBLIC include ../common/include) target_link_libraries(pdb_2021 PRIVATE CANBus diff --git a/rover-apps/pdb/include/AppConfig.h b/rover-apps/pdb_2021/include/AppConfig.h similarity index 73% rename from rover-apps/pdb/include/AppConfig.h rename to rover-apps/pdb_2021/include/AppConfig.h index 17885fb14..b2e56f21f 100644 --- a/rover-apps/pdb/include/AppConfig.h +++ b/rover-apps/pdb_2021/include/AppConfig.h @@ -5,9 +5,9 @@ #include "Module.h" #include "PDBMonitoring.h" -PDBMonitoring PDB; +PDBMonitoring PDB_monitoring; std::vector gModules = { // put modules here - &PDB, + &PDB_monitoring, }; diff --git a/rover-apps/pdb/include/PDBMonitoring.h b/rover-apps/pdb_2021/include/PDBMonitoring.h similarity index 100% rename from rover-apps/pdb/include/PDBMonitoring.h rename to rover-apps/pdb_2021/include/PDBMonitoring.h diff --git a/rover-apps/pdb/src/PDBMonitoring.cpp b/rover-apps/pdb_2021/src/PDBMonitoring.cpp similarity index 100% rename from rover-apps/pdb/src/PDBMonitoring.cpp rename to rover-apps/pdb_2021/src/PDBMonitoring.cpp diff --git a/rover-apps/science_2021/CMakeLists.txt b/rover-apps/science_2021/CMakeLists.txt index 1f307a2ed..08f066f30 100644 --- a/rover-apps/science_2021/CMakeLists.txt +++ b/rover-apps/science_2021/CMakeLists.txt @@ -1,14 +1,7 @@ -<<<<<<< HEAD:rover-apps/science_2021/CMakeLists.txt add_executable(science_2021) -target_sources(science_2021 PRIVATE src/main.cpp) -target_include_directories(science_2021 PUBLIC include) +target_sources(science_2021 PRIVATE ../common/src/main.cpp) +target_include_directories(science_2021 PUBLIC include ../common/include) target_link_libraries(science_2021 -======= -add_executable(science) -target_sources(science PRIVATE ../common/src/main.cpp) -target_include_directories(science PUBLIC include ../common/include) -target_link_libraries(science ->>>>>>> Create modules skeleton for new app structure (#382):rover-apps/science/CMakeLists.txt PRIVATE #Control OpenLoopController diff --git a/rover-apps/science/include/AppConfig.h b/rover-apps/science_2021/include/AppConfig.h similarity index 100% rename from rover-apps/science/include/AppConfig.h rename to rover-apps/science_2021/include/AppConfig.h From 3f052b13b7bdf6831ea89d061d3c6dbbcd84b567 Mon Sep 17 00:00:00 2001 From: Cindy Li Date: Sun, 17 Oct 2021 12:01:03 -0700 Subject: [PATCH 05/12] fix common modules not found --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b14defa08..0a747dc23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,12 +89,12 @@ function(add_app_subdirectory APP_SUBDIRECTORY) endfunction() ## Include Rover Apps +add_subdirectory(${ROVER_APPS_DIR}/common) add_app_subdirectory(${ROVER_APPS_DIR}/arm_2021) add_app_subdirectory(${ROVER_APPS_DIR}/gamepad_2021) add_app_subdirectory(${ROVER_APPS_DIR}/gimbal_2021) add_app_subdirectory(${ROVER_APPS_DIR}/pdb_2021) add_app_subdirectory(${ROVER_APPS_DIR}/science_2021) -add_app_subdirectory(${ROVER_APPS_DIR}/common) # Include Test Apps add_app_subdirectory(${TEST_APPS_DIR}/test-actuator-controller) From d1c8689cf10bc8954630c11f84e8f50c9b3bfc4a Mon Sep 17 00:00:00 2001 From: upadhyaydhruv Date: Sat, 15 Jan 2022 16:35:34 -0500 Subject: [PATCH 06/12] created CANModule and fixed txProcessor function --- libs/can/include/CANInterface.h | 2 +- libs/can/include/CANModule.h | 18 +++++++ libs/can/src/CANInterface.cpp | 78 +++++++++++++-------------- rover-apps/common/include/CANModule.h | 17 ++++++ rover-apps/common/src/CANModule.cpp | 21 ++++++++ 5 files changed, 94 insertions(+), 42 deletions(-) create mode 100644 libs/can/include/CANModule.h create mode 100644 rover-apps/common/include/CANModule.h create mode 100644 rover-apps/common/src/CANModule.cpp diff --git a/libs/can/include/CANInterface.h b/libs/can/include/CANInterface.h index 0c0bf4f41..104915083 100644 --- a/libs/can/include/CANInterface.h +++ b/libs/can/include/CANInterface.h @@ -36,7 +36,7 @@ class CANInterface { bool getRXSignalValue(HWBRIDGE::CANID msgID, HWBRIDGE::CANSIGNAL signalName, HWBRIDGE::CANSignalValue_t &signalValue); // Switch CAN bus - bool switchCANBus(HWBRIDGE::CANBUSID canBusID); + bool switchCANBus(HWBRIDGE::CANBUSID canBusID); // TODO: Unnecessary // Set CAN bus hw filter bool setFilter(HWBRIDGE::CANFILTER filter, CANFormat format = CANStandard, diff --git a/libs/can/include/CANModule.h b/libs/can/include/CANModule.h new file mode 100644 index 000000000..2e0b42923 --- /dev/null +++ b/libs/can/include/CANModule.h @@ -0,0 +1,18 @@ +#pragma onceusing + +#include "Module.h" +#include "mbed.h" +#include "CANInterface.h" + +class CANModule final : public Module { + public: + + CANModule(); + + void periodic_1ms(void) override {} + void periodic_10ms(void) override {} + + + private: + CANInterface +} \ No newline at end of file diff --git a/libs/can/src/CANInterface.cpp b/libs/can/src/CANInterface.cpp index 685413383..45cc8f115 100644 --- a/libs/can/src/CANInterface.cpp +++ b/libs/can/src/CANInterface.cpp @@ -59,8 +59,8 @@ void CANInterface::rxClient(void) { // Wait for a message to arrive do { mail = m_rxMailbox.try_get(); // using try_get() because try_get_for() was crashing - ThisThread::sleep_for(1ms); - } while (mail == nullptr); + ThisThread::sleep_for(1ms); // TODO: Check for object in mailbox every ms + } while (mail == nullptr); MBED_ASSERT(mail != nullptr); @@ -112,51 +112,47 @@ void CANInterface::rxClient(void) { } void CANInterface::txProcessor(void) { - while (true) { - auto startTime = Kernel::Clock::now(); + auto startTime = Kernel::Clock::now(); - CANMsg *mail = nullptr; + CANMsg *mail = nullptr; - // Send all one-shot messages that were queued - while ((mail = m_txMailboxOneShot.try_get()) != nullptr) { - if (!m_activeCANBus->write(*mail)) { - MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_WRITE_FAILED), "CAN TX write failed"); - m_numCANTXFaults++; - } - MBED_ASSERT(m_txMailboxOneShot.free(mail) == osOK); - ThisThread::sleep_for(TX_INTERDELAY); + // Send all one-shot messages that were queued + while ((mail = m_txMailboxOneShot.try_get()) != nullptr) { + if (!m_activeCANBus->write(*mail)) { + MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_WRITE_FAILED), "CAN TX write failed"); + m_numCANTXFaults++; } + MBED_ASSERT(m_txMailboxOneShot.free(mail) == osOK); + ThisThread::sleep_for(TX_INTERDELAY); + } - // Send all streamed messages - if (m_txMsgMap != nullptr) { - for (auto it = m_txMsgMap->begin(); it != m_txMsgMap->end(); it++) { - HWBRIDGE::CANID msgID = it->first; - HWBRIDGE::CANMsgData_t msgData = {0}; - size_t len = 0; - - m_txMutex.lock(); - bool msgPacked = HWBRIDGE::packCANMsg(msgData.raw, msgID, m_txMsgMap, len); - m_txMutex.unlock(); - - if (msgPacked) { - // Send message - CANMsg msg; - msg.setID(msgID); - msg.setPayload(msgData, len); - m_activeCANBus->write(msg); - - m_numStreamedMsgsSent++; - - ThisThread::sleep_for(TX_INTERDELAY); - } else { - MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_DATA_DETECTED), - "CAN TX message packing failed"); - m_numCANTXFaults++; - } + // Send all streamed messages + if (m_txMsgMap != nullptr) { + for (auto it = m_txMsgMap->begin(); it != m_txMsgMap->end(); it++) { + HWBRIDGE::CANID msgID = it->first; + HWBRIDGE::CANMsgData_t msgData = {0}; + size_t len = 0; + + m_txMutex.lock(); + bool msgPacked = HWBRIDGE::packCANMsg(msgData.raw, msgID, m_txMsgMap, len); + m_txMutex.unlock(); + + if (msgPacked) { + // Send message + CANMsg msg; + msg.setID(msgID); + msg.setPayload(msgData, len); + m_activeCANBus->write(msg); + + m_numStreamedMsgsSent++; + + ThisThread::sleep_for(TX_INTERDELAY); + } else { + MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_DATA_DETECTED), + "CAN TX message packing failed"); + m_numCANTXFaults++; } } - - ThisThread::sleep_until(startTime + TX_PERIOD); } } diff --git a/rover-apps/common/include/CANModule.h b/rover-apps/common/include/CANModule.h new file mode 100644 index 000000000..081b5be26 --- /dev/null +++ b/rover-apps/common/include/CANModule.h @@ -0,0 +1,17 @@ +#pragma onceusing + +#include "CANInterface.h" +#include "Module.h" +#include "mbed.h" + +class CANModule final : public Module { + public: + CANModule(const Config &config); + + void periodic_1ms(void) override {} + void periodic_10ms(void) override {} + + private: + CANInterface interface; + +}; \ No newline at end of file diff --git a/rover-apps/common/src/CANModule.cpp b/rover-apps/common/src/CANModule.cpp new file mode 100644 index 000000000..09c6ffe8b --- /dev/null +++ b/rover-apps/common/src/CANModule.cpp @@ -0,0 +1,21 @@ +#include "CANModule.h" + +#include "Module.h" +#include "mbed.h" + +// Using initializer lists to construct CANInterface object will attach ISRs and other required tasks +CANModule::CANModule(const Config &config) : interface(config) { + // Nothing should be required here +} + +void CANModule::periodic_1ms(void) { + + // These functions need to be called at 1 kHz, or every 1ms + interface.rxClient(); +} + +void CANModule::periodic_10ms(void) { + + // These functions need to be called every 100 Hz (10ms) + interface.txProcessor(); +} \ No newline at end of file From 5de8de916d48e52de07aa3ed81a63be17285984a Mon Sep 17 00:00:00 2001 From: upadhyaydhruv Date: Sat, 15 Jan 2022 16:37:35 -0500 Subject: [PATCH 07/12] fixed rxClient function for modular use --- libs/can/src/CANInterface.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libs/can/src/CANInterface.cpp b/libs/can/src/CANInterface.cpp index 45cc8f115..1340b73b8 100644 --- a/libs/can/src/CANInterface.cpp +++ b/libs/can/src/CANInterface.cpp @@ -55,12 +55,8 @@ void CANInterface::rxPostman(void) { void CANInterface::rxClient(void) { while (true) { CANMsg *mail = nullptr; - - // Wait for a message to arrive - do { - mail = m_rxMailbox.try_get(); // using try_get() because try_get_for() was crashing - ThisThread::sleep_for(1ms); // TODO: Check for object in mailbox every ms - } while (mail == nullptr); + // Check if a message has arrived: + mail = m_rxMailbox.try_get(); MBED_ASSERT(mail != nullptr); From 2c23625e1efcfa173eb1b63b2b8bb9f6cc7d8679 Mon Sep 17 00:00:00 2001 From: upadhyaydhruv Date: Sat, 15 Jan 2022 16:53:20 -0500 Subject: [PATCH 08/12] made CMake linking changes for CANModule --- rover-apps/common/CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rover-apps/common/CMakeLists.txt b/rover-apps/common/CMakeLists.txt index 6da4a69b8..49758775e 100644 --- a/rover-apps/common/CMakeLists.txt +++ b/rover-apps/common/CMakeLists.txt @@ -5,4 +5,14 @@ target_link_libraries(WatchdogModule PRIVATE WatchdogWrapper mbed-os - ) \ No newline at end of file + ) + +add_library(CANModule) +target_sources(CANModule PRIVATE src/CANModule.cpp) +target_include_directories(CANModule PUBLIC include) +target_link_libraries(CANModule + PRIVATE + CANInterface + mbed-os + ) + From 541583dba2602c4c19d18a47c445f36b0def3c1d Mon Sep 17 00:00:00 2001 From: upadhyaydhruv Date: Wed, 2 Feb 2022 22:12:20 -0500 Subject: [PATCH 09/12] implemented most changes as requested by Melvion and Cindy --- libs/can/include/CANInterface.h | 6 +- libs/can/src/CANInterface.cpp | 89 +++++++++---------- rover-apps/common/CMakeLists.txt | 8 +- .../{CANModule.h => CANDriverModule.h} | 0 .../{CANModule.cpp => CANDriverModule.cpp} | 0 5 files changed, 46 insertions(+), 57 deletions(-) rename rover-apps/common/include/{CANModule.h => CANDriverModule.h} (100%) rename rover-apps/common/src/{CANModule.cpp => CANDriverModule.cpp} (100%) diff --git a/libs/can/include/CANInterface.h b/libs/can/include/CANInterface.h index 104915083..ce8f90529 100644 --- a/libs/can/include/CANInterface.h +++ b/libs/can/include/CANInterface.h @@ -60,16 +60,14 @@ class CANInterface { void rxISR(void); void rxPostman(void); - void rxClient(void); - void txProcessor(void); + void rxClientPeriodic(void); + void txProcessorPeriodic(void); CANBus m_CANBus1; CANBus m_CANBus2; CANBus *m_activeCANBus; Thread m_rxPostmanThread; - Thread m_rxClientThread; - Thread m_txProcessorThread; Mutex m_rxMutex; Mutex m_txMutex; diff --git a/libs/can/src/CANInterface.cpp b/libs/can/src/CANInterface.cpp index 1340b73b8..3c4246e7d 100644 --- a/libs/can/src/CANInterface.cpp +++ b/libs/can/src/CANInterface.cpp @@ -5,8 +5,6 @@ CANInterface::CANInterface(const Config &config) m_CANBus2(config.can2_RX, config.can2_TX, config.frequency_hz), m_activeCANBus(&m_CANBus1), m_rxPostmanThread(RX_POSTMAN_THREAD_PRIORITY), - m_rxClientThread(RX_CLIENT_THREAD_PRIORITY), - m_txProcessorThread(TX_PROCESSOR_THREAD_PRIORITY), m_rxMsgMap(config.rxMsgMap), m_txMsgMap(config.txMsgMap), m_rxOneShotMsgHandler(config.rxOneShotMsgHandler), @@ -22,8 +20,6 @@ CANInterface::CANInterface(const Config &config) // Processing threads m_rxPostmanThread.start(callback(&m_rxEventQueue, &EventQueue::dispatch_forever)); - m_rxClientThread.start(callback(this, &CANInterface::rxClient)); - m_txProcessorThread.start(callback(this, &CANInterface::txProcessor)); // RX ISR m_CANBus1.attach(callback(this, &CANInterface::rxISR), CAN::RxIrq); @@ -52,63 +48,60 @@ void CANInterface::rxPostman(void) { can_irq_set(m_activeCANBus->getHandle(), IRQ_RX, true); } -void CANInterface::rxClient(void) { - while (true) { - CANMsg *mail = nullptr; - // Check if a message has arrived: - mail = m_rxMailbox.try_get(); +void CANInterface::rxClientPeriodic(void) { + CANMsg *mail = nullptr; + // Check if a message has arrived: + mail = m_rxMailbox.try_get(); + + MBED_ASSERT(mail != nullptr); - MBED_ASSERT(mail != nullptr); + // Extract message + CANMsg msg = *mail; + MBED_ASSERT(m_rxMailbox.free(mail) == osOK); - // Extract message - CANMsg msg = *mail; - MBED_ASSERT(m_rxMailbox.free(mail) == osOK); + // Check if message is intended to be received by this node + m_rxMutex.lock(); + bool validMsgReceived = (m_rxMsgMap != nullptr) && m_rxMsgMap->contains(msg.getID()); + m_rxMutex.unlock(); - // Check if message is intended to be received by this node + if (validMsgReceived) { + HWBRIDGE::CANMsgData_t msgData; + msg.getPayload(msgData); + + // Extract message signals and put into RX message map m_rxMutex.lock(); - bool validMsgReceived = (m_rxMsgMap != nullptr) && m_rxMsgMap->contains(msg.getID()); + bool msgUnpacked = HWBRIDGE::unpackCANMsg(msgData.raw, msg.getID(), m_rxMsgMap); m_rxMutex.unlock(); - if (validMsgReceived) { - HWBRIDGE::CANMsgData_t msgData; - msg.getPayload(msgData); - - // Extract message signals and put into RX message map - m_rxMutex.lock(); - bool msgUnpacked = HWBRIDGE::unpackCANMsg(msgData.raw, msg.getID(), m_rxMsgMap); - m_rxMutex.unlock(); - - if (msgUnpacked) { - // If message is one-shot, process message - if ((m_rxOneShotMsgHandler != nullptr) && m_rxOneShotMsgHandler->contains(msg.getID())) { - if (m_rxOneShotMsgHandler->at(msg.getID())() != MBED_SUCCESS) { - MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_FAILED_OPERATION), - "Failed to process CAN message"); - } - m_numOneShotMsgsReceived++; - } - // Otherwise message is streamed - else { - m_numStreamedMsgsReceived++; + if (msgUnpacked) { + // If message is one-shot, process message + if ((m_rxOneShotMsgHandler != nullptr) && m_rxOneShotMsgHandler->contains(msg.getID())) { + if (m_rxOneShotMsgHandler->at(msg.getID())() != MBED_SUCCESS) { + MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_FAILED_OPERATION), + "Failed to process CAN message"); } - } else { - MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_DATA_DETECTED), - "CAN RX message unpacking failed"); - m_numCANRXFaults++; + m_numOneShotMsgsReceived++; } - } - - // Otherwise invalid message was received - else { + // Otherwise message is streamed + else { + m_numStreamedMsgsReceived++; + } + } else { MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_DATA_DETECTED), - "Invalid CAN message received"); + "CAN RX message unpacking failed"); m_numCANRXFaults++; } } + + // Otherwise invalid message was received + else { + MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_DATA_DETECTED), + "Invalid CAN message received"); + m_numCANRXFaults++; + } } -void CANInterface::txProcessor(void) { - auto startTime = Kernel::Clock::now(); +void CANInterface::txProcessorPeriodic(void) { CANMsg *mail = nullptr; @@ -119,7 +112,6 @@ void CANInterface::txProcessor(void) { m_numCANTXFaults++; } MBED_ASSERT(m_txMailboxOneShot.free(mail) == osOK); - ThisThread::sleep_for(TX_INTERDELAY); } // Send all streamed messages @@ -142,7 +134,6 @@ void CANInterface::txProcessor(void) { m_numStreamedMsgsSent++; - ThisThread::sleep_for(TX_INTERDELAY); } else { MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_DATA_DETECTED), "CAN TX message packing failed"); diff --git a/rover-apps/common/CMakeLists.txt b/rover-apps/common/CMakeLists.txt index 49758775e..e7d6dde16 100644 --- a/rover-apps/common/CMakeLists.txt +++ b/rover-apps/common/CMakeLists.txt @@ -7,10 +7,10 @@ target_link_libraries(WatchdogModule mbed-os ) -add_library(CANModule) -target_sources(CANModule PRIVATE src/CANModule.cpp) -target_include_directories(CANModule PUBLIC include) -target_link_libraries(CANModule +add_library(CANDriverModule) +target_sources(CANDriverModule PRIVATE src/CANDriverModule.cpp) +target_include_directories(CANDriverModule PUBLIC include) +target_link_libraries(CANDriverModule PRIVATE CANInterface mbed-os diff --git a/rover-apps/common/include/CANModule.h b/rover-apps/common/include/CANDriverModule.h similarity index 100% rename from rover-apps/common/include/CANModule.h rename to rover-apps/common/include/CANDriverModule.h diff --git a/rover-apps/common/src/CANModule.cpp b/rover-apps/common/src/CANDriverModule.cpp similarity index 100% rename from rover-apps/common/src/CANModule.cpp rename to rover-apps/common/src/CANDriverModule.cpp From 6947dd6f63bf0399a849dfa7b028bf7c8d3d424a Mon Sep 17 00:00:00 2001 From: upadhyaydhruv Date: Thu, 3 Feb 2022 19:27:48 -0500 Subject: [PATCH 10/12] added all changes requested, hw bridge issue persists --- libs/can/src/CANInterface.cpp | 72 +++++++++++++++++------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/libs/can/src/CANInterface.cpp b/libs/can/src/CANInterface.cpp index 3c4246e7d..e6b949b68 100644 --- a/libs/can/src/CANInterface.cpp +++ b/libs/can/src/CANInterface.cpp @@ -53,52 +53,52 @@ void CANInterface::rxClientPeriodic(void) { // Check if a message has arrived: mail = m_rxMailbox.try_get(); - MBED_ASSERT(mail != nullptr); + if (mail != nullptr) { + // Extract message + CANMsg msg = *mail; + MBED_ASSERT(m_rxMailbox.free(mail) == osOK); - // Extract message - CANMsg msg = *mail; - MBED_ASSERT(m_rxMailbox.free(mail) == osOK); - - // Check if message is intended to be received by this node - m_rxMutex.lock(); - bool validMsgReceived = (m_rxMsgMap != nullptr) && m_rxMsgMap->contains(msg.getID()); - m_rxMutex.unlock(); - - if (validMsgReceived) { - HWBRIDGE::CANMsgData_t msgData; - msg.getPayload(msgData); - - // Extract message signals and put into RX message map + // Check if message is intended to be received by this node m_rxMutex.lock(); - bool msgUnpacked = HWBRIDGE::unpackCANMsg(msgData.raw, msg.getID(), m_rxMsgMap); + bool validMsgReceived = (m_rxMsgMap != nullptr) && m_rxMsgMap->contains(msg.getID()); m_rxMutex.unlock(); - if (msgUnpacked) { - // If message is one-shot, process message - if ((m_rxOneShotMsgHandler != nullptr) && m_rxOneShotMsgHandler->contains(msg.getID())) { - if (m_rxOneShotMsgHandler->at(msg.getID())() != MBED_SUCCESS) { - MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_FAILED_OPERATION), - "Failed to process CAN message"); + if (validMsgReceived) { + HWBRIDGE::CANMsgData_t msgData; + msg.getPayload(msgData); + + // Extract message signals and put into RX message map + m_rxMutex.lock(); + bool msgUnpacked = HWBRIDGE::unpackCANMsg(msgData.raw, msg.getID(), m_rxMsgMap); + m_rxMutex.unlock(); + + if (msgUnpacked) { + // If message is one-shot, process message + if ((m_rxOneShotMsgHandler != nullptr) && m_rxOneShotMsgHandler->contains(msg.getID())) { + if (m_rxOneShotMsgHandler->at(msg.getID())() != MBED_SUCCESS) { + MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_FAILED_OPERATION), + "Failed to process CAN message"); + } + m_numOneShotMsgsReceived++; } - m_numOneShotMsgsReceived++; - } - // Otherwise message is streamed - else { - m_numStreamedMsgsReceived++; + // Otherwise message is streamed + else { + m_numStreamedMsgsReceived++; + } + } else { + MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_DATA_DETECTED), + "CAN RX message unpacking failed"); + m_numCANRXFaults++; } - } else { + } + + // Otherwise invalid message was received + else { MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_DATA_DETECTED), - "CAN RX message unpacking failed"); + "Invalid CAN message received"); m_numCANRXFaults++; } } - - // Otherwise invalid message was received - else { - MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_DATA_DETECTED), - "Invalid CAN message received"); - m_numCANRXFaults++; - } } void CANInterface::txProcessorPeriodic(void) { From a667ffacd3f607c580001539a7a4dfece5d1d616 Mon Sep 17 00:00:00 2001 From: upadhyaydhruv Date: Thu, 10 Feb 2022 17:59:38 -0500 Subject: [PATCH 11/12] fixed issues preventing compilation --- libs/can/CMakeLists.txt | 1 - libs/can/include/CANInterface.h | 5 +++-- libs/can/include/CANModule.h | 18 ------------------ rover-apps/common/CMakeLists.txt | 4 ++-- rover-apps/common/include/CANDriverModule.h | 20 +++++++++++++------- rover-apps/common/src/CANDriverModule.cpp | 16 ++++++++-------- rover-apps/science_2021/CMakeLists.txt | 1 + rover-apps/science_2021/include/AppConfig.h | 1 + 8 files changed, 28 insertions(+), 38 deletions(-) delete mode 100644 libs/can/include/CANModule.h diff --git a/libs/can/CMakeLists.txt b/libs/can/CMakeLists.txt index 472dca768..c77449f0e 100644 --- a/libs/can/CMakeLists.txt +++ b/libs/can/CMakeLists.txt @@ -33,7 +33,6 @@ target_link_libraries(CANInterface PUBLIC mbed-os mbed-events - PRIVATE uwrt-mars-rover-hw-bridge CANBus CANMsg diff --git a/libs/can/include/CANInterface.h b/libs/can/include/CANInterface.h index ce8f90529..ebb3202be 100644 --- a/libs/can/include/CANInterface.h +++ b/libs/can/include/CANInterface.h @@ -51,6 +51,9 @@ class CANInterface { uint16_t getNumCANRXFaults(void); uint16_t getNumCANTXFaults(void); + void rxClientPeriodic(void); + void txProcessorPeriodic(void); + private: static constexpr osPriority RX_POSTMAN_THREAD_PRIORITY = osPriorityRealtime; static constexpr osPriority RX_CLIENT_THREAD_PRIORITY = osPriorityAboveNormal; @@ -60,8 +63,6 @@ class CANInterface { void rxISR(void); void rxPostman(void); - void rxClientPeriodic(void); - void txProcessorPeriodic(void); CANBus m_CANBus1; CANBus m_CANBus2; diff --git a/libs/can/include/CANModule.h b/libs/can/include/CANModule.h deleted file mode 100644 index 2e0b42923..000000000 --- a/libs/can/include/CANModule.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma onceusing - -#include "Module.h" -#include "mbed.h" -#include "CANInterface.h" - -class CANModule final : public Module { - public: - - CANModule(); - - void periodic_1ms(void) override {} - void periodic_10ms(void) override {} - - - private: - CANInterface -} \ No newline at end of file diff --git a/rover-apps/common/CMakeLists.txt b/rover-apps/common/CMakeLists.txt index e7d6dde16..b3a746144 100644 --- a/rover-apps/common/CMakeLists.txt +++ b/rover-apps/common/CMakeLists.txt @@ -7,12 +7,12 @@ target_link_libraries(WatchdogModule mbed-os ) -add_library(CANDriverModule) +add_library(CANDriverModule STATIC) target_sources(CANDriverModule PRIVATE src/CANDriverModule.cpp) target_include_directories(CANDriverModule PUBLIC include) target_link_libraries(CANDriverModule PRIVATE CANInterface - mbed-os + mbed-os ) diff --git a/rover-apps/common/include/CANDriverModule.h b/rover-apps/common/include/CANDriverModule.h index 081b5be26..2bf32c350 100644 --- a/rover-apps/common/include/CANDriverModule.h +++ b/rover-apps/common/include/CANDriverModule.h @@ -1,17 +1,23 @@ -#pragma onceusing +#pragma once #include "CANInterface.h" #include "Module.h" #include "mbed.h" +#include "CANBus.h" +#include "CANMsg.h" +#include "hw_bridge.h" +#include "mbed.h" -class CANModule final : public Module { +class CANDriverModule final : public Module { public: - CANModule(const Config &config); + CANDriverModule(const CANInterface::Config &config); + void periodic_1s(void) override; - void periodic_1ms(void) override {} - void periodic_10ms(void) override {} + void periodic_10s(void) override; + void periodic_100ms(void) override; + void periodic_10ms(void) override; + void periodic_1ms(void) override; private: CANInterface interface; - -}; \ No newline at end of file +}; diff --git a/rover-apps/common/src/CANDriverModule.cpp b/rover-apps/common/src/CANDriverModule.cpp index 09c6ffe8b..78adfe853 100644 --- a/rover-apps/common/src/CANDriverModule.cpp +++ b/rover-apps/common/src/CANDriverModule.cpp @@ -1,21 +1,21 @@ -#include "CANModule.h" - +#include "CANDriverModule.h" +#include "CANInterface.h" #include "Module.h" #include "mbed.h" // Using initializer lists to construct CANInterface object will attach ISRs and other required tasks -CANModule::CANModule(const Config &config) : interface(config) { - // Nothing should be required here +CANDriverModule::CANDriverModule(const CANInterface::Config &config) : interface(config) { + // Nothing should be required here } -void CANModule::periodic_1ms(void) { +void CANDriverModule::periodic_1ms(void) { // These functions need to be called at 1 kHz, or every 1ms - interface.rxClient(); + interface.rxClientPeriodic(); } -void CANModule::periodic_10ms(void) { +void CANDriverModule::periodic_10ms(void) { // These functions need to be called every 100 Hz (10ms) - interface.txProcessor(); + interface.txProcessorPeriodic(); } \ No newline at end of file diff --git a/rover-apps/science_2021/CMakeLists.txt b/rover-apps/science_2021/CMakeLists.txt index 08f066f30..91fcf7109 100644 --- a/rover-apps/science_2021/CMakeLists.txt +++ b/rover-apps/science_2021/CMakeLists.txt @@ -24,6 +24,7 @@ target_link_libraries(science_2021 AdafruitSTEMMA #common-modules WatchdogModule + CANDriverModule #Other uwrt-mars-rover-hw-bridge Logger diff --git a/rover-apps/science_2021/include/AppConfig.h b/rover-apps/science_2021/include/AppConfig.h index d196cd0bd..b8f123544 100644 --- a/rover-apps/science_2021/include/AppConfig.h +++ b/rover-apps/science_2021/include/AppConfig.h @@ -4,6 +4,7 @@ #include "Module.h" #include "WatchdogModule.h" +#include "CANDriverModule.h" WatchdogModule science_watchdog; From a0d658b097df214ab50e7c404375c809acef9718 Mon Sep 17 00:00:00 2001 From: upadhyaydhruv Date: Sun, 13 Feb 2022 21:20:48 -0500 Subject: [PATCH 12/12] added wrapper for other CANInterface functions --- rover-apps/arm_2021/CMakeLists.txt | 1 + rover-apps/arm_2021/include/AppConfig.h | 4 ++ rover-apps/common/CMakeLists.txt | 1 + rover-apps/common/include/CANDriverModule.h | 21 +++++++++ rover-apps/common/src/CANDriverModule.cpp | 50 ++++++++++++++++++++- 5 files changed, 76 insertions(+), 1 deletion(-) diff --git a/rover-apps/arm_2021/CMakeLists.txt b/rover-apps/arm_2021/CMakeLists.txt index 223a5681f..f969f8adf 100644 --- a/rover-apps/arm_2021/CMakeLists.txt +++ b/rover-apps/arm_2021/CMakeLists.txt @@ -23,6 +23,7 @@ target_link_libraries(arm_2021 CurrentSensor #common-modules WatchdogModule + CANDriverModule #Other uwrt-mars-rover-hw-bridge Logger diff --git a/rover-apps/arm_2021/include/AppConfig.h b/rover-apps/arm_2021/include/AppConfig.h index 877d41d7e..954df3039 100644 --- a/rover-apps/arm_2021/include/AppConfig.h +++ b/rover-apps/arm_2021/include/AppConfig.h @@ -4,6 +4,10 @@ #include "Module.h" #include "WatchdogModule.h" +#include "CANDriverModule.h" +#include "CANConfig.h" +#include "hw_bridge.h" +#include "CANInterface.h" WatchdogModule arm_watchdog; diff --git a/rover-apps/common/CMakeLists.txt b/rover-apps/common/CMakeLists.txt index b3a746144..02a84ee4b 100644 --- a/rover-apps/common/CMakeLists.txt +++ b/rover-apps/common/CMakeLists.txt @@ -13,6 +13,7 @@ target_include_directories(CANDriverModule PUBLIC include) target_link_libraries(CANDriverModule PRIVATE CANInterface + CANMsg mbed-os ) diff --git a/rover-apps/common/include/CANDriverModule.h b/rover-apps/common/include/CANDriverModule.h index 2bf32c350..1ef3b2e73 100644 --- a/rover-apps/common/include/CANDriverModule.h +++ b/rover-apps/common/include/CANDriverModule.h @@ -17,6 +17,27 @@ class CANDriverModule final : public Module { void periodic_100ms(void) override; void periodic_10ms(void) override; void periodic_1ms(void) override; + void rxPostman(void); + bool sendOneShotMessage(CANMsg &msg, Kernel::Clock::duration_u32 timeout); + + // Update a TX CAN signal + bool setTXSignalValue(HWBRIDGE::CANID msgID, HWBRIDGE::CANSIGNAL signalName, HWBRIDGE::CANSignalValue_t signalValue); + + // Read a RX CAN signal + bool getRXSignalValue(HWBRIDGE::CANID msgID, HWBRIDGE::CANSIGNAL signalName, HWBRIDGE::CANSignalValue_t &signalValue); + + // Set CAN bus hw filter + bool setFilter(HWBRIDGE::CANFILTER filter, CANFormat format = CANStandard, + uint16_t mask = HWBRIDGE::ROVER_CANID_FILTER_MASK, int handle = 0); + + // For diagnostic purposes + uint32_t getNumStreamedMsgsReceived(void); + uint32_t getNumOneShotMsgsReceived(void); + uint32_t getNumStreamedMsgsSent(void); + uint32_t getNumOneShotMsgsSent(void); + + uint16_t getNumCANRXFaults(void); + uint16_t getNumCANTXFaults(void); private: CANInterface interface; diff --git a/rover-apps/common/src/CANDriverModule.cpp b/rover-apps/common/src/CANDriverModule.cpp index 78adfe853..d31424f52 100644 --- a/rover-apps/common/src/CANDriverModule.cpp +++ b/rover-apps/common/src/CANDriverModule.cpp @@ -18,4 +18,52 @@ void CANDriverModule::periodic_10ms(void) { // These functions need to be called every 100 Hz (10ms) interface.txProcessorPeriodic(); -} \ No newline at end of file +} + +void CANDriverModule::rxPostman(void) { + interface.rxPostman(); +} + +bool CANDriverModule::sendOneShotMessage(CANMsg &msg, Kernel::Clock::duration_u32 timeout) { + return interface.sendOneShotMessage(msg, timeout); +} + +bool CANDriverModule::setTXSignalValue(HWBRIDGE::CANID msgID, HWBRIDGE::CANSIGNAL signalName, + HWBRIDGE::CANSignalValue_t signalValue) { + return interface.setTXSignalValue(msgID, signalName, signalValue); +} + +bool CANDriverModule::getRXSignalValue(HWBRIDGE::CANID msgID, HWBRIDGE::CANSIGNAL signalName, HWBRIDGE::CANSignalValue_t &signalValue) { + return interface.getRXSignalValue(msgID, signalName, signalValue); +} + +bool CANDriverModule::setFilter(HWBRIDGE::CANFILTER filter, CANFormat format = CANStandard, + uint16_t mask = HWBRIDGE::ROVER_CANID_FILTER_MASK, int handle = 0) { + return interface.setFilter(filter, format, mask, handle); +} + +uint32_t CANDriverModule::getNumStreamedMsgsReceived(void) { + return interface.getNumStreamedMsgsReceived(); +} + +uint32_t CANDriverModule::getNumOneShotMsgsReceived(void) { + return interface.getNumOneShotMsgsReceived(); +} + +uint32_t CANDriverModule::getNumStreamedMsgsSent(void) { + return interface.getNumStreamedMsgsSent(); +} + +uint32_t CANDriverModule::getNumOneShotMsgsSent(void) { + return interface.getNumOneShotMsgsSent(); +} + +uint16_t CANDriverModule::getNumCANRXFaults(void) { + return interface.getNumCANRXFaults(); +} + +uint16_t CANDriverModule::getNumCANTXFaults(void) { + return interface.getNumCANTXFaults(); +} + +