- todos
- test driving
This commit is contained in:
@@ -16,14 +16,14 @@ Speedometer::Speedometer(uint8_t pin, double diameter, uint16_t steps) {
|
||||
this->steps = steps;
|
||||
|
||||
this->pulseCounter = new Counter(pin);
|
||||
this->pulseCounter->setFilterValue(1000); // ignore pulses less than 1000 x 2.5ns
|
||||
this->pulseCounter->setFilterValue(1023); // ignore pulses less than 1000 x 2.5ns
|
||||
|
||||
this->pulseCounter->clear();
|
||||
this->pulseCounter->resume();
|
||||
|
||||
Component::loopDelay = Speedometer::loopDelay;
|
||||
|
||||
clearAvgBuf();
|
||||
this->clearAvgBuf();
|
||||
}
|
||||
|
||||
Speedometer::~Speedometer() {
|
||||
@@ -47,18 +47,27 @@ void Speedometer::run() {
|
||||
double n = (double)pulse / this->steps; // Wheel revolutions in absolute time
|
||||
double u = n / ((double)elapsedTime / 1000); // Wheel revolutions per second
|
||||
double ms = u * (diameter * PI); // Speed in m/s
|
||||
double rad = u * 2 * PI;
|
||||
|
||||
if (speed < 0.1) {
|
||||
speed = 0;
|
||||
rad = 0;
|
||||
}
|
||||
|
||||
switch (this->currentDirection) {
|
||||
case Direction::Forward :
|
||||
this->speed = ms;
|
||||
this->rad = rad;
|
||||
break;
|
||||
|
||||
case Direction::Backward :
|
||||
this->speed = -ms;
|
||||
this->rad = -rad;
|
||||
break;
|
||||
|
||||
case Direction::None :
|
||||
this->speed = 0;
|
||||
this->rad = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,13 +59,6 @@ class Speedometer : public Component {
|
||||
*/
|
||||
void setDirection(Direction dir);
|
||||
|
||||
/**
|
||||
* @brief Set the number of last values to be taken into account for the average.
|
||||
*
|
||||
* @param val length of the array
|
||||
*/
|
||||
void setNumOfValForAvg(uint8_t val);
|
||||
|
||||
/**
|
||||
* @brief Set the Enc Filter to prevent bouncing
|
||||
*
|
||||
@@ -88,6 +81,7 @@ class Speedometer : public Component {
|
||||
* @return double speed in m/s
|
||||
*/
|
||||
double getSpeed() const { return this->speed; }
|
||||
double getSpeedRad() const { return this->rad; };
|
||||
double getAvgSpeed() const;
|
||||
|
||||
/**
|
||||
@@ -111,7 +105,6 @@ class Speedometer : public Component {
|
||||
|
||||
private:
|
||||
void run() override;
|
||||
void init(uint8_t pin, double diameter, uint16_t steps);
|
||||
void clearAvgBuf();
|
||||
void addValToBuf(int16_t val);
|
||||
int16_t calcAverage() const;
|
||||
@@ -126,6 +119,7 @@ class Speedometer : public Component {
|
||||
bool calibrationRunning = false;
|
||||
|
||||
double speed = 0;
|
||||
double rad = 0;
|
||||
double diameter;
|
||||
|
||||
uint8_t printCounter = 0;
|
||||
|
||||
Reference in New Issue
Block a user