PM2_Lib
Dependencies: LSM9DS1 RangeFinder FastPWM
PositionController.h@8:6b747ad59ff5, 2021-04-19 (annotated)
- Committer:
- pmic
- Date:
- Mon Apr 19 15:54:15 2021 +0000
- Revision:
- 8:6b747ad59ff5
- Child:
- 10:fe74e8909d3f
Included simple p position controller for dc motor 2 in example and extended the libary.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmic | 8:6b747ad59ff5 | 1 | #ifndef PositionController_H_ |
pmic | 8:6b747ad59ff5 | 2 | #define PositionController_H_ |
pmic | 8:6b747ad59ff5 | 3 | #include <cstdlib> |
pmic | 8:6b747ad59ff5 | 4 | #include <mbed.h> |
pmic | 8:6b747ad59ff5 | 5 | #include "EncoderCounter.h" |
pmic | 8:6b747ad59ff5 | 6 | #include "LowpassFilter.h" |
pmic | 8:6b747ad59ff5 | 7 | #include "ThreadFlag.h" |
pmic | 8:6b747ad59ff5 | 8 | #include "FastPWM.h" |
pmic | 8:6b747ad59ff5 | 9 | |
pmic | 8:6b747ad59ff5 | 10 | class PositionController |
pmic | 8:6b747ad59ff5 | 11 | { |
pmic | 8:6b747ad59ff5 | 12 | public: |
pmic | 8:6b747ad59ff5 | 13 | |
pmic | 8:6b747ad59ff5 | 14 | PositionController(float counts_per_turn, float kn, float max_voltage, FastPWM& pwm, EncoderCounter& encoderCounter); |
pmic | 8:6b747ad59ff5 | 15 | PositionController(float counts_per_turn, float kn, float kp, float p, float max_voltage, FastPWM& pwm, EncoderCounter& encoderCounter); |
pmic | 8:6b747ad59ff5 | 16 | |
pmic | 8:6b747ad59ff5 | 17 | virtual ~PositionController(); |
pmic | 8:6b747ad59ff5 | 18 | |
pmic | 8:6b747ad59ff5 | 19 | float getSpeedRPM(); |
pmic | 8:6b747ad59ff5 | 20 | float getSpeedRPS(); |
pmic | 8:6b747ad59ff5 | 21 | void setDesiredRotation(float desiredRotation); |
pmic | 8:6b747ad59ff5 | 22 | void setDesiredRotation(float desiredRotation, float maxSpeedRPS); |
pmic | 8:6b747ad59ff5 | 23 | float getRotation(); |
pmic | 8:6b747ad59ff5 | 24 | |
pmic | 8:6b747ad59ff5 | 25 | private: |
pmic | 8:6b747ad59ff5 | 26 | |
pmic | 8:6b747ad59ff5 | 27 | static const float TS; |
pmic | 8:6b747ad59ff5 | 28 | static const float LOWPASS_FILTER_FREQUENCY; |
pmic | 8:6b747ad59ff5 | 29 | static const float MIN_DUTY_CYCLE; |
pmic | 8:6b747ad59ff5 | 30 | static const float MAX_DUTY_CYCLE; |
pmic | 8:6b747ad59ff5 | 31 | |
pmic | 8:6b747ad59ff5 | 32 | float counts_per_turn; |
pmic | 8:6b747ad59ff5 | 33 | float kn; |
pmic | 8:6b747ad59ff5 | 34 | float kp; |
pmic | 8:6b747ad59ff5 | 35 | float max_voltage; |
pmic | 8:6b747ad59ff5 | 36 | float max_speed; |
pmic | 8:6b747ad59ff5 | 37 | float p; |
pmic | 8:6b747ad59ff5 | 38 | |
pmic | 8:6b747ad59ff5 | 39 | FastPWM& pwm; |
pmic | 8:6b747ad59ff5 | 40 | EncoderCounter& encoderCounter; |
pmic | 8:6b747ad59ff5 | 41 | short previousValueCounter; |
pmic | 8:6b747ad59ff5 | 42 | LowpassFilter speedFilter; |
pmic | 8:6b747ad59ff5 | 43 | float desiredSpeed; |
pmic | 8:6b747ad59ff5 | 44 | float actualSpeed; |
pmic | 8:6b747ad59ff5 | 45 | float initialRotation; |
pmic | 8:6b747ad59ff5 | 46 | float actualRotation; |
pmic | 8:6b747ad59ff5 | 47 | float desiredRotation; |
pmic | 8:6b747ad59ff5 | 48 | |
pmic | 8:6b747ad59ff5 | 49 | ThreadFlag threadFlag; |
pmic | 8:6b747ad59ff5 | 50 | Thread thread; |
pmic | 8:6b747ad59ff5 | 51 | Ticker ticker; |
pmic | 8:6b747ad59ff5 | 52 | |
pmic | 8:6b747ad59ff5 | 53 | void run(); |
pmic | 8:6b747ad59ff5 | 54 | void sendThreadFlag(); |
pmic | 8:6b747ad59ff5 | 55 | }; |
pmic | 8:6b747ad59ff5 | 56 | |
pmic | 8:6b747ad59ff5 | 57 | #endif /* PositionController_H_ */ |