PM2_Lib

Dependencies:   LSM9DS1 RangeFinder FastPWM

Revision:
8:6b747ad59ff5
Child:
10:fe74e8909d3f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PositionController.h	Mon Apr 19 15:54:15 2021 +0000
@@ -0,0 +1,57 @@
+#ifndef PositionController_H_
+#define PositionController_H_
+#include <cstdlib>
+#include <mbed.h>
+#include "EncoderCounter.h"
+#include "LowpassFilter.h"
+#include "ThreadFlag.h"
+#include "FastPWM.h"
+
+class PositionController
+{
+public:
+
+    PositionController(float counts_per_turn, float kn, float max_voltage, FastPWM& pwm, EncoderCounter& encoderCounter);
+    PositionController(float counts_per_turn, float kn, float kp, float p, float max_voltage, FastPWM& pwm, EncoderCounter& encoderCounter);
+
+    virtual ~PositionController();
+
+    float    getSpeedRPM();
+    float    getSpeedRPS();
+    void     setDesiredRotation(float desiredRotation);
+    void     setDesiredRotation(float desiredRotation, float maxSpeedRPS);
+    float    getRotation();
+
+private:
+
+    static const float TS;
+    static const float LOWPASS_FILTER_FREQUENCY;
+    static const float MIN_DUTY_CYCLE;
+    static const float MAX_DUTY_CYCLE;
+
+    float counts_per_turn;
+    float kn;
+    float kp;
+    float max_voltage;
+    float max_speed;
+    float p;
+
+    FastPWM&           pwm;
+    EncoderCounter&    encoderCounter;
+    short              previousValueCounter;
+    LowpassFilter      speedFilter;
+    float              desiredSpeed;
+    float              actualSpeed;
+    float              initialRotation;
+    float              actualRotation;
+    float              desiredRotation;
+
+    ThreadFlag         threadFlag;
+    Thread             thread;
+    Ticker             ticker;
+
+    void               run();
+    void               sendThreadFlag();
+};
+
+#endif /* PositionController_H_ */
\ No newline at end of file