PM2_Lib

Dependencies:   LSM9DS1 RangeFinder FastPWM

Committer:
pmic
Date:
Thu Feb 10 12:04:36 2022 +0000
Revision:
10:fe74e8909d3f
Parent:
6:41dd03654c44
Minor adjustments.

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 6:41dd03654c44 14 SpeedController(float counts_per_turn, float kn, 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 setDesiredSpeedRPS(float desiredSpeed);
pmic 4:9c003c402033 19 float getSpeedRPS();
pmic 10:fe74e8909d3f 20 float getSpeedRPM();
pmic 10:fe74e8909d3f 21 void setFeedForwardGain(float kn);
pmic 10:fe74e8909d3f 22 void setSpeedCntrlGain(float kp);
pmic 3:8b42e643b294 23
pmic 3:8b42e643b294 24 private:
pmic 3:8b42e643b294 25
pmic 10:fe74e8909d3f 26 void setDesiredSpeedRPM(float desiredSpeed);
pmic 10:fe74e8909d3f 27
pmic 6:41dd03654c44 28 static const float TS;
pmic 3:8b42e643b294 29 static const float LOWPASS_FILTER_FREQUENCY;
pmic 3:8b42e643b294 30 static const float MIN_DUTY_CYCLE;
pmic 3:8b42e643b294 31 static const float MAX_DUTY_CYCLE;
pmic 3:8b42e643b294 32
pmic 6:41dd03654c44 33 float counts_per_turn;
pmic 6:41dd03654c44 34 float kn;
pmic 6:41dd03654c44 35 float kp;
pmic 6:41dd03654c44 36 float max_voltage;
pmic 4:9c003c402033 37
pmic 5:6cd242a61e4c 38 FastPWM& pwm;
pmic 3:8b42e643b294 39 EncoderCounter& encoderCounter;
pmic 3:8b42e643b294 40 short previousValueCounter;
pmic 3:8b42e643b294 41 LowpassFilter speedFilter;
pmic 3:8b42e643b294 42 float desiredSpeed;
pmic 3:8b42e643b294 43 float actualSpeed;
pmic 4:9c003c402033 44 // float actualAngle;
pmic 3:8b42e643b294 45
pmic 3:8b42e643b294 46 ThreadFlag threadFlag;
pmic 3:8b42e643b294 47 Thread thread;
pmic 3:8b42e643b294 48 Ticker ticker;
pmic 3:8b42e643b294 49
pmic 6:41dd03654c44 50 void run();
pmic 3:8b42e643b294 51 void sendThreadFlag();
pmic 3:8b42e643b294 52 };
pmic 3:8b42e643b294 53
pmic 3:8b42e643b294 54 #endif /* SpeedController_H_ */