done with all changes for new encoder
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <ESP32Encoder.h>
|
||||
#include <esp32_pcnt.h>
|
||||
|
||||
/**
|
||||
* @brief The default size of numbers to be taken in account for the average.
|
||||
@@ -39,20 +39,31 @@
|
||||
*/
|
||||
class Speedometer {
|
||||
public:
|
||||
Speedometer();
|
||||
~Speedometer();
|
||||
/**
|
||||
* @brief Enum to control the direction.
|
||||
*
|
||||
* If the Direction is Forward, the internal counter counts up and a positiv speed will be returned.
|
||||
* If the Direction is Backward, the internal counter counts down and a negativ speed will be returned.
|
||||
* If the Dorection is None, no measurement will be taken.
|
||||
*/
|
||||
enum Direction {
|
||||
None,
|
||||
Forward,
|
||||
Backward
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Initialize the speedometer
|
||||
* @brief Construct a new Speedometer object
|
||||
*
|
||||
* @param pinA Pin on the Esp from the encoder.
|
||||
* @param pinB Pin on the Esp from the encoder.
|
||||
* @param pin Pin on the Esp from the encoder.
|
||||
* @param diameter Diameter of the wheel in meters.
|
||||
* @param steps Encodersteps for a complete wheel rotation.
|
||||
* @param numOfValForAvg Number of last values to be taken into account for the average.
|
||||
*/
|
||||
void init(uint8_t pinA, uint8_t pinB, double diameter, uint16_t steps, uint8_t numOfValForAvg);
|
||||
void init(uint8_t pinA, uint8_t pinB, double diameter, uint16_t steps);
|
||||
Speedometer(uint8_t pin, double diameter, uint16_t steps, uint8_t numOfValForAvg);
|
||||
Speedometer(uint8_t pin, double diameter, uint16_t steps);
|
||||
|
||||
~Speedometer();
|
||||
|
||||
/**
|
||||
* @brief Calls runSpeedometer() to update all Values.
|
||||
@@ -72,6 +83,13 @@ class Speedometer {
|
||||
*/
|
||||
void runSpeedometer();
|
||||
|
||||
/**
|
||||
* @brief Set the direction
|
||||
*
|
||||
* @param dir Direction
|
||||
*/
|
||||
void setDirection(Direction dir) { this->currentDirection = dir; }
|
||||
|
||||
/**
|
||||
* @brief Set the number of last values to be taken into account for the average.
|
||||
*
|
||||
@@ -82,7 +100,9 @@ class Speedometer {
|
||||
/**
|
||||
* @brief Set the Enc Filter to prevent bouncing
|
||||
*
|
||||
* @param val default = 250, max = 1023
|
||||
* ignore pulses less than val x 2.5ns
|
||||
*
|
||||
* @param val default = 1000, max = 1023
|
||||
*/
|
||||
void setEncFilter(uint16_t val);
|
||||
|
||||
@@ -91,14 +111,21 @@ class Speedometer {
|
||||
*
|
||||
* @param delayLoop time in Milliseconds
|
||||
*/
|
||||
void setDelay(uint8_t delayLoop);
|
||||
void setDelay(uint8_t delayLoop) { this->delayLoop = delayLoop; }
|
||||
|
||||
/**
|
||||
* @brief Get the Direction
|
||||
*
|
||||
* @return Direction
|
||||
*/
|
||||
Direction getDirection() { return this->currentDirection; }
|
||||
|
||||
/**
|
||||
* @brief Get the calculated speed of the Wheel
|
||||
*
|
||||
* @return double speed in m/s
|
||||
*/
|
||||
double getSpeed();
|
||||
double getSpeed() { return this->speed; }
|
||||
|
||||
/**
|
||||
* @brief Start calibration
|
||||
@@ -120,14 +147,15 @@ class Speedometer {
|
||||
|
||||
|
||||
private:
|
||||
void init(uint8_t pin, double diameter, uint16_t steps);
|
||||
void initAvgBuf();
|
||||
void addValToBuf(int16_t val);
|
||||
void updateAvgBufSize();
|
||||
int16_t calcAverage();
|
||||
|
||||
ESP32Encoder encoder;
|
||||
PulseCounter* pulseCounter;
|
||||
Direction currentDirection = Direction::None;
|
||||
|
||||
bool isInit = false;
|
||||
bool calibrationRunning = false;
|
||||
|
||||
double speed = 0;
|
||||
|
||||
Reference in New Issue
Block a user