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

This file was deleted.

38 changes: 38 additions & 0 deletions include/dev/hallSensor.hpp
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include <EVT/io/GPIO.hpp>
#include <EVT/DEV/RTCTimer.hpp>

namespace IO = EVT::core::IO;
namespace DEV = EVT::core::DEV;


namespace hallSensor {
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved

class HallSensor {

public:
enum WheelSpeedState {
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
STOPPED = 0, // First pulse or wheel is dead
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
MAINTAIN = 1, // 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 update(); // Update the wheel speed
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved

// Get the current speed of the wheel
uint32_t getSpeed(uint32_t timeDiff);


private:
IO::GPIO& gpio; // GPIO instance for the sensor
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
uint32_t wheelRadius; // Radius of the wheel
uint32_t prevTime; // Previous time for calculating delta time
uint32_t wheelSpeed; // Current speed of the wheel
WheelSpeedState state; // Current state of the wheel speed
bool isHigh; // If the sensor is currently high
};

} // namespace hallSensor
File renamed without changes.
33 changes: 0 additions & 33 deletions src/dev/LED.cpp

This file was deleted.

67 changes: 67 additions & 0 deletions src/dev/hallSensor.cpp
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "EVT/dev/RTC.hpp"
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
#include "EVT/manager.hpp"
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
#include <DEV/hallSensor.hpp>
#include <EVT/io/GPIO.hpp>

namespace IO = EVT::core::IO;
namespace DEV = EVT::core::DEV;

constexpr uint32_t THRESHOLD = 10; // Threshold for wheel speed
constexpr uint32_t THETA = 2; // Constant for wheel speed calculation
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved

namespace hallSensor {
DEV::RTC& clock = DEV::getRTC();
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved

HallSensor::HallSensor(IO::GPIO& gpio, uint32_t wheelRadius): gpio((IO::GPIO&) gpio), wheelRadius(wheelRadius) {
this->prevTime = 0;
this->wheelSpeed = 0;
this->state = WheelSpeedState::STOPPED;
this->isHigh = false;
}

uint32_t HallSensor::update(){
uint32_t timeDiff = 0;

switch (state) {
case WheelSpeedState::STOPPED:
if (isHigh) {
// should never get here
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
break;
}
else{
prevTime = clock.getTime();
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
isHigh = true;
state = WheelSpeedState::MAINTAIN;
}
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
case WheelSpeedState::MAINTAIN:
if (gpio.readPin() == EVT::core::IO::GPIO::State::HIGH) {
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
if(isHigh) {
break;
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
}
else{
timeDiff = clock.getTime() - prevTime;
uint32_t possibleSpeed = getSpeed(timeDiff);
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
if (possibleSpeed > THRESHOLD){
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
state = WheelSpeedState::STOPPED;
prevTime = 0;
wheelSpeed = 0;
isHigh = false;
}
else if (possibleSpeed < wheelSpeed){
wheelSpeed = possibleSpeed;
}
else{
//do nothing
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
return timeDiff;
}
}

uint32_t HallSensor::getSpeed(uint32_t timeDiff){
return (THETA * wheelRadius) / timeDiff;
}


} // namespace hallSensor
4 changes: 2 additions & 2 deletions targets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Add all targets
add_subdirectory(blinkUtil)
add_subdirectory(BIKE_NAME-BOARD_NAME)
add_subdirectory(REV3-WSS)
add_subdirectory(hallSensor)
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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})

File renamed without changes.
36 changes: 0 additions & 36 deletions targets/blinkUtil/main.cpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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)
Expand Down
35 changes: 35 additions & 0 deletions targets/hallSensor/main.cpp
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* This is a basic sample of using the UART module. The program provides a
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
* basic echo functionality where the uart will write back whatever the user
* enters.
*/

#include <EVT/io/UART.hpp>
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
#include <EVT/manager.hpp>
#include <EVT/io/pin.hpp>
#include <EVT/io/GPIO.hpp>
#include <DEV/hallSensor.hpp>

namespace IO = EVT::core::IO;

int main() {
// Initialize system
EVT::core::platform::init();

// Setup UART
IO::UART& uart = IO::getUART<IO::Pin::UART_TX, IO::Pin::UART_RX>(9600);

// Setup GPIO
IO::GPIO& gpio = IO::getGPIO<IO::Pin::GPIO_0, IO::Pin::GPIO_1>();

// Setup Hall Sensor
constexpr uint32_t WHEEL_RADIUS = 10;
hallSensor::HallSensor hallSensor(gpio, WHEEL_RADIUS);

// Main loop
while (1) {
uint32_t timeDiff = hallSensor.update();
uart.printf("Wheel speed: %d\n", hallSensor.getSpeed(timeDiff));
ol2764RIT marked this conversation as resolved.
Show resolved Hide resolved
uart.printf("Time Diff: %d\n", timeDiff);
}
}
Loading