From d22fc8e244290b0141a7afe59204e631814ab4d6 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 29 Jan 2024 10:46:36 +0100 Subject: [PATCH] Improved encoder support --- AbsoluteEncoder.cpp | 2 ++ FeedbackServo.h => AbsoluteEncoder.h | 5 +++-- Encoder.cpp | 19 +++++++++++-------- Encoder.h | 20 +++++++++++++------- FeedbackServo.cpp | 3 --- IncrementalEncoder.cpp | 19 +++++++++++++++++++ 6 files changed, 48 insertions(+), 20 deletions(-) create mode 100644 AbsoluteEncoder.cpp rename FeedbackServo.h => AbsoluteEncoder.h (67%) delete mode 100644 FeedbackServo.cpp create mode 100644 IncrementalEncoder.cpp diff --git a/AbsoluteEncoder.cpp b/AbsoluteEncoder.cpp new file mode 100644 index 0000000..6606485 --- /dev/null +++ b/AbsoluteEncoder.cpp @@ -0,0 +1,2 @@ +#include "AbsoluteEncoder.h" + diff --git a/FeedbackServo.h b/AbsoluteEncoder.h similarity index 67% rename from FeedbackServo.h rename to AbsoluteEncoder.h index 5201b9d..bcc643e 100644 --- a/FeedbackServo.h +++ b/AbsoluteEncoder.h @@ -5,11 +5,12 @@ namespace Passer { namespace RoboidContol { -class FeedbackServo : public ServoMotor { +class AbsoluteEncoder { public: - FeedbackServo(); + AbsoluteEncoder() {} virtual float GetActualAngle() = 0; + virtual float GetActualVelocity() = 0; }; } // namespace RoboidContol diff --git a/Encoder.cpp b/Encoder.cpp index 07e2558..f9a472b 100644 --- a/Encoder.cpp +++ b/Encoder.cpp @@ -1,18 +1,21 @@ +/* #include "Encoder.h" -Encoder::Encoder(unsigned char pulsesPerRevolution, - unsigned char distancePerRotation) { - //: Encoder::Encoder() { +IncrementalEncoder::IncrementalEncoder(unsigned char pulsesPerRevolution, + unsigned char distancePerRotation) { this->pulsesPerRevolution = pulsesPerRevolution; this->distancePerRevolution = distancePerRotation; } -int Encoder::GetPulseCount() { return 0; } +int IncrementalEncoder::GetPulseCount() { return 0; } -float Encoder::GetDistance() { return 0; } +float IncrementalEncoder::GetDistance() { return 0; } -float Encoder::GetPulsesPerSecond(float currentTimeMs) { return 0; } +float IncrementalEncoder::GetPulsesPerSecond(float currentTimeMs) { return 0; } -float Encoder::GetRevolutionsPerSecond(float currentTimeMs) { return 0; } +float IncrementalEncoder::GetRevolutionsPerSecond(float currentTimeMs) { + return 0; +} -float Encoder::GetSpeed(float currentTimeMs) { return 0; } +float IncrementalEncoder::GetSpeed(float currentTimeMs) { return 0; } +*/ \ No newline at end of file diff --git a/Encoder.h b/Encoder.h index e85cdaf..bf0a672 100644 --- a/Encoder.h +++ b/Encoder.h @@ -1,19 +1,25 @@ #pragma once +#include "IncrementalEncoder.h" + namespace Passer { namespace RoboidControl { -/// @brief An Encoder measures the rotations of an axle using a rotary sensor -/// Some encoders are able to detect direction, while others can not. -class Encoder { +// Deprecated, use explicit IncrementalEncoder in the future +using Encoder = IncrementalEncoder; + +/* +/// @brief An Encoder measures the rotations of an axle using a rotary +/// sensor Some encoders are able to detect direction, while others can not. +class IncrementalEncoder { public: /// @brief Creates a sensor which measures distance from pulses /// @param pulsesPerRevolution The number of pulse edges which make a /// full rotation /// @param distancePerRevolution The distance a wheel travels per full /// rotation - Encoder(unsigned char pulsesPerRevolution = 1, - unsigned char distancePerRevolution = 1); + IncrementalEncoder(unsigned char pulsesPerRevolution = 1, + unsigned char distancePerRevolution = 1); /// @brief Get the total number of pulses since the previous call /// @return The number of pulses, is zero or greater @@ -45,7 +51,7 @@ public: /// meter unsigned char distancePerRevolution = 1; }; - +*/ } // namespace RoboidControl } // namespace Passer -using namespace Passer::RoboidControl; \ No newline at end of file +using namespace Passer::RoboidControl; diff --git a/FeedbackServo.cpp b/FeedbackServo.cpp deleted file mode 100644 index cab0e95..0000000 --- a/FeedbackServo.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "FeedbackServo.h" - -FeedbackServo::FeedbackServo() {} \ No newline at end of file diff --git a/IncrementalEncoder.cpp b/IncrementalEncoder.cpp new file mode 100644 index 0000000..2da89b8 --- /dev/null +++ b/IncrementalEncoder.cpp @@ -0,0 +1,19 @@ +#include "Encoder.h" + +IncrementalEncoder::IncrementalEncoder(unsigned char pulsesPerRevolution, + unsigned char distancePerRotation) { + this->pulsesPerRevolution = pulsesPerRevolution; + this->distancePerRevolution = distancePerRotation; +} + +int IncrementalEncoder::GetPulseCount() { return 0; } + +float IncrementalEncoder::GetDistance() { return 0; } + +float IncrementalEncoder::GetPulsesPerSecond(float currentTimeMs) { return 0; } + +float IncrementalEncoder::GetRevolutionsPerSecond(float currentTimeMs) { + return 0; +} + +float IncrementalEncoder::GetSpeed(float currentTimeMs) { return 0; }