Files
Embedded-System-Projects/Project_3_Dynamic_Controller/include/speed_estimator.h
T

37 lines
610 B
C++

#ifndef SPEED_ESTIMATOR_H
#define SPEED_ESTIMATOR_H
#include <stdint.h>
class Speed_estimator
{
public:
Speed_estimator(
double countsPerRevolution,
double sampleTimeSeconds
);
void reset(int32_t initialPosition);
double update(int32_t currentPosition);
double rpm() const;
private:
static const uint8_t WINDOW_SIZE = 10;
double countsPerRevolution;
double sampleTime;
int32_t previousPosition;
int32_t countHistory[WINDOW_SIZE];
int32_t rollingCounts;
uint8_t historyIndex;
uint8_t samplesFilled;
double currentRPM;
};
#endif