Workshop 2
SpeedController.h@6:41dd03654c44, 2021-04-07 (annotated)
- Committer:
- pmic
- Date:
- Wed Apr 07 12:13:45 2021 +0000
- Revision:
- 6:41dd03654c44
- Parent:
- 5:6cd242a61e4c
Last commit before first workshop 2.
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 | 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 | 6:41dd03654c44 | 15 | SpeedController(float counts_per_turn, float kn, float kp, float max_voltage, FastPWM& pwm, EncoderCounter& encoderCounter); |
pmic | 3:8b42e643b294 | 16 | |
pmic | 3:8b42e643b294 | 17 | virtual ~SpeedController(); |
pmic | 3:8b42e643b294 | 18 | |
pmic | 4:9c003c402033 | 19 | void setDesiredSpeedRPM(float desiredSpeed); |
pmic | 4:9c003c402033 | 20 | float getSpeedRPM(); |
pmic | 4:9c003c402033 | 21 | void setDesiredSpeedRPS(float desiredSpeed); |
pmic | 4:9c003c402033 | 22 | float getSpeedRPS(); |
pmic | 3:8b42e643b294 | 23 | |
pmic | 3:8b42e643b294 | 24 | private: |
pmic | 3:8b42e643b294 | 25 | |
pmic | 6:41dd03654c44 | 26 | static const float TS; |
pmic | 3:8b42e643b294 | 27 | static const float LOWPASS_FILTER_FREQUENCY; |
pmic | 3:8b42e643b294 | 28 | static const float MIN_DUTY_CYCLE; |
pmic | 3:8b42e643b294 | 29 | static const float MAX_DUTY_CYCLE; |
pmic | 3:8b42e643b294 | 30 | |
pmic | 6:41dd03654c44 | 31 | float counts_per_turn; |
pmic | 6:41dd03654c44 | 32 | float kn; |
pmic | 6:41dd03654c44 | 33 | float kp; |
pmic | 6:41dd03654c44 | 34 | float max_voltage; |
pmic | 4:9c003c402033 | 35 | |
pmic | 5:6cd242a61e4c | 36 | FastPWM& pwm; |
pmic | 3:8b42e643b294 | 37 | EncoderCounter& encoderCounter; |
pmic | 3:8b42e643b294 | 38 | short previousValueCounter; |
pmic | 3:8b42e643b294 | 39 | LowpassFilter speedFilter; |
pmic | 3:8b42e643b294 | 40 | float desiredSpeed; |
pmic | 3:8b42e643b294 | 41 | float actualSpeed; |
pmic | 4:9c003c402033 | 42 | // float actualAngle; |
pmic | 3:8b42e643b294 | 43 | |
pmic | 3:8b42e643b294 | 44 | ThreadFlag threadFlag; |
pmic | 3:8b42e643b294 | 45 | Thread thread; |
pmic | 3:8b42e643b294 | 46 | Ticker ticker; |
pmic | 3:8b42e643b294 | 47 | |
pmic | 6:41dd03654c44 | 48 | void run(); |
pmic | 3:8b42e643b294 | 49 | void sendThreadFlag(); |
pmic | 3:8b42e643b294 | 50 | }; |
pmic | 3:8b42e643b294 | 51 | |
pmic | 3:8b42e643b294 | 52 | #endif /* SpeedController_H_ */ |