Workshop 2

Dependencies:   FastPWM

Revision:
3:8b42e643b294
Child:
4:9c003c402033
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SpeedController.h	Thu Apr 01 14:31:43 2021 +0000
@@ -0,0 +1,49 @@
+#ifndef SpeedController_H_
+#define SpeedController_H_
+#include <cstdlib>
+#include <mbed.h>
+#include "EncoderCounter.h"
+#include "LowpassFilter.h"
+#include "ThreadFlag.h"
+
+class SpeedController
+{
+
+public:
+
+    SpeedController(PwmOut& pwm, EncoderCounter& encoderCounter);
+
+    virtual ~SpeedController();
+
+    void     setDesiredSpeed(float desiredSpeed);
+    float    getSpeed();
+
+private:
+
+    static const float PERIOD;
+    static const float COUNTS_PER_TURN;
+    static const float LOWPASS_FILTER_FREQUENCY;
+    static const float KN;
+    static const float KP;
+    static const float MAX_VOLTAGE;
+    static const float MIN_DUTY_CYCLE;
+    static const float MAX_DUTY_CYCLE;
+
+    PwmOut&            pwm;
+    EncoderCounter&    encoderCounter;
+    short              previousValueCounter;
+    LowpassFilter      speedFilter;
+    float              desiredSpeed;
+    float              actualSpeed;
+    float              actualAngle;
+
+    ThreadFlag         threadFlag;
+    Thread             thread;
+    Ticker             ticker;
+
+    void               sendThreadFlag();
+    void               run();
+
+};
+
+#endif /* SpeedController_H_ */
\ No newline at end of file