Improved encoder support

This commit is contained in:
Pascal Serrarens 2024-01-29 10:46:36 +01:00
parent b86484d59d
commit d22fc8e244
6 changed files with 48 additions and 20 deletions

2
AbsoluteEncoder.cpp Normal file
View File

@ -0,0 +1,2 @@
#include "AbsoluteEncoder.h"

View File

@ -5,11 +5,12 @@
namespace Passer { namespace Passer {
namespace RoboidContol { namespace RoboidContol {
class FeedbackServo : public ServoMotor { class AbsoluteEncoder {
public: public:
FeedbackServo(); AbsoluteEncoder() {}
virtual float GetActualAngle() = 0; virtual float GetActualAngle() = 0;
virtual float GetActualVelocity() = 0;
}; };
} // namespace RoboidContol } // namespace RoboidContol

View File

@ -1,18 +1,21 @@
/*
#include "Encoder.h" #include "Encoder.h"
Encoder::Encoder(unsigned char pulsesPerRevolution, IncrementalEncoder::IncrementalEncoder(unsigned char pulsesPerRevolution,
unsigned char distancePerRotation) { unsigned char distancePerRotation) {
//: Encoder::Encoder() {
this->pulsesPerRevolution = pulsesPerRevolution; this->pulsesPerRevolution = pulsesPerRevolution;
this->distancePerRevolution = distancePerRotation; 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; }
*/

View File

@ -1,18 +1,24 @@
#pragma once #pragma once
#include "IncrementalEncoder.h"
namespace Passer { namespace Passer {
namespace RoboidControl { namespace RoboidControl {
/// @brief An Encoder measures the rotations of an axle using a rotary sensor // Deprecated, use explicit IncrementalEncoder in the future
/// Some encoders are able to detect direction, while others can not. using Encoder = IncrementalEncoder;
class Encoder {
/*
/// @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: public:
/// @brief Creates a sensor which measures distance from pulses /// @brief Creates a sensor which measures distance from pulses
/// @param pulsesPerRevolution The number of pulse edges which make a /// @param pulsesPerRevolution The number of pulse edges which make a
/// full rotation /// full rotation
/// @param distancePerRevolution The distance a wheel travels per full /// @param distancePerRevolution The distance a wheel travels per full
/// rotation /// rotation
Encoder(unsigned char pulsesPerRevolution = 1, IncrementalEncoder(unsigned char pulsesPerRevolution = 1,
unsigned char distancePerRevolution = 1); unsigned char distancePerRevolution = 1);
/// @brief Get the total number of pulses since the previous call /// @brief Get the total number of pulses since the previous call
@ -45,7 +51,7 @@ public:
/// meter /// meter
unsigned char distancePerRevolution = 1; unsigned char distancePerRevolution = 1;
}; };
*/
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer } // namespace Passer
using namespace Passer::RoboidControl; using namespace Passer::RoboidControl;

View File

@ -1,3 +0,0 @@
#include "FeedbackServo.h"
FeedbackServo::FeedbackServo() {}

19
IncrementalEncoder.cpp Normal file
View File

@ -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; }