PM2_Lib
Dependencies: LSM9DS1 RangeFinder FastPWM
PositionController.h@10:fe74e8909d3f, 2022-02-10 (annotated)
- Committer:
- pmic
- Date:
- Thu Feb 10 12:04:36 2022 +0000
- Revision:
- 10:fe74e8909d3f
- Parent:
- 8:6b747ad59ff5
Minor adjustments.
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 | 10:fe74e8909d3f | 15 | PositionController(float counts_per_turn, float kn, float kp, float max_voltage, FastPWM& pwm, EncoderCounter& encoderCounter); |
pmic | 8:6b747ad59ff5 | 16 | PositionController(float counts_per_turn, float kn, float kp, float p, float max_voltage, FastPWM& pwm, EncoderCounter& encoderCounter); |
pmic | 8:6b747ad59ff5 | 17 | |
pmic | 8:6b747ad59ff5 | 18 | virtual ~PositionController(); |
pmic | 8:6b747ad59ff5 | 19 | |
pmic | 8:6b747ad59ff5 | 20 | float getSpeedRPM(); |
pmic | 8:6b747ad59ff5 | 21 | float getSpeedRPS(); |
pmic | 8:6b747ad59ff5 | 22 | void setDesiredRotation(float desiredRotation); |
pmic | 8:6b747ad59ff5 | 23 | void setDesiredRotation(float desiredRotation, float maxSpeedRPS); |
pmic | 8:6b747ad59ff5 | 24 | float getRotation(); |
pmic | 10:fe74e8909d3f | 25 | void setFeedForwardGain(float kn); |
pmic | 10:fe74e8909d3f | 26 | void setSpeedCntrlGain(float kp); |
pmic | 10:fe74e8909d3f | 27 | void setPositionCntrlGain(float p); |
pmic | 8:6b747ad59ff5 | 28 | |
pmic | 8:6b747ad59ff5 | 29 | private: |
pmic | 8:6b747ad59ff5 | 30 | |
pmic | 8:6b747ad59ff5 | 31 | static const float TS; |
pmic | 8:6b747ad59ff5 | 32 | static const float LOWPASS_FILTER_FREQUENCY; |
pmic | 8:6b747ad59ff5 | 33 | static const float MIN_DUTY_CYCLE; |
pmic | 8:6b747ad59ff5 | 34 | static const float MAX_DUTY_CYCLE; |
pmic | 8:6b747ad59ff5 | 35 | |
pmic | 8:6b747ad59ff5 | 36 | float counts_per_turn; |
pmic | 8:6b747ad59ff5 | 37 | float kn; |
pmic | 8:6b747ad59ff5 | 38 | float kp; |
pmic | 8:6b747ad59ff5 | 39 | float max_voltage; |
pmic | 8:6b747ad59ff5 | 40 | float max_speed; |
pmic | 8:6b747ad59ff5 | 41 | float p; |
pmic | 8:6b747ad59ff5 | 42 | |
pmic | 8:6b747ad59ff5 | 43 | FastPWM& pwm; |
pmic | 8:6b747ad59ff5 | 44 | EncoderCounter& encoderCounter; |
pmic | 8:6b747ad59ff5 | 45 | short previousValueCounter; |
pmic | 8:6b747ad59ff5 | 46 | LowpassFilter speedFilter; |
pmic | 8:6b747ad59ff5 | 47 | float desiredSpeed; |
pmic | 8:6b747ad59ff5 | 48 | float actualSpeed; |
pmic | 8:6b747ad59ff5 | 49 | float initialRotation; |
pmic | 8:6b747ad59ff5 | 50 | float actualRotation; |
pmic | 8:6b747ad59ff5 | 51 | float desiredRotation; |
pmic | 8:6b747ad59ff5 | 52 | |
pmic | 8:6b747ad59ff5 | 53 | ThreadFlag threadFlag; |
pmic | 8:6b747ad59ff5 | 54 | Thread thread; |
pmic | 8:6b747ad59ff5 | 55 | Ticker ticker; |
pmic | 8:6b747ad59ff5 | 56 | |
pmic | 8:6b747ad59ff5 | 57 | void run(); |
pmic | 8:6b747ad59ff5 | 58 | void sendThreadFlag(); |
pmic | 8:6b747ad59ff5 | 59 | }; |
pmic | 8:6b747ad59ff5 | 60 | |
pmic | 8:6b747ad59ff5 | 61 | #endif /* PositionController_H_ */ |