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 32 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
13 changes: 0 additions & 13 deletions include/BOARD_NAME.hpp

This file was deleted.

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

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

#define NUM_HALLSENSORS 2
chl1043 marked this conversation as resolved.
Show resolved Hide resolved

using namespace EVT::core::IO;
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
chl1043 marked this conversation as resolved.
Show resolved Hide resolved

namespace WSS {

/**
* This is an example of a class for a board
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
*/
class WSS : public CANDevice {
public:
WSS(DEV::HallSensor& hallSensor1, DEV::HallSensor& hallSensor2);
chl1043 marked this conversation as resolved.
Show resolved Hide resolved

static constexpr uint16_t NODE_ID = 8;

/**
* Gets the object dictionary
*
* @return an object dictionary
*/
CO_OBJ_T* getObjectDictionary();
chl1043 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Updates the temperature values in an array and updates the error array from the TMU object.
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
*/
void process();

/**
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
* Get the device's node ID
*
* @return The node ID of the can device.
*/
uint8_t getNodeID() override;

/**
* Get the number of elements in the object dictionary.
*
* @return The number of elements in the object dictionary
*/
uint8_t getNumElements() override;

private:
DEV::HallSensor* hallSensors[NUM_HALLSENSORS]{};

uint32_t wheelSpeeds[NUM_HALLSENSORS] = {0, 0};
chl1043 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Object Dictionary Size
*/
static constexpr uint16_t OBJECT_DICTIONARY_SIZE = 24;

/**
* CAN Open object dictionary
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
*/
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, (uintptr_t) wheelSpeeds[0]),
DATA_LINK_21XX(0x00, 2, CO_TUNSIGNED16, (uintptr_t) wheelSpeeds[1]),

CO_OBJ_DICT_ENDMARK,
};
};

}// namespace WSS
37 changes: 37 additions & 0 deletions include/dev/HallSensor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once
chl1043 marked this conversation as resolved.
Show resolved Hide resolved

#include <EVT/io/GPIO.hpp>

namespace IO = EVT::core::IO;

namespace WSS::DEV {

class HallSensor {
chl1043 marked this conversation as resolved.
Show resolved Hide resolved

public:
enum WheelSpeedState {
STOP = 0, // First pulse or wheel is dead
INITIALIZING = 1,// Setting speed based on first reading
MAINTAIN = 2, // Wheel is spinning at a constant speed or speeding up
mjh9585 marked this conversation as resolved.
Show resolved Hide resolved
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
};

// Constructor (take a GPIO instance and the radius of the wheel)
ajs7422 marked this conversation as resolved.
Show resolved Hide resolved
HallSensor(IO::GPIO& gpio, uint32_t wheelRadius);

void update();// Update the wheel speed
ajs7422 marked this conversation as resolved.
Show resolved Hide resolved

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

private:
IO::GPIO& gpio; // GPIO instance for the sensor
chl1043 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 lastInterval;// Last fully measured interval
WheelSpeedState state;// Current state of the wheel
bool magnetInLastRead;// Flag to check if the sensor is high

IO::GPIO::State MAGNET_DETECTED_STATE = IO::GPIO::State::LOW;
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
};

}// namespace WSS::DEV
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.

29 changes: 29 additions & 0 deletions src/WSS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <WSS.hpp>

namespace WSS {

WSS::WSS(DEV::HallSensor& hallSensor1, DEV::HallSensor& hallSensor2) {
this->hallSensors[0] = &hallSensor1;
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
this->hallSensors[1] = &hallSensor2;
}

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();
}
}

uint8_t WSS::getNodeID() {
return NODE_ID;
}

uint8_t WSS::getNumElements() {
return OBJECT_DICTIONARY_SIZE;
}

}// namespace WSS
93 changes: 93 additions & 0 deletions src/dev/HallSensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include <EVT/io/GPIO.hpp>
#include <HALf3/stm32f3xx_hal.h>
#include <dev/HallSensor.hpp>

namespace IO = EVT::core::IO;

// TODO Tune these values
constexpr uint32_t THRESHOLD = 10000;// Threshold for wheel speed
constexpr uint32_t THETA = 2; // Constant for wheel speed calculation

namespace WSS::DEV {

HallSensor::HallSensor(IO::GPIO& gpio, uint32_t wheelRadius) : gpio((IO::GPIO&) gpio), wheelRadius(wheelRadius) {
this->prevTime = 0;
this->lastInterval = 0;
this->state = WheelSpeedState::STOP;
this->magnetInLastRead = false;
}

void HallSensor::update() {
uint32_t now = HAL_GetTick();

switch (state) {
case WheelSpeedState::STOP:
if (gpio.readPin() == MAGNET_DETECTED_STATE) {
// If the magnet is detected for the first time, record the time and start initializing
if (!magnetInLastRead) {
prevTime = now;
magnetInLastRead = true;
state = WheelSpeedState::INITIALIZING;
}
} else {
magnetInLastRead = false;
}
break;

case WheelSpeedState::INITIALIZING:
if (gpio.readPin() == MAGNET_DETECTED_STATE) {
if (!magnetInLastRead) {
// If the magnet is detected for the second time, record the time and the first
// interval and start maintaining
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
lastInterval = now - prevTime;
prevTime = now;
magnetInLastRead = true;
state = WheelSpeedState::MAINTAIN;
}
} else {
magnetInLastRead = false;
}

// If the magnet hasn't been detected for a significant amount of time, go back to the stop
// state
if (now - prevTime > THRESHOLD) {
state = WheelSpeedState::STOP;
prevTime = 0;
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
}
break;

case WheelSpeedState::MAINTAIN:
if (gpio.readPin() == MAGNET_DETECTED_STATE) {
if (!magnetInLastRead) {
// If the magnet is newly detected, record the time and interval
lastInterval = now - prevTime;
prevTime = now;
magnetInLastRead = true;
}
} else {
magnetInLastRead = false;
}

uint32_t elapsedTime = now - prevTime;
// If the magnet hasn't been detected for a significant amount of time, go back to the stop
// state
if (elapsedTime > THRESHOLD) {
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
state = WheelSpeedState::STOP;
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
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::getSpeed() {
// TODO Calculate speed
chl1043 marked this conversation as resolved.
Show resolved Hide resolved
return lastInterval;
}

}// namespace WSS::DEV
Loading
Loading