diff --git a/CMakeLists.txt b/CMakeLists.txt index b3ef056..b859c85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ ############################################################################### -# Top level CMakeList for building the *EVT_BOARD_NAME* source code +# Top level CMakeList for building the WSS source code ############################################################################### cmake_minimum_required(VERSION 3.15) @@ -44,7 +44,7 @@ include(${EVT_CORE_DIR}/cmake/evt-core_install.cmake) ############################################################################### # Project Setup ############################################################################### -set(BOARD_LIB_NAME BOARD_NAME) +set(BOARD_LIB_NAME WSS) if("${BOARD_LIB_NAME}" STREQUAL BOARD_NAME) message(FATAL_ERROR "You must set the template project name in the top-level CMakeLists.txt") @@ -55,22 +55,22 @@ file(STRINGS version.txt BOARD_VERSION) project(${BOARD_LIB_NAME} VERSION ${BOARD_VERSION} LANGUAGES CXX C - ) +) add_library(${PROJECT_NAME} STATIC) # Add sources target_sources(${PROJECT_NAME} PRIVATE - src/dev/LED.cpp - src/BOARD_NAME.cpp - ) + src/WSS.cpp + src/dev/HallSensor.cpp +) ############################################################################### # Handle dependencies ############################################################################### target_link_libraries(${PROJECT_NAME} PUBLIC EVT - ) +) ############################################################################### # Install and expose library @@ -80,4 +80,4 @@ install_and_expose(${PROJECT_NAME}) ############################################################################### # Build Target Code ############################################################################### -add_subdirectory(targets) +add_subdirectory(targets) \ No newline at end of file diff --git a/README.md b/README.md index b353454..64d05f8 100644 --- a/README.md +++ b/README.md @@ -1,78 +1,9 @@ -# Project Template - -## Overview - -### EVT-core -For an overview of EVT please see the following links: - -[EVT-core Documentation](https://evt-core.readthedocs.io/) - -[EVT-core GitHub](https://github.com/RIT-EVT/EVT-core/) - -### Template Project - -This project-template serves as the skeleton template that is used for -all EVT board repositories. It contains the following capabilities: - -- Includes EVT-core as a submodule and compiled as a library for the board -- Set up to contain code pertinent to the board to be built -- Supports an arbitrary number of executable targets to be built and deployed onto a microcontroller - - These contain targets to be run on a specific EVT custom PCB - - Also contain utilities for validation and debugging -- Provides a framework for auto-generated and built documentation using Sphinx and hosted on -`readthedocs.io` - -## Steps to Set Up a New Project - -1) Create a new repo based on the project-template - 1) From [project-template](https://github.com/RIT-EVT/project-template) click `Use this template` - 2) Set the owner of the repository to RIT-EVT - 3) Name the repo with the new board's acronym - 4) Set the privacy to Public - 5) Don't include all branches -2) Clone the new repo and create a setup branch - 1) `git clone ` - 2) `git checkout -b feature//inital-setup` -3) Set the project template up as an upstream repository - 1) `git remote add upstream https://github.com/RIT-EVT/project-template` - 2) `git remote set-url --push upstream no-push` - 1) Confirm that this worked by running `git remote -v` - 2) This should produce output similar to this: - ``` - origin https://github.com/RIT-EVT/ABC.git (fetch) - origin https://github.com/RIT-EVT/ABC.git (push) - upstream https://github.com/RIT-EVT/project-template (fetch) - upstream no-push (push) - ``` - 3) `git fetch upstream` - 4) `git merge upstream/main --allow-unrelated-histories` - -4) Update the EVT submodule - 1) `git submodule update --init --recursive && git pull` - 2) `cd ./libs/EVT-core` - 3) `git merge origin/main` - 4) `cd ../..` -5) Import the project into Read the Docs, following the steps on -[the wiki](https://wiki.rit.edu/display/EVT/Documentation+and+Organization+Standards) -6) Update all instances of BOARD_NAME to match your project name - 1) `CMakeLists.txt:28` - 2) Directory `./targets/BIKE_NAME-BOARD_NAME` - 3) `targets/BIKE_NAME-BOARD_NAME/CMakeLists.txt:3` - 4) `src/BOARD_NAME.cpp` - 5) `include/BOARD_NAME.hpp` - 6) `docs/Doxyfile:35` - 7) `docs/source/index.rst:6` - 8) `docs/source/api/index.rst:4,12,15` - 9) `README.md:56` -7) Sample files are included in `./src` and `./include`. Once proper functionality has been -confirmed, these files should be deleted. There are placeholders to demonstrate the board library -building functionality. -8) Everything in this README from this final step up should be deleted, leaving only the content -below. When finished, all the changes should be committed and pushed to the setup branch, and a PR -should be created to merge into main. - -# BIKE_NAME-BOARD_NAME +# REV3-WSS ## Introduction - -*One-paragraph summary of the board and its purpose on the bike* \ No newline at end of file +The Wheel Speed Sensor (WSS) is a PCB that senses the RPM of wheels on the bike and calculates the speed of +the bike. It uses sensors in both the front and back wheels. It calculates the RPM of each wheel by using +a hall effect sensor and a magnet in each wheel to get a time interval of how long it takes for a wheel to +make a full rotation. This is then used to calculate RPM, and then RPM is used with the radius of the wheel +to calculate the speed of the bike in miles per hour. The WSS then broadcasts the data on the CAN network. +This is on chip STM32F334. \ No newline at end of file diff --git a/include/BOARD_NAME.hpp b/include/BOARD_NAME.hpp deleted file mode 100644 index 83b794b..0000000 --- a/include/BOARD_NAME.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -namespace BOARD_NAME { - -/** - * This is an example of a class for a board - */ -class BOARD_NAME { -public: -private: -}; - -} diff --git a/include/WSS.hpp b/include/WSS.hpp new file mode 100644 index 0000000..3b434ea --- /dev/null +++ b/include/WSS.hpp @@ -0,0 +1,83 @@ +#ifndef WSS_HPP +#define WSS_HPP + +#include +#include +#include +#include +#include + +constexpr uint8_t NUM_HALLSENSORS = 2; + +namespace IO = EVT::core::IO; + +namespace WSS { + +/** + * This is the main class for the Wheel Speed Sensor + */ +class WSS : public CANDevice { +public: + /** + * Initialize WSS driver + * + * @param[in] hallSensor1 Front Hall sensor + * @param[in] hallSensor2 Back Hall sensor + */ + WSS(DEV::HallSensor& hallSensor1, DEV::HallSensor& hallSensor2); + + static constexpr uint16_t NODE_ID = 8; + + /** Updates the wheel speed values for all hallsensors in an array */ + void process(); + + CO_OBJ_T* getObjectDictionary() override; + + uint8_t getNodeID() override; + + uint8_t getNumElements() override; + +private: + /** This is an array of the hall sensors for the front and back sensor */ + DEV::HallSensor* hallSensors[NUM_HALLSENSORS]{}; + + /** This is an array of wheel speeds for the front and back wheel in miles per hour */ + uint16_t wheelSpeeds[NUM_HALLSENSORS] = {0, 0}; + + /** Time in tick value that is used to print out wheel speeds five times a second */ + uint32_t debugPrintTime; + + /** + * Object Dictionary Size + */ + static constexpr uint16_t OBJECT_DICTIONARY_SIZE = 24; + + /** + * CANopen object dictionary + */ + CO_OBJ_T objectDictionary[OBJECT_DICTIONARY_SIZE + 1] = { + MANDATORY_IDENTIFICATION_ENTRIES_1000_1014, + HEARTBEAT_PRODUCER_1017(2000), + IDENTITY_OBJECT_1018, + SDO_CONFIGURATION_1200, + + // TPDO 0 CONFIGURATION + TRANSMIT_PDO_SETTINGS_OBJECT_18XX(0x00, TRANSMIT_PDO_TRIGGER_TIMER, TRANSMIT_PDO_INHIBIT_TIME_DISABLE, 2000), + + // TPDO 0 MAPPING + TRANSMIT_PDO_MAPPING_START_KEY_1AXX(0, 2), + TRANSMIT_PDO_MAPPING_ENTRY_1AXX(0x00, 1, PDO_MAPPING_UNSIGNED16), + TRANSMIT_PDO_MAPPING_ENTRY_1AXX(0x00, 2, PDO_MAPPING_UNSIGNED16), + + // TPDO 0 DATA LINKS + DATA_LINK_START_KEY_21XX(0, 2), + DATA_LINK_21XX(0x00, 1, CO_TUNSIGNED16, &wheelSpeeds[0]), + DATA_LINK_21XX(0x00, 2, CO_TUNSIGNED16, &wheelSpeeds[1]), + + CO_OBJ_DICT_ENDMARK, + }; +}; + +}// namespace WSS + +#endif \ No newline at end of file diff --git a/include/dev/HallSensor.hpp b/include/dev/HallSensor.hpp new file mode 100644 index 0000000..befff2f --- /dev/null +++ b/include/dev/HallSensor.hpp @@ -0,0 +1,59 @@ +#ifndef HALLSENSOR_HPP +#define HALLSENSOR_HPP + +#include + +namespace IO = EVT::core::IO; + +namespace WSS::DEV { + +/** + * This is the class for each individual front and back HallSensor + */ +class HallSensor { +public: + /** The state of the wheel whether it is stopped, starting to spin, or spinning */ + enum class WheelSpeedState { + STOP, /** Wheel is not moving */ + INITIALIZING, /** Setting speed based on first reading */ + MAINTAIN, /** Wheel is spinning at a constant speed or speeding up */ + }; + + /** Constructor (take a GPIO instance and the radius of the wheel) */ + HallSensor(IO::GPIO& gpio, uint32_t wheelRadius, uint32_t numberOfMagnets); + + void update();// Update the sensor interval + + /** Get the current speed of the wheel */ + uint32_t getSpeed(); + + /** Get the last interval of one full rotation of the wheel */ + uint32_t getRawInterval(); + +private: + /** GPIO instance for the sensor */ + IO::GPIO& gpio; + /** Radius of the wheel */ + uint32_t wheelRadius; + /** Number of magnets in a wheel */ + uint32_t numberOfMagnets; + /** Previous time for calculating delta time */ + uint32_t prevTime; + /** Last fully measured interval */ + uint32_t lastInterval; + /** Current state of the wheel */ + WheelSpeedState state; + /** Flag to check if the sensor is high */ + bool magnetInLastRead; + /** The magnet is detected if the pin is low */ + static constexpr IO::GPIO::State MAGNET_DETECTED_STATE = IO::GPIO::State::LOW; + /** + * The threshold in milliseconds for how long a magnet has not been detected before + * setting the WheelSpeedState to STOP + */ + static constexpr uint32_t THRESHOLD = 5000; +}; + +}// namespace WSS::DEV + +#endif diff --git a/include/dev/LED.hpp b/include/dev/LED.hpp deleted file mode 100644 index 78f7579..0000000 --- a/include/dev/LED.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef _BOARD_NAME_LED_ -#define _BOARD_NAME_LED_ - -#include - -namespace BOARD_NAME::DEV { - -class LED { -public: - /** - * Represents if the LED is active high or active low. - */ - enum class ActiveState { - HIGH = 0u, - LOW = 1u - }; - - /** - * Create an instance of the LED based on the given GPIO pin. - * - * @param gpio GPIO pin - * @param activeState Represents if the LED is active high or active low - */ - LED(EVT::core::IO::GPIO& gpio, ActiveState activeState); - - /** - * Toggle the current state of the LED - */ - void toggle(); - - /** - * Set the current state of the LED. - * - * @param state The state to set the LED to. - */ - void setState(EVT::core::IO::GPIO::State state); - -private: - /// The gpio pin used by the LED - EVT::core::IO::GPIO& gpio; - /// If the LED is active high or active low - ActiveState activeState; -}; - -}//namespace BOARD_NAME::DEV - -#endif diff --git a/libs/EVT-core b/libs/EVT-core index dc48bf7..b3321e9 160000 --- a/libs/EVT-core +++ b/libs/EVT-core @@ -1 +1 @@ -Subproject commit dc48bf74ce1e30feea1d972075fd4a5ff7017dee +Subproject commit b3321e978e7a7dd057f932aa252653b7002bcb7a diff --git a/src/BOARD_NAME.cpp b/src/BOARD_NAME.cpp deleted file mode 100644 index 5e5fced..0000000 --- a/src/BOARD_NAME.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -namespace BOARD_NAME {} diff --git a/src/WSS.cpp b/src/WSS.cpp new file mode 100644 index 0000000..54d6157 --- /dev/null +++ b/src/WSS.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include + +namespace log = EVT::core::log; + +namespace WSS { + +WSS::WSS(DEV::HallSensor& hallSensor1, DEV::HallSensor& hallSensor2) + : hallSensors{&hallSensor1, &hallSensor2}, debugPrintTime(HAL_GetTick()) {} + +CO_OBJ_T* WSS::getObjectDictionary() { + return objectDictionary; +} + +void WSS::process() { + for (uint8_t i = 0; i < NUM_HALLSENSORS; i++) { + hallSensors[i]->update(); + wheelSpeeds[i] = hallSensors[i]->getSpeed(); + } + + // Prints out the wheel speed in miles per hour every 5 times a second + if (HAL_GetTick() - debugPrintTime > 1000) { + debugPrintTime = HAL_GetTick(); + log::LOGGER.log(log::Logger::LogLevel::DEBUG, "Wheelspeed[0]:%d", wheelSpeeds[0]); + log::LOGGER.log(log::Logger::LogLevel::DEBUG, "Wheelspeed[1]:%d", wheelSpeeds[1]); + } +} + +uint8_t WSS::getNodeID() { + return NODE_ID; +} + +uint8_t WSS::getNumElements() { + return OBJECT_DICTIONARY_SIZE; +} + +}// namespace WSS diff --git a/src/dev/HallSensor.cpp b/src/dev/HallSensor.cpp new file mode 100644 index 0000000..f3128bb --- /dev/null +++ b/src/dev/HallSensor.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include + +namespace IO = EVT::core::IO; + +namespace WSS::DEV { + +HallSensor::HallSensor(IO::GPIO& gpio, uint32_t wheelRadius, uint32_t numberOfMagnets) : gpio((IO::GPIO&) gpio), wheelRadius(wheelRadius), numberOfMagnets(numberOfMagnets) { + this->prevTime = 0; + this->lastInterval = 0; + this->state = WheelSpeedState::STOP; + this->magnetInLastRead = false; +} + +void HallSensor::update() { + uint32_t now = HAL_GetTick(); + uint32_t elapsedTime = now - prevTime; + + // The magnet is detected if the previous gpio pin reading is the same as the current gpio + // pin reading, and if the pin is LOW + const bool magnetReadLow = gpio.readPin() == MAGNET_DETECTED_STATE; + bool magnetDetected = false; + if (magnetReadLow && magnetInLastRead != magnetReadLow) { + magnetDetected = true; + } + magnetInLastRead = magnetReadLow; + + switch (state) { + case WheelSpeedState::STOP: + if (magnetDetected) { + prevTime = now; + state = WheelSpeedState::INITIALIZING; + } + break; + + case WheelSpeedState::INITIALIZING: + if (magnetDetected) { + // If the magnet is detected for the second time, record the time and the first + // interval and enter the maintain state + lastInterval = elapsedTime; + prevTime = now; + state = WheelSpeedState::MAINTAIN; + } + + // If the magnet hasn't been detected for a significant amount of time, go back to the stop + // state + if (elapsedTime > THRESHOLD) { + state = WheelSpeedState::STOP; + prevTime = 0; + lastInterval = 0; + } + break; + + case WheelSpeedState::MAINTAIN: + if (magnetDetected) { + // If the magnet is newly detected, record the time and interval + lastInterval = elapsedTime; + prevTime = now; + + // If the magnet hasn't been detected for a significant amount of time, go back to the stop + // state + } else if (elapsedTime > THRESHOLD) { + state = WheelSpeedState::STOP; + prevTime = 0; + lastInterval = 0; + + // If the elapsed time since the magnet was last detected exceeds the last interval, record + // the last interval as if the magnet was just detected because the bike is slowing + // down, but the exact speed can't be calculated + } else if (elapsedTime > lastInterval) { + lastInterval = elapsedTime; + } + break; + } +} + +uint32_t HallSensor::getRawInterval() { + return lastInterval; +} + +uint32_t HallSensor::getSpeed() { + if (state != WheelSpeedState::MAINTAIN) { + // The wheel isn't moving, so its speed is zero. + return 0; + } + + /* + * The speed of the wheel in revolutions per minute. + * lastInterval is the time that it takes for one full revolution of the wheel + * in milliseconds, so converting that to RPM is just dividing 60000 by lastInterval. + */ + const uint32_t rpm = 60000 / lastInterval / numberOfMagnets; + /* + * The speed of the bike in miles per hour. + * RPM * (circumference in inches (2 * pi * wheelRadius) / 1 rotation) * (1 mile / 63360 inches) * (60 minutes / hour) + * is what calculates the speed in mph. + */ + const uint32_t speed = rpm * wheelRadius * 2 * 3142 * 60 / 63360000; + + return speed; +} + +}// namespace WSS::DEV \ No newline at end of file diff --git a/src/dev/LED.cpp b/src/dev/LED.cpp deleted file mode 100644 index fe0567e..0000000 --- a/src/dev/LED.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include - -namespace BOARD_NAME::DEV { - -LED::LED(EVT::core::IO::GPIO& gpio, LED::ActiveState activeState) - : gpio(gpio) { - this->setState(EVT::core::IO::GPIO::State::LOW); -} - -void LED::toggle() { - EVT::core::IO::GPIO::State currentState = this->gpio.readPin(); - - if (EVT::core::IO::GPIO::State::LOW == currentState) { - this->gpio.writePin(EVT::core::IO::GPIO::State::HIGH); - } else { - this->gpio.writePin(EVT::core::IO::GPIO::State::LOW); - } -} - -void LED::setState(EVT::core::IO::GPIO::State state) { - // if the LED is active high, it's state follows from pin setting - if (this->activeState == ActiveState::HIGH) { - this->gpio.writePin(state); - } else { - if (state == EVT::core::IO::GPIO::State::HIGH) { - this->gpio.writePin(EVT::core::IO::GPIO::State::LOW); - } else { - this->gpio.writePin(EVT::core::IO::GPIO::State::HIGH); - } - } -} - -}// namespace BOARD_NAME::DEV diff --git a/targets/BIKE_NAME-BOARD_NAME/main.cpp b/targets/BIKE_NAME-BOARD_NAME/main.cpp deleted file mode 100644 index 4583803..0000000 --- a/targets/BIKE_NAME-BOARD_NAME/main.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/** - * This is a basic sample of using the UART module. The program provides a - * basic echo functionality where the uart will write back whatever the user - * enters. - */ - -#include -#include -#include - -namespace IO = EVT::core::IO; - -int main() { - // Initialize system - EVT::core::platform::init(); - - // Setup UART - IO::UART& uart = IO::getUART(9600); - - // String to store user input - char buf[100]; - - while (1) { - // Read user input - uart.printf("Enter message: "); - uart.gets(buf, 100); - uart.printf("\n\recho: %s\n\r", buf); - } -} diff --git a/targets/CMakeLists.txt b/targets/CMakeLists.txt index 8e824bd..86264b4 100644 --- a/targets/CMakeLists.txt +++ b/targets/CMakeLists.txt @@ -1,3 +1,3 @@ # Add all targets -add_subdirectory(blinkUtil) -add_subdirectory(BIKE_NAME-BOARD_NAME) +add_subdirectory(REV3-WSS) +add_subdirectory(hall_sensor) diff --git a/targets/blinkUtil/CMakeLists.txt b/targets/REV3-WSS/CMakeLists.txt similarity index 90% rename from targets/blinkUtil/CMakeLists.txt rename to targets/REV3-WSS/CMakeLists.txt index 4f19f29..472eb17 100644 --- a/targets/blinkUtil/CMakeLists.txt +++ b/targets/REV3-WSS/CMakeLists.txt @@ -1,8 +1,7 @@ include(${EVT_CORE_DIR}/cmake/evt-core_build.cmake) -project(blinkUtil) +project(REV3-WSS) cmake_minimum_required(VERSION 3.15) make_exe(${PROJECT_NAME} main.cpp) target_link_libraries(${PROJECT_NAME} PUBLIC ${BOARD_LIB_NAME}) - diff --git a/targets/REV3-WSS/main.cpp b/targets/REV3-WSS/main.cpp new file mode 100644 index 0000000..e8abd73 --- /dev/null +++ b/targets/REV3-WSS/main.cpp @@ -0,0 +1,114 @@ +/** + * This is a program that senses the speed of both wheels on the bike. + * This is the main target for the board. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace IO = EVT::core::IO; +namespace log = EVT::core::log; +namespace time = EVT::core::time; +namespace DEV = EVT::core::DEV; + +// Create a can interrupt handler +void canInterrupt(IO::CANMessage& message, void* priv) { + EVT::core::types::FixedQueue* queue = + (EVT::core::types::FixedQueue*) priv; + + if (queue != nullptr) { + queue->append(message); + } +} + +int main() { + // Initialize system + EVT::core::platform::init(); + + // Setup UART + IO::UART& uart = IO::getUART(9600); + + // Setup GPIO + IO::GPIO& frontInterruptGPIO = IO::getGPIO( + IO::GPIO::Direction::INPUT); + IO::GPIO& backInterruptGPIO = IO::getGPIO( + IO::GPIO::Direction::INPUT); + + uart.printf("GPIO Initialized\r\n"); + + // Initialize logger + log::LOGGER.setUART(&uart); + + // Setup Hall Sensor + // Wheel radius in inches + constexpr uint32_t FRONT_WHEEL_RADIUS = 15; + constexpr uint32_t BACK_WHEEL_RADIUS = 15; + constexpr uint32_t FRONT_WHEEL_NUM_OF_MAGNETS = 1; + constexpr uint32_t BACK_WHEEL_NUM_OF_MAGNETS = 1; + + WSS::DEV::HallSensor hallSensor1(frontInterruptGPIO, FRONT_WHEEL_RADIUS, FRONT_WHEEL_NUM_OF_MAGNETS); + WSS::DEV::HallSensor hallSensor2(backInterruptGPIO, BACK_WHEEL_RADIUS, BACK_WHEEL_NUM_OF_MAGNETS); + + // Setup WSS + WSS::WSS wss(hallSensor1, hallSensor2); + + DEV::Timer& timer = DEV::getTimer(100); + + /////////////////////////////////////////////////////////////////////////// + // Setup CAN configuration, this handles making drivers, applying settings. + // And generally creating the CANopen stack node which is the interface + // between the application (the code we write) and the physical CAN network + /////////////////////////////////////////////////////////////////////////// + /// + // Will store CANopen messages that will be populated by the EVT-core CAN + // interrupt + EVT::core::types::FixedQueue canOpenQueue; + + // Initialize CAN, add an IRQ which will add messages to the queue above + IO::CAN& can = IO::getCAN(); + can.addIRQHandler(canInterrupt, reinterpret_cast(&canOpenQueue)); + + // Attempt to join the CAN network + IO::CAN::CANStatus result = can.connect(); + + // Check to see if the device is connected to the CAN network + if (result != IO::CAN::CANStatus::OK) { + log::LOGGER.log(log::Logger::LogLevel::ERROR, "Failed to connect to CAN network\r\n"); + return 1; + } else { + log::LOGGER.log(log::Logger::LogLevel::INFO, "Connected to CAN network\r\n"); + } + + // Reserved memory for CANopen stack usage + uint8_t sdoBuffer[CO_SSDO_N * CO_SDO_BUF_BYTE]; + CO_TMR_MEM appTmrMem[16]; + + // Reserve driver variables + CO_IF_DRV canStackDriver; + + CO_IF_CAN_DRV canDriver; + CO_IF_TIMER_DRV timerDriver; + CO_IF_NVM_DRV nvmDriver; + + CO_NODE canNode; + + // Initialize all the CANOpen drivers. + IO::initializeCANopenDriver(&canOpenQueue, &can, &timer, &canStackDriver, &nvmDriver, &timerDriver, &canDriver); + + // Initialize the CANOpen node we are using. + IO::initializeCANopenNode(&canNode, &wss, &canStackDriver, sdoBuffer, appTmrMem); + + // Set the node to operational mode + CONmtSetMode(&canNode.Nmt, CO_OPERATIONAL); + + while (1) { + wss.process(); + IO::processCANopenNode(&canNode); + } +} diff --git a/targets/blinkUtil/main.cpp b/targets/blinkUtil/main.cpp deleted file mode 100644 index f37d45e..0000000 --- a/targets/blinkUtil/main.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * This example is the basic LED blink sample. This samples shows how the - * device level drivers (the LED in this case) can be established by providing - * the driver with the corresponding IO level driver (GPIO in this case). - * - * The code will setup a GPIO pin as an output then setup an LED using that - * GPIO. - */ - -#include -#include -#include - -namespace IO = EVT::core::IO; -namespace DEV = BOARD_NAME::DEV; -namespace time = EVT::core::time; - -int main() { - // Initialize system - EVT::core::platform::init(); - - // Setup the GPIO pin. - // Notice that the pin used is called "LED". Each platform has a dedicated - // LED pin, for the f3xx that is PB_13. - IO::GPIO& ledGPIO = IO::getGPIO(); - DEV::LED led(ledGPIO, DEV::LED::ActiveState::HIGH); - - while (1) { - led.toggle(); - - // Wait half a second - time::wait(500); - } - - return 0; -} diff --git a/targets/BIKE_NAME-BOARD_NAME/CMakeLists.txt b/targets/hall_sensor/CMakeLists.txt similarity index 86% rename from targets/BIKE_NAME-BOARD_NAME/CMakeLists.txt rename to targets/hall_sensor/CMakeLists.txt index 9a133e2..2113c00 100644 --- a/targets/BIKE_NAME-BOARD_NAME/CMakeLists.txt +++ b/targets/hall_sensor/CMakeLists.txt @@ -1,6 +1,6 @@ include(${EVT_CORE_DIR}/cmake/evt-core_build.cmake) -project(BIKE_NAME-BOARD_NAME) +project(hallSensor) cmake_minimum_required(VERSION 3.15) make_exe(${PROJECT_NAME} main.cpp) diff --git a/targets/hall_sensor/main.cpp b/targets/hall_sensor/main.cpp new file mode 100644 index 0000000..a0a326b --- /dev/null +++ b/targets/hall_sensor/main.cpp @@ -0,0 +1,50 @@ +/** + * This is a test program for the Hall Effect sensor. + */ + +#include +#include +#include +#include +#include + +namespace IO = EVT::core::IO; + +constexpr IO::Pin INTERRUPT_PIN = IO::Pin::PA_1; + +int main() { + // Initialize system + EVT::core::platform::init(); + + // Setup UART + IO::UART& uart = IO::getUART(9600); + uart.printf("UART Initialized\r\n"); + + // Setup GPIO + IO::GPIO& interruptGPIO = IO::getGPIO( + IO::GPIO::Direction::INPUT); + IO::GPIO& interruptGPIO2 = IO::getGPIO( + IO::GPIO::Direction::INPUT); + + uart.printf("GPIO Initialized\r\n"); + + // Setup Hall Sensor + // Wheel radius in inches + constexpr uint32_t WHEEL_RADIUS = 15; + constexpr uint32_t NUM_OF_MAGNETS = 1; + + WSS::DEV::HallSensor hallSensor(interruptGPIO, WHEEL_RADIUS, NUM_OF_MAGNETS); + + uint32_t debugPrintTime = HAL_GetTick(); + + // Main loop + while (1) { + hallSensor.update(); + + // Prints out the wheel speed in miles per hour every 5 times a second + if (HAL_GetTick() - debugPrintTime > 200) { + debugPrintTime = HAL_GetTick(); + uart.printf("Wheel speed (miles/hour): %d\r\n", hallSensor.getSpeed()); + } + } +}