Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FWT-11 #2 hallelujah effect sensor #1

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
942e48c
Updated to fix CMAKE errors
ol2764RIT Feb 20, 2024
fb49d10
pseudocode
ol2764RIT Feb 20, 2024
04a34dd
pseudocode pt 2
ol2764RIT Feb 20, 2024
c3ff6e3
pseudocode pt 3
ol2764RIT Feb 20, 2024
bac0b6f
some real code from pseudocode
ol2764RIT Feb 21, 2024
841ee33
added some redamentary logic for rotation
ol2764RIT Feb 21, 2024
5d8a8a7
some small logic for hallSensor
ol2764RIT Feb 24, 2024
408c2e4
setup main target
ol2764RIT Feb 24, 2024
ca7b885
updated for gpio pin
ol2764RIT Feb 24, 2024
cc0d489
fixed include for CMAKE
ol2764RIT Feb 27, 2024
260189e
refactoring code for rising edge handler
ol2764RIT Mar 5, 2024
6251827
reverterd
ol2764RIT Mar 8, 2024
7f53631
added fix for GPIO
ol2764RIT Mar 20, 2024
a9b3a00
added workaround for ms using halSysTick
ol2764RIT Mar 29, 2024
f5394e6
added workaround for ms using halSysTick
ol2764RIT Mar 29, 2024
378e774
fixed so that it boilds correctly
ol2764RIT Mar 29, 2024
39ba763
namespace bug wtih DEV
ol2764RIT Mar 29, 2024
f02f1e3
should fix it
ol2764RIT Mar 29, 2024
45ebc97
halo 3 elite approves
ol2764RIT Mar 29, 2024
f4b8adb
halo 3 elite approves pt 2
ol2764RIT Mar 29, 2024
e81b452
Applied Formatting Changes During GitHub Build
Mar 29, 2024
6b50ab6
added can support
ol2764RIT Apr 5, 2024
b47e189
added can fixes
ol2764RIT Apr 5, 2024
8e6ea5b
changed namespace
ol2764RIT Apr 5, 2024
0b88756
changed namespace
ol2764RIT Apr 5, 2024
fbaff6e
Merge pull request #2 from RIT-EVT/feature/ol2764RIT/WSSMain
ol2764RIT Apr 11, 2024
a273a75
Applied Formatting Changes During GitHub Build
Apr 11, 2024
7d57d39
sleep
ol2764RIT Apr 16, 2024
02ec177
Merge remote-tracking branch 'origin/feature/ol2764RIT/hallEffectSens…
ol2764RIT Apr 16, 2024
bd53c13
Sensor Driver Rework
mjmagee991 Apr 18, 2024
b3fdc6c
Applied Formatting Changes During GitHub Build
Apr 18, 2024
04e6e22
small fix to WSS to correct sensor not zeroing on stop.
mjh9585 Apr 19, 2024
b565fa0
cleaned up comments and did some requested code changes
chl1043 Sep 28, 2024
c804f9d
cleaned up comments and did some requested code changes
chl1043 Sep 28, 2024
ae98eff
Applied Formatting Changes During GitHub Build
Sep 30, 2024
b292c32
updated the main program descriptor comment
chl1043 Oct 1, 2024
6f93a65
added requested comments and made the test use one class instance to …
chl1043 Oct 1, 2024
1412c1b
fixed comments and implemented speed calculation and updated README
chl1043 Oct 5, 2024
a909677
added chip to readme and fixed variable comments
chl1043 Oct 7, 2024
ddeeba8
fixed the wheel speed algorithm
chl1043 Nov 15, 2024
d5f5f5f
updated comments and implemented multiple magnets per wheel option
chl1043 Nov 15, 2024
94bfb11
Formatting fixes
savillea1375 Nov 15, 2024
c2690c8
fixed the hallsensor test program
chl1043 Nov 16, 2024
2fc19fd
Merge remote-tracking branch 'origin/feature/ol2764RIT/hallEffectSens…
chl1043 Nov 16, 2024
df79aea
deleted the build folder and fixed formatting and comments
chl1043 Nov 16, 2024
65564b7
comment fixes and deleted logging raw recieved CAN data
chl1043 Nov 16, 2024
4426d99
Applied Formatting Changes During GitHub Build
Nov 16, 2024
9fd519e
cleaned up comments
chl1043 Nov 16, 2024
0321093
Merge remote-tracking branch 'origin/feature/ol2764RIT/hallEffectSens…
chl1043 Nov 16, 2024
4d9bf99
fixed comments and the magnet detection method and cleaned other thin…
chl1043 Nov 23, 2024
e778605
Applied Formatting Changes During GitHub Build
Nov 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -80,4 +80,4 @@ install_and_expose(${PROJECT_NAME})
###############################################################################
# Build Target Code
###############################################################################
add_subdirectory(targets)
add_subdirectory(targets)
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
83 changes: 7 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <URL>`
2) `git checkout -b feature/<github-username>/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*
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.
13 changes: 0 additions & 13 deletions include/BOARD_NAME.hpp

This file was deleted.

83 changes: 83 additions & 0 deletions include/WSS.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#ifndef WSS_HPP
#define WSS_HPP

#include <EVT/io/CANDevice.hpp>
#include <EVT/io/CANOpenMacros.hpp>
#include <EVT/io/SPI.hpp>
#include <co_core.h>
#include <dev/HallSensor.hpp>

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);
chl1043 marked this conversation as resolved.
Show resolved Hide resolved

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),
mjmagee991 marked this conversation as resolved.
Show resolved Hide resolved
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
59 changes: 59 additions & 0 deletions include/dev/HallSensor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef HALLSENSOR_HPP
#define HALLSENSOR_HPP

#include <EVT/io/GPIO.hpp>

namespace IO = EVT::core::IO;

namespace WSS::DEV {

/**
* This is the class for each individual front and back HallSensor
*/
class HallSensor {
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
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 */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be constant, speeding up, or slowing down

Suggested change
MAINTAIN, /** Wheel is spinning at a constant speed or speeding up */
MAINTAIN, /** Wheel is spinning */

};

/** Constructor (take a GPIO instance and the radius of the wheel) */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this comment and make it match our normal standard

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 */
ajs7422 marked this conversation as resolved.
Show resolved Hide resolved
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 */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your comments and variables, you should talk about the magnet being detected or not detected. If we get another hall effect sensor that's active high instead of low, we don't want to have to go through and update all the comments. The value of MAGNET_DETECTED_STATE should be the only way to know if the sensor is active high or low

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
47 changes: 0 additions & 47 deletions include/dev/LED.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion libs/EVT-core
Submodule EVT-core updated 239 files
3 changes: 0 additions & 3 deletions src/BOARD_NAME.cpp

This file was deleted.

40 changes: 40 additions & 0 deletions src/WSS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <EVT/utils/log.hpp>
#include <HALf3/stm32f3xx_hal.h>
#include <WSS.hpp>
#include <cstdlib>
#include <string>

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
Loading