PM2_Lib
Dependencies: LSM9DS1 RangeFinder FastPWM
SpeedController.h@3:8b42e643b294, 2021-04-01 (annotated)
- Committer:
- pmic
- Date:
- Thu Apr 01 14:31:43 2021 +0000
- Revision:
- 3:8b42e643b294
- Child:
- 4:9c003c402033
Changed Controller to SpeedController to only speedcontrol one motor per instance.
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:8b42e643b294 | 8 | |
pmic | 3:8b42e643b294 | 9 | class SpeedController |
pmic | 3:8b42e643b294 | 10 | { |
pmic | 3:8b42e643b294 | 11 | |
pmic | 3:8b42e643b294 | 12 | public: |
pmic | 3:8b42e643b294 | 13 | |
pmic | 3:8b42e643b294 | 14 | SpeedController(PwmOut& pwm, EncoderCounter& encoderCounter); |
pmic | 3:8b42e643b294 | 15 | |
pmic | 3:8b42e643b294 | 16 | virtual ~SpeedController(); |
pmic | 3:8b42e643b294 | 17 | |
pmic | 3:8b42e643b294 | 18 | void setDesiredSpeed(float desiredSpeed); |
pmic | 3:8b42e643b294 | 19 | float getSpeed(); |
pmic | 3:8b42e643b294 | 20 | |
pmic | 3:8b42e643b294 | 21 | private: |
pmic | 3:8b42e643b294 | 22 | |
pmic | 3:8b42e643b294 | 23 | static const float PERIOD; |
pmic | 3:8b42e643b294 | 24 | static const float COUNTS_PER_TURN; |
pmic | 3:8b42e643b294 | 25 | static const float LOWPASS_FILTER_FREQUENCY; |
pmic | 3:8b42e643b294 | 26 | static const float KN; |
pmic | 3:8b42e643b294 | 27 | static const float KP; |
pmic | 3:8b42e643b294 | 28 | static const float MAX_VOLTAGE; |
pmic | 3:8b42e643b294 | 29 | static const float MIN_DUTY_CYCLE; |
pmic | 3:8b42e643b294 | 30 | static const float MAX_DUTY_CYCLE; |
pmic | 3:8b42e643b294 | 31 | |
pmic | 3:8b42e643b294 | 32 | PwmOut& pwm; |
pmic | 3:8b42e643b294 | 33 | EncoderCounter& encoderCounter; |
pmic | 3:8b42e643b294 | 34 | short previousValueCounter; |
pmic | 3:8b42e643b294 | 35 | LowpassFilter speedFilter; |
pmic | 3:8b42e643b294 | 36 | float desiredSpeed; |
pmic | 3:8b42e643b294 | 37 | float actualSpeed; |
pmic | 3:8b42e643b294 | 38 | float actualAngle; |
pmic | 3:8b42e643b294 | 39 | |
pmic | 3:8b42e643b294 | 40 | ThreadFlag threadFlag; |
pmic | 3:8b42e643b294 | 41 | Thread thread; |
pmic | 3:8b42e643b294 | 42 | Ticker ticker; |
pmic | 3:8b42e643b294 | 43 | |
pmic | 3:8b42e643b294 | 44 | void sendThreadFlag(); |
pmic | 3:8b42e643b294 | 45 | void run(); |
pmic | 3:8b42e643b294 | 46 | |
pmic | 3:8b42e643b294 | 47 | }; |
pmic | 3:8b42e643b294 | 48 | |
pmic | 3:8b42e643b294 | 49 | #endif /* SpeedController_H_ */ |