From e995d4cec9a2c7dd630edd7868592c9e434a733c Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 29 Jan 2024 10:48:37 +0100 Subject: [PATCH] Fixed missing IncrementalEncoder.h --- IncrementalEncoder.h | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 IncrementalEncoder.h diff --git a/IncrementalEncoder.h b/IncrementalEncoder.h new file mode 100644 index 0000000..83bd135 --- /dev/null +++ b/IncrementalEncoder.h @@ -0,0 +1,51 @@ +#pragma once + +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 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 + 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 + virtual int GetPulseCount(); + /// @brief Get the pulse speed since the previous call + /// @param currentTimeMs The clock time in milliseconds + /// @return The average pulses per second in the last period. + virtual float GetPulsesPerSecond(float currentTimeMs); + + /// @brief Get the distance traveled since the previous call + /// @return The distance in meters. + virtual float GetDistance(); + + /// @brief Get the rotation speed since the previous call + /// @param currentTimeMs The clock time in milliseconds + /// @return The speed in rotations per second + virtual float GetRevolutionsPerSecond(float currentTimeMs); + + /// @brief Get the speed since the previous call + /// @param currentTimeMs The clock time in milliseconds + /// @return The speed in meters per second. + /// @note this value is dependent on the accurate setting of the + /// pulsesPerRevolution and distancePerRevolution parameters; + virtual float GetSpeed(float currentTimeMs); + + /// @brief The numer of pulses corresponding to a full rotation of the axle + unsigned char pulsesPerRevolution = 1; + /// @brief The number of revolutions which makes the wheel move forward 1 + /// meter + unsigned char distancePerRevolution = 1; +}; + +} // namespace RoboidControl +} // namespace Passer +using namespace Passer::RoboidControl; \ No newline at end of file