From ad71c4d8c6d1bccab3ee613933aea5dafca4d72a Mon Sep 17 00:00:00 2001 From: Cindy Li Date: Tue, 25 May 2021 23:27:12 -0400 Subject: [PATCH] CAN: rebase master --- apps/arm/CMakeLists.txt | 27 -- apps/gimbal/CMakeLists.txt | 25 -- apps/test-can/CMakeLists.txt | 11 - apps/test-can/src/main_old.cpp | 71 ----- apps/test-stress-can/CMakeLists.txt | 11 - libs/can/CMakeLists.txt | 7 +- libs/can/include/CANInterface.h | 94 +++++++ libs/can/src/CANInterface.cpp | 261 ++++++++++++++++++ mbed-os | 2 +- rover-apps/arm/include/CANConfig.h | 2 + rover-apps/gimbal/include/CANConfig.h | 2 + rover-apps/science/include/CANConfig.h | 2 + test-apps/test-can/CMakeLists.txt | 2 + test-apps/test-stress-can/CMakeLists.txt | 12 + .../test-stress-can/include/CANConfigArm.h | 23 +- .../test-stress-can/include/CANConfigGimbal.h | 20 +- .../test-stress-can/include/CANConfigPDB.h | 0 .../include/CANConfigScience.h | 22 +- .../test-stress-can/src/main.cpp | 0 uwrt-mars-rover-hw-bridge | 2 +- 20 files changed, 403 insertions(+), 193 deletions(-) delete mode 100644 apps/arm/CMakeLists.txt delete mode 100644 apps/gimbal/CMakeLists.txt delete mode 100644 apps/test-can/CMakeLists.txt delete mode 100644 apps/test-can/src/main_old.cpp delete mode 100644 apps/test-stress-can/CMakeLists.txt create mode 100644 libs/can/include/CANInterface.h create mode 100644 libs/can/src/CANInterface.cpp create mode 100644 test-apps/test-stress-can/CMakeLists.txt rename {apps => test-apps}/test-stress-can/include/CANConfigArm.h (86%) rename {apps => test-apps}/test-stress-can/include/CANConfigGimbal.h (71%) rename {apps => test-apps}/test-stress-can/include/CANConfigPDB.h (100%) rename {apps => test-apps}/test-stress-can/include/CANConfigScience.h (76%) rename {apps => test-apps}/test-stress-can/src/main.cpp (100%) diff --git a/apps/arm/CMakeLists.txt b/apps/arm/CMakeLists.txt deleted file mode 100644 index e02382631..000000000 --- a/apps/arm/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -add_executable(arm.${TARGET}-board.elf) -target_sources(arm.${TARGET}-board.elf PRIVATE src/main.cpp) -target_include_directories(arm.${TARGET}-board.elf PUBLIC include) -target_link_libraries(arm.${TARGET}-board.elf - PRIVATE -#Control - OpenLoopController - PositionController - VelocityController - CurrentController - ActuatorControllerManager -#Motors - LimServo - DCMotor -#Encoders - EncoderAEAT6012 - EncoderMAE3 - EncoderPololu37D -#CAN - CANInterface - CANMsg -#Sensor - CurrentSensor -#Other - uwrt-mars-rover-hw-bridge - Logger) -target_set_firmware_properties(arm.${TARGET}-board.elf) diff --git a/apps/gimbal/CMakeLists.txt b/apps/gimbal/CMakeLists.txt deleted file mode 100644 index b8d45a2b0..000000000 --- a/apps/gimbal/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -add_executable(gimbal.${TARGET}-board.elf) -target_sources(gimbal.${TARGET}-board.elf PRIVATE src/main.cpp) -target_include_directories(gimbal.${TARGET}-board.elf PUBLIC include) -target_link_libraries(gimbal.${TARGET}-board.elf PRIVATE - PRIVATE -#Control - OpenLoopController - PositionController - VelocityController - CurrentController - ActuatorControllerManager -#Motors - LimServo - ContServo -#Encoders - EncoderAEAT6012 -#CAN - CANInterface - CANMsg -#Sensor - CurrentSensor -#Other - Logger - uwrt-mars-rover-hw-bridge) -target_set_firmware_properties(gimbal.${TARGET}-board.elf) diff --git a/apps/test-can/CMakeLists.txt b/apps/test-can/CMakeLists.txt deleted file mode 100644 index ebbe711fa..000000000 --- a/apps/test-can/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -add_executable(test-can.${TARGET}-board.elf) -target_sources(test-can.${TARGET}-board.elf PRIVATE src/main.cpp) -target_include_directories(test-can.${TARGET}-board.elf PUBLIC include) -target_link_libraries(test-can.${TARGET}-board.elf - PRIVATE - CANInterface - CANMsg - uwrt-mars-rover-hw-bridge - Logger -) -target_set_firmware_properties(test-can.${TARGET}-board.elf) diff --git a/apps/test-can/src/main_old.cpp b/apps/test-can/src/main_old.cpp deleted file mode 100644 index be5216f2a..000000000 --- a/apps/test-can/src/main_old.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "CANBus.h" -#include "CANMsg.h" -#include "Logger.h" -#include "hw_bridge.h" -#include "mbed.h" - -CANBus can(CAN1_RX, CAN1_TX, HWBRIDGE::ROVERCONFIG::ROVER_CANBUS_FREQUENCY); -CANMsg rxMsg; -CANMsg txMsg; -DigitalOut ledTX(LED1); -DigitalOut ledRX(LED2); -Timer timer; -uint8_t counter = 0; - -constexpr uint16_t TX_ID = 0x100; -constexpr uint16_t RX_ID = 0x101; - -/** - * @brief Prints CAN msg to PC's serial terminal - * @note - * @param CANMsg to print - * @retval - */ -void printMsg(CANMsg& msg) { - printf(" ID = 0x%.3x\r\n", static_cast(msg.getID())); - printf(" Type = %d\r\n", msg.type); - printf(" Format = %d\r\n", msg.format); - printf(" Length = %d\r\n", msg.len); - printf(" Data ="); - for (int i = 0; i < msg.len; i++) printf(" 0x%.2X", msg.data[i]); - printf("\r\n"); -} - -int main(void) { - ledTX = 0; // set transmit LED off - ledRX = 0; // set recieve LED off - timer.start(); // start timer - printf("CAN_Hello\r\n"); - - while (1) { - if (timer.elapsed_time() >= 1s) { // check for timeout - timer.reset(); // reset timer - counter++; // increment counter - txMsg.clear(); // clear Tx message storage - txMsg.setID(static_cast(TX_ID)); // set ID - txMsg << counter; // copy counter value to CAN msg payload - if (can.write(txMsg)) { // transmit message - printf("-------------------------------------\r\n"); - printf("CAN message sent\r\n"); - printMsg(txMsg); - printf(" counter = %d\r\n", counter); - ledTX = !ledTX; - } else - printf("Transmission error\r\n"); - } - - if (can.read(rxMsg)) { - ledRX = !ledRX; // turn the LED on - printf("-------------------------------------\r\n"); - printf("CAN message received\r\n"); - printMsg(rxMsg); - - // Filtering performed by software: - if (rxMsg.getID() == static_cast(RX_ID)) { - rxMsg >> counter; // extract data from the received CAN message - printf(" counter = %d\r\n", counter); - timer.start(); // transmission lag - } - } - } -} diff --git a/apps/test-stress-can/CMakeLists.txt b/apps/test-stress-can/CMakeLists.txt deleted file mode 100644 index 39d17d854..000000000 --- a/apps/test-stress-can/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -add_executable(test-stress-can.${TARGET}-board.elf) -target_sources(test-stress-can.${TARGET}-board.elf PRIVATE src/main.cpp) -target_include_directories(test-stress-can.${TARGET}-board.elf PUBLIC include) -target_link_libraries(test-stress-can.${TARGET}-board.elf - PRIVATE - CANInterface - CANMsg - uwrt-mars-rover-hw-bridge - Logger -) -target_set_firmware_properties(test-stress-can.${TARGET}-board.elf) diff --git a/libs/can/CMakeLists.txt b/libs/can/CMakeLists.txt index 7eae7a2e1..dbcd2fb71 100644 --- a/libs/can/CMakeLists.txt +++ b/libs/can/CMakeLists.txt @@ -21,12 +21,10 @@ add_library(CANBus STATIC) target_sources(CANBus PRIVATE src/CANBus.cpp) target_include_directories(CANBus PUBLIC include) target_link_libraries(CANBus - PUBLIC - mbed-os PRIVATE uwrt-mars-rover-hw-bridge + mbed-os ) -target_set_mbed_dependency(CANBus) add_library(CANInterface STATIC) target_sources(CANInterface PRIVATE src/CANInterface.cpp) @@ -36,5 +34,6 @@ target_link_libraries(CANInterface uwrt-mars-rover-hw-bridge CANBus CANMsg + mbed-os + mbed-events ) -target_set_mbed_dependency(CANInterface) diff --git a/libs/can/include/CANInterface.h b/libs/can/include/CANInterface.h new file mode 100644 index 000000000..0c0bf4f41 --- /dev/null +++ b/libs/can/include/CANInterface.h @@ -0,0 +1,94 @@ +#pragma once + +#include "CANBus.h" +#include "CANMsg.h" +#include "hw_bridge.h" +#include "mbed.h" + +class CANInterface { + public: + typedef struct { + // CAN bus pins + PinName can1_RX; + PinName can1_TX; + PinName can2_RX; + PinName can2_TX; + + // Message maps and handlers + HWBRIDGE::CANMsgMap *rxMsgMap; + HWBRIDGE::CANMsgMap *txMsgMap; + const CANMsg::CANMsgHandlerMap *rxOneShotMsgHandler; + + // Bus frequency + uint32_t frequency_hz = HWBRIDGE::ROVER_CANBUS_FREQUENCY_HZ; + } Config; + + // Initialize CAN interface + CANInterface(const Config &config); + + // Queue up a one shot message to be sent + 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); + + // Switch CAN bus + bool switchCANBus(HWBRIDGE::CANBUSID canBusID); + + // 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: + static constexpr osPriority RX_POSTMAN_THREAD_PRIORITY = osPriorityRealtime; + static constexpr osPriority RX_CLIENT_THREAD_PRIORITY = osPriorityAboveNormal; + static constexpr osPriority TX_PROCESSOR_THREAD_PRIORITY = osPriorityBelowNormal; + static constexpr std::chrono::milliseconds TX_INTERDELAY = 1ms; + static constexpr std::chrono::milliseconds TX_PERIOD = 10ms; + + void rxISR(void); + void rxPostman(void); + void rxClient(void); + void txProcessor(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; + + Mail m_rxMailbox; + Mail m_txMailboxOneShot; + EventQueue m_rxEventQueue; + + HWBRIDGE::CANMsgMap *m_rxMsgMap; + HWBRIDGE::CANMsgMap *m_txMsgMap; + + const CANMsg::CANMsgHandlerMap *m_rxOneShotMsgHandler; + + // For diagnostic purposes + uint32_t m_numStreamedMsgsReceived; + uint32_t m_numOneShotMsgsReceived; + uint32_t m_numStreamedMsgsSent; + uint32_t m_numOneShotMsgsSent; + + uint16_t m_numCANRXFaults; + uint16_t m_numCANTXFaults; +}; diff --git a/libs/can/src/CANInterface.cpp b/libs/can/src/CANInterface.cpp new file mode 100644 index 000000000..685413383 --- /dev/null +++ b/libs/can/src/CANInterface.cpp @@ -0,0 +1,261 @@ +#include "CANInterface.h" + +CANInterface::CANInterface(const Config &config) + : m_CANBus1(config.can1_RX, config.can1_TX, config.frequency_hz), + 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), + m_numStreamedMsgsReceived(0), + m_numOneShotMsgsReceived(0), + m_numStreamedMsgsSent(0), + m_numOneShotMsgsSent(0), + m_numCANRXFaults(0), + m_numCANTXFaults(0) { + // Put CAN bus 2 in silent monitoring mode, also disable CAN 2 RX interrupts + m_CANBus2.monitor(true); + can_irq_set(m_CANBus2.getHandle(), IRQ_RX, false); + + // 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); + m_CANBus2.attach(callback(this, &CANInterface::rxISR), CAN::RxIrq); +} + +void CANInterface::rxISR(void) { + can_irq_set(m_activeCANBus->getHandle(), IRQ_RX, false); + m_rxEventQueue.call(callback(this, &CANInterface::rxPostman)); +} + +void CANInterface::rxPostman(void) { + CANMsg msg; + // this loop is needed to avoid missing msg received between turning off the IRQ and turning it back on + while (m_activeCANBus->read(msg)) { + CANMsg *mail = m_rxMailbox.try_alloc(); // no wait + + if (mail != nullptr) { + *mail = msg; + MBED_ASSERT(m_rxMailbox.put(mail) == osOK); + } else { + MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_BUFFER_FULL), "CAN RX mailbox full"); + m_numCANRXFaults++; + } + } + can_irq_set(m_activeCANBus->getHandle(), IRQ_RX, true); +} + +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); + } while (mail == nullptr); + + MBED_ASSERT(mail != nullptr); + + // 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 + 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++; + } + } else { + MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_DATA_DETECTED), + "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) { + while (true) { + auto startTime = Kernel::Clock::now(); + + 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 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); + } +} + +bool CANInterface::sendOneShotMessage(CANMsg &msg, Kernel::Clock::duration_u32 timeout) { + CANMsg *mail = m_txMailboxOneShot.try_alloc_for(timeout); + if (mail) { + *mail = msg; + MBED_ASSERT(m_txMailboxOneShot.put(mail) == osOK); + m_numOneShotMsgsSent++; + return true; + } + return false; +} + +bool CANInterface::setTXSignalValue(HWBRIDGE::CANID msgID, HWBRIDGE::CANSIGNAL signalName, + HWBRIDGE::CANSignalValue_t signalValue) { + m_txMutex.lock(); + bool success = (m_txMsgMap != nullptr) && m_txMsgMap->setSignalValue(msgID, signalName, signalValue); + m_txMutex.unlock(); + return success; +} + +bool CANInterface::getRXSignalValue(HWBRIDGE::CANID msgID, HWBRIDGE::CANSIGNAL signalName, + HWBRIDGE::CANSignalValue_t &signalValue) { + m_rxMutex.lock(); + bool success = (m_rxMsgMap != nullptr) && m_rxMsgMap->getSignalValue(msgID, signalName, signalValue); + m_rxMutex.unlock(); + return success; +} + +bool CANInterface::switchCANBus(HWBRIDGE::CANBUSID canBusID) { + bool success = false; + + switch (canBusID) { + case HWBRIDGE::CANBUSID::CANBUS1: + if (m_activeCANBus != &m_CANBus1) { + // Disable CAN 2 + can_irq_set(m_CANBus2.getHandle(), IRQ_RX, false); + m_CANBus2.monitor(true); + + // Enable CAN 1 + m_activeCANBus = &m_CANBus1; + can_irq_set(m_CANBus1.getHandle(), IRQ_RX, true); + m_CANBus1.monitor(false); + } + success = true; + break; + + case HWBRIDGE::CANBUSID::CANBUS2: + if (m_activeCANBus != &m_CANBus2) { + // Disable CAN 1 + can_irq_set(m_CANBus1.getHandle(), IRQ_RX, false); + m_CANBus1.monitor(true); + + // Enable CAN 2 + m_activeCANBus = &m_CANBus2; + can_irq_set(m_CANBus2.getHandle(), IRQ_RX, true); + m_CANBus2.monitor(false); + } + success = true; + break; + + default: + success = false; + break; + } + + return success; +} + +bool CANInterface::setFilter(HWBRIDGE::CANFILTER filter, CANFormat format, uint16_t mask, int handle) { + bool success = true; + if (handle >= 0 && handle < 14) { + success &= m_CANBus1.setFilter(filter, format, mask, handle); // CAN 1 filter banks: 0-13 + success &= m_CANBus2.setFilter(filter, format, mask, handle + 14); // CAN 2 filter banks: 14-27 + } + return success; +} + +uint32_t CANInterface::getNumStreamedMsgsReceived(void) { + return m_numStreamedMsgsReceived; +} + +uint32_t CANInterface::getNumOneShotMsgsReceived(void) { + return m_numOneShotMsgsReceived; +} + +uint32_t CANInterface::getNumStreamedMsgsSent(void) { + return m_numStreamedMsgsSent; +} + +uint32_t CANInterface::getNumOneShotMsgsSent(void) { + return m_numOneShotMsgsSent; +} + +uint16_t CANInterface::getNumCANRXFaults(void) { + return m_numCANRXFaults; +} + +uint16_t CANInterface::getNumCANTXFaults(void) { + return m_numCANTXFaults; +} diff --git a/mbed-os b/mbed-os index f2278567d..3681094cb 160000 --- a/mbed-os +++ b/mbed-os @@ -1 +1 @@ -Subproject commit f2278567d09b9ae9f4843e1d9d393526b9462783 +Subproject commit 3681094cb2e543984a297103f95f6fffb0e917a7 diff --git a/rover-apps/arm/include/CANConfig.h b/rover-apps/arm/include/CANConfig.h index 57422204f..79f3f9a57 100644 --- a/rover-apps/arm/include/CANConfig.h +++ b/rover-apps/arm/include/CANConfig.h @@ -123,6 +123,8 @@ static CANMsgMap txMsgMap = { (CANSignalValue_t)ARM_RIGHT_WRIST_CURRENT_SENSOR_STATE_VALUES::SNA}, {CANSIGNAL::ARM_CLAW_ENCODER_STATE, (CANSignalValue_t)ARM_CLAW_ENCODER_STATE_VALUES::SNA}, {CANSIGNAL::ARM_CLAW_CURRENT_SENSOR_STATE, (CANSignalValue_t)ARM_CLAW_CURRENT_SENSOR_STATE_VALUES::SNA}, + {CANSIGNAL::ARM_NUM_CANRX_FAULTS, 0}, + {CANSIGNAL::ARM_NUM_CANTX_FAULTS, 0}, }}, {CANID::ARM_REPORT_DIAGNOSTICS, { diff --git a/rover-apps/gimbal/include/CANConfig.h b/rover-apps/gimbal/include/CANConfig.h index 92cc5f587..f7354642d 100644 --- a/rover-apps/gimbal/include/CANConfig.h +++ b/rover-apps/gimbal/include/CANConfig.h @@ -55,6 +55,8 @@ static CANMsgMap txMsgMap = { {CANID::GIMBAL_REPORT_FAULTS, { {CANSIGNAL::GIMBAL_PAN_ENCODER_STATE, (CANSignalValue_t)GIMBAL_PAN_ENCODER_STATE_VALUES::SNA}, + {CANSIGNAL::GIMBAL_NUM_CANRX_FAULTS, 0}, + {CANSIGNAL::GIMBAL_NUM_CANTX_FAULTS, 0}, }}, {CANID::GIMBAL_REPORT_DIAGNOSTICS, { diff --git a/rover-apps/science/include/CANConfig.h b/rover-apps/science/include/CANConfig.h index 6d638f9e1..ae551c39c 100644 --- a/rover-apps/science/include/CANConfig.h +++ b/rover-apps/science/include/CANConfig.h @@ -67,6 +67,8 @@ static CANMsgMap txMsgMap = { {CANSIGNAL::SCIENCE_GENEVA_ENCODER_STATE, (CANSignalValue_t)SCIENCE_GENEVA_ENCODER_STATE_VALUES::SNA}, {CANSIGNAL::SCIENCE_ELEVATOR_ENCODER_STATE, (CANSignalValue_t)SCIENCE_ELEVATOR_ENCODER_STATE_VALUES::SNA}, {CANSIGNAL::SCIENCE_MOISTURE_SENSOR_STATE, (CANSignalValue_t)SCIENCE_MOISTURE_SENSOR_STATE_VALUES::SNA}, + {CANSIGNAL::SCIENCE_NUM_CANRX_FAULTS, 0}, + {CANSIGNAL::SCIENCE_NUM_CANTX_FAULTS, 0}, }}, {CANID::SCIENCE_REPORT_DIAGNOSTICS, { diff --git a/test-apps/test-can/CMakeLists.txt b/test-apps/test-can/CMakeLists.txt index 57312c67e..9fe3e3a31 100644 --- a/test-apps/test-can/CMakeLists.txt +++ b/test-apps/test-can/CMakeLists.txt @@ -2,9 +2,11 @@ add_executable(test-can) target_sources(test-can PRIVATE src/main.cpp) target_link_libraries(test-can PRIVATE + CANInterface CANBus CANMsg Logger mbed-os + uwrt-mars-rover-hw-bridge ) mbed_set_post_build(test-can) diff --git a/test-apps/test-stress-can/CMakeLists.txt b/test-apps/test-stress-can/CMakeLists.txt new file mode 100644 index 000000000..850d2e0ca --- /dev/null +++ b/test-apps/test-stress-can/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable(test-stress-can) +target_sources(test-stress-can PRIVATE src/main.cpp) +target_include_directories(test-stress-can PUBLIC include) +target_link_libraries(test-stress-can + PRIVATE + CANInterface + CANMsg + uwrt-mars-rover-hw-bridge + mbed-os + Logger +) +mbed_set_post_build(test-stress-can) diff --git a/apps/test-stress-can/include/CANConfigArm.h b/test-apps/test-stress-can/include/CANConfigArm.h similarity index 86% rename from apps/test-stress-can/include/CANConfigArm.h rename to test-apps/test-stress-can/include/CANConfigArm.h index 25437e1ee..79f3f9a57 100644 --- a/apps/test-stress-can/include/CANConfigArm.h +++ b/test-apps/test-stress-can/include/CANConfigArm.h @@ -4,16 +4,11 @@ #include "CANMsg.h" #include "hw_bridge.h" -const HWBRIDGE::CANFILTER targetCANIDFilter = HWBRIDGE::CANFILTER::ARM_RX_FILTER; -const HWBRIDGE::CANID targetReportDiagnosticsCANID = HWBRIDGE::CANID::ARM_REPORT_DIAGNOSTICS; -const HWBRIDGE::CANSIGNAL targetReportNumStreamedSignal = HWBRIDGE::CANSIGNAL::ARM_REPORT_NUM_STREAMED_MSGS_RECEIVED; -const HWBRIDGE::CANSIGNAL targetReportNumOneShotsSignal = HWBRIDGE::CANSIGNAL::ARM_REPORT_NUM_ONE_SHOT_MSGS_RECEIVED; -const HWBRIDGE::CANID targetReportFaultsCANID = HWBRIDGE::CANID::ARM_REPORT_FAULTS; -const HWBRIDGE::CANSIGNAL targetNumCANRXFaultsSignal = HWBRIDGE::CANSIGNAL::ARM_NUM_CANRX_FAULTS; -const HWBRIDGE::CANSIGNAL targetNumCANTXFaultsSignal = HWBRIDGE::CANSIGNAL::ARM_NUM_CANTX_FAULTS; - -static mbed_error_status_t oneShotHandler(void); -static mbed_error_status_t switchCANBus(void); +static void sendACK(HWBRIDGE::ARM_ACK_VALUES ackValue); +static mbed_error_status_t armSetControlMode(void); +static mbed_error_status_t armSetJointPIDParams(void); +static mbed_error_status_t armSetSafetyCheck(void); +static mbed_error_status_t commonSwitchCANBus(void); namespace CANConfig { @@ -139,10 +134,10 @@ static CANMsgMap txMsgMap = { }; const static CANMsg::CANMsgHandlerMap rxOneShotMsgHandler = { - {CANID::ARM_SET_CONTROL_MODE, &oneShotHandler}, - {CANID::ARM_SET_JOINT_PID_PARAMS, &oneShotHandler}, - {CANID::ARM_SET_JOINT_SAFETY_CHECK, &oneShotHandler}, - {CANID::COMMON_SWITCH_CAN_BUS, &switchCANBus}, + {CANID::ARM_SET_CONTROL_MODE, &armSetControlMode}, + {CANID::ARM_SET_JOINT_PID_PARAMS, &armSetJointPIDParams}, + {CANID::ARM_SET_JOINT_SAFETY_CHECK, &armSetSafetyCheck}, + {CANID::COMMON_SWITCH_CAN_BUS, &commonSwitchCANBus}, }; CANInterface::Config config = { diff --git a/apps/test-stress-can/include/CANConfigGimbal.h b/test-apps/test-stress-can/include/CANConfigGimbal.h similarity index 71% rename from apps/test-stress-can/include/CANConfigGimbal.h rename to test-apps/test-stress-can/include/CANConfigGimbal.h index 517381785..f7354642d 100644 --- a/apps/test-stress-can/include/CANConfigGimbal.h +++ b/test-apps/test-stress-can/include/CANConfigGimbal.h @@ -4,16 +4,10 @@ #include "CANMsg.h" #include "hw_bridge.h" -const HWBRIDGE::CANFILTER targetCANIDFilter = HWBRIDGE::CANFILTER::GIMBAL_RX_FILTER; -const HWBRIDGE::CANID targetReportDiagnosticsCANID = HWBRIDGE::CANID::GIMBAL_REPORT_DIAGNOSTICS; -const HWBRIDGE::CANSIGNAL targetReportNumStreamedSignal = HWBRIDGE::CANSIGNAL::GIMBAL_REPORT_NUM_STREAMED_MSGS_RECEIVED; -const HWBRIDGE::CANSIGNAL targetReportNumOneShotsSignal = HWBRIDGE::CANSIGNAL::GIMBAL_REPORT_NUM_ONE_SHOT_MSGS_RECEIVED; -const HWBRIDGE::CANID targetReportFaultsCANID = HWBRIDGE::CANID::GIMBAL_REPORT_FAULTS; -const HWBRIDGE::CANSIGNAL targetNumCANRXFaultsSignal = HWBRIDGE::CANSIGNAL::GIMBAL_NUM_CANRX_FAULTS; -const HWBRIDGE::CANSIGNAL targetNumCANTXFaultsSignal = HWBRIDGE::CANSIGNAL::GIMBAL_NUM_CANTX_FAULTS; - -static mbed_error_status_t oneShotHandler(void); -static mbed_error_status_t switchCANBus(void); +static void sendACK(HWBRIDGE::GIMBAL_ACK_VALUES ackValue); +static mbed_error_status_t gimbalSetControlMode(void); +static mbed_error_status_t gimbalSetJointPIDParams(void); +static mbed_error_status_t commonSwitchCANBus(void); namespace CANConfig { @@ -72,9 +66,9 @@ static CANMsgMap txMsgMap = { }; const static CANMsg::CANMsgHandlerMap rxOneShotMsgHandler = { - {CANID::GIMBAL_SET_CONTROL_MODE, &oneShotHandler}, - {CANID::GIMBAL_SET_JOINT_PID_PARAMS, &oneShotHandler}, - {CANID::COMMON_SWITCH_CAN_BUS, &switchCANBus}, + {CANID::GIMBAL_SET_CONTROL_MODE, &gimbalSetControlMode}, + {CANID::GIMBAL_SET_JOINT_PID_PARAMS, &gimbalSetJointPIDParams}, + {CANID::COMMON_SWITCH_CAN_BUS, &commonSwitchCANBus}, }; CANInterface::Config config = { diff --git a/apps/test-stress-can/include/CANConfigPDB.h b/test-apps/test-stress-can/include/CANConfigPDB.h similarity index 100% rename from apps/test-stress-can/include/CANConfigPDB.h rename to test-apps/test-stress-can/include/CANConfigPDB.h diff --git a/apps/test-stress-can/include/CANConfigScience.h b/test-apps/test-stress-can/include/CANConfigScience.h similarity index 76% rename from apps/test-stress-can/include/CANConfigScience.h rename to test-apps/test-stress-can/include/CANConfigScience.h index 1aa653bef..ae551c39c 100644 --- a/apps/test-stress-can/include/CANConfigScience.h +++ b/test-apps/test-stress-can/include/CANConfigScience.h @@ -4,18 +4,10 @@ #include "CANMsg.h" #include "hw_bridge.h" -const HWBRIDGE::CANFILTER targetCANIDFilter = HWBRIDGE::CANFILTER::SCIENCE_RX_FILTER; -const HWBRIDGE::CANID targetReportDiagnosticsCANID = HWBRIDGE::CANID::SCIENCE_REPORT_DIAGNOSTICS; -const HWBRIDGE::CANSIGNAL targetReportNumStreamedSignal = - HWBRIDGE::CANSIGNAL::SCIENCE_REPORT_NUM_STREAMED_MSGS_RECEIVED; -const HWBRIDGE::CANSIGNAL targetReportNumOneShotsSignal = - HWBRIDGE::CANSIGNAL::SCIENCE_REPORT_NUM_ONE_SHOT_MSGS_RECEIVED; -const HWBRIDGE::CANID targetReportFaultsCANID = HWBRIDGE::CANID::SCIENCE_REPORT_FAULTS; -const HWBRIDGE::CANSIGNAL targetNumCANRXFaultsSignal = HWBRIDGE::CANSIGNAL::SCIENCE_NUM_CANRX_FAULTS; -const HWBRIDGE::CANSIGNAL targetNumCANTXFaultsSignal = HWBRIDGE::CANSIGNAL::SCIENCE_NUM_CANTX_FAULTS; - -static mbed_error_status_t oneShotHandler(void); -static mbed_error_status_t switchCANBus(void); +static void sendACK(HWBRIDGE::SCIENCE_ACK_VALUES ackValue); +static mbed_error_status_t scienceSetControlMode(void); +static mbed_error_status_t scienceSetJointPIDParams(void); +static mbed_error_status_t commonSwitchCANBus(void); namespace CANConfig { @@ -86,9 +78,9 @@ static CANMsgMap txMsgMap = { }; const static CANMsg::CANMsgHandlerMap rxOneShotMsgHandler = { - {CANID::SCIENCE_SET_CONTROL_MODE, &oneShotHandler}, - {CANID::SCIENCE_SET_JOINT_PID_PARAMS, &oneShotHandler}, - {CANID::COMMON_SWITCH_CAN_BUS, &switchCANBus}, + {CANID::SCIENCE_SET_CONTROL_MODE, &scienceSetControlMode}, + {CANID::SCIENCE_SET_JOINT_PID_PARAMS, &scienceSetJointPIDParams}, + {CANID::COMMON_SWITCH_CAN_BUS, &commonSwitchCANBus}, }; CANInterface::Config config = { diff --git a/apps/test-stress-can/src/main.cpp b/test-apps/test-stress-can/src/main.cpp similarity index 100% rename from apps/test-stress-can/src/main.cpp rename to test-apps/test-stress-can/src/main.cpp diff --git a/uwrt-mars-rover-hw-bridge b/uwrt-mars-rover-hw-bridge index dafb4f6d8..66469ea05 160000 --- a/uwrt-mars-rover-hw-bridge +++ b/uwrt-mars-rover-hw-bridge @@ -1 +1 @@ -Subproject commit dafb4f6d820c917d699ab14002b66b6c454b4f16 +Subproject commit 66469ea0547cadbb04bcc4ea75543afc9bb4e952