PM2_Lib

Dependencies:   LSM9DS1 RangeFinder FastPWM

Committer:
pmic
Date:
Tue Apr 06 12:19:29 2021 +0000
Revision:
5:6cd242a61e4c
Parent:
4:9c003c402033
Child:
6:41dd03654c44
Introduce FastPWM Libary.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pmic 3:8b42e643b294 1 #ifndef SpeedController_H_
pmic 3:8b42e643b294 2 #define SpeedController_H_
pmic 3:8b42e643b294 3 #include <cstdlib>
pmic 3:8b42e643b294 4 #include <mbed.h>
pmic 3:8b42e643b294 5 #include "EncoderCounter.h"
pmic 3:8b42e643b294 6 #include "LowpassFilter.h"
pmic 3:8b42e643b294 7 #include "ThreadFlag.h"
pmic 5:6cd242a61e4c 8 #include "FastPWM.h"
pmic 3:8b42e643b294 9
pmic 3:8b42e643b294 10 class SpeedController
pmic 3:8b42e643b294 11 {
pmic 3:8b42e643b294 12 public:
pmic 3:8b42e643b294 13
pmic 5:6cd242a61e4c 14 SpeedController(float COUNTS_PER_TURN, float KN, float KP, float MAX_VOLTAGE, FastPWM& pwm, EncoderCounter& encoderCounter);
pmic 3:8b42e643b294 15
pmic 3:8b42e643b294 16 virtual ~SpeedController();
pmic 3:8b42e643b294 17
pmic 4:9c003c402033 18 void setDesiredSpeedRPM(float desiredSpeed);
pmic 4:9c003c402033 19 float getSpeedRPM();
pmic 4:9c003c402033 20 void setDesiredSpeedRPS(float desiredSpeed);
pmic 4:9c003c402033 21 float getSpeedRPS();
pmic 3:8b42e643b294 22
pmic 3:8b42e643b294 23 private:
pmic 3:8b42e643b294 24
pmic 3:8b42e643b294 25 static const float PERIOD;
pmic 4:9c003c402033 26 // static const float COUNTS_PER_TURN;
pmic 3:8b42e643b294 27 static const float LOWPASS_FILTER_FREQUENCY;
pmic 4:9c003c402033 28 // static const float KN;
pmic 4:9c003c402033 29 // static const float KP;
pmic 4:9c003c402033 30 // static const float MAX_VOLTAGE;
pmic 3:8b42e643b294 31 static const float MIN_DUTY_CYCLE;
pmic 3:8b42e643b294 32 static const float MAX_DUTY_CYCLE;
pmic 3:8b42e643b294 33
pmic 4:9c003c402033 34 float COUNTS_PER_TURN;
pmic 4:9c003c402033 35 float KN;
pmic 4:9c003c402033 36 float KP;
pmic 4:9c003c402033 37 float MAX_VOLTAGE;
pmic 4:9c003c402033 38
pmic 5:6cd242a61e4c 39 FastPWM& pwm;
pmic 3:8b42e643b294 40 EncoderCounter& encoderCounter;
pmic 3:8b42e643b294 41 short previousValueCounter;
pmic 3:8b42e643b294 42 LowpassFilter speedFilter;
pmic 3:8b42e643b294 43 float desiredSpeed;
pmic 3:8b42e643b294 44 float actualSpeed;
pmic 4:9c003c402033 45 // float actualAngle;
pmic 3:8b42e643b294 46
pmic 3:8b42e643b294 47 ThreadFlag threadFlag;
pmic 3:8b42e643b294 48 Thread thread;
pmic 3:8b42e643b294 49 Ticker ticker;
pmic 3:8b42e643b294 50
pmic 3:8b42e643b294 51 void sendThreadFlag();
pmic 3:8b42e643b294 52 void run();
pmic 3:8b42e643b294 53 };
pmic 3:8b42e643b294 54
pmic 3:8b42e643b294 55 #endif /* SpeedController_H_ */