Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: 7_20_17_FSG_ 7_21_17_FSG 7_26_17_FSG
Fork of Controller by
controller.hpp@6:29cf76bb9956, 2017-07-28 (annotated)
- Committer:
- mdavis30
- Date:
- Fri Jul 28 18:49:24 2017 +0000
- Revision:
- 6:29cf76bb9956
- Parent:
- 0:2566234da01a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tzyoung | 0:2566234da01a | 1 | #ifndef MBED_DEPTHCONTROLLER_H |
tzyoung | 0:2566234da01a | 2 | #define MBED_DEPTHCONTROLLER_H |
tzyoung | 0:2566234da01a | 3 | |
tzyoung | 0:2566234da01a | 4 | #include "mbed.h" |
tzyoung | 0:2566234da01a | 5 | |
tzyoung | 0:2566234da01a | 6 | class PositionController |
tzyoung | 0:2566234da01a | 7 | { |
tzyoung | 0:2566234da01a | 8 | public: |
tzyoung | 0:2566234da01a | 9 | PositionController(); |
tzyoung | 0:2566234da01a | 10 | |
tzyoung | 0:2566234da01a | 11 | void update(float position, float velocity, float dt); |
tzyoung | 0:2566234da01a | 12 | |
tzyoung | 0:2566234da01a | 13 | float getOutput(); |
tzyoung | 0:2566234da01a | 14 | |
tzyoung | 0:2566234da01a | 15 | void setPgain(float gain); |
tzyoung | 0:2566234da01a | 16 | void setIgain(float gain); |
tzyoung | 0:2566234da01a | 17 | void setDgain(float gain); |
tzyoung | 0:2566234da01a | 18 | |
tzyoung | 0:2566234da01a | 19 | void writeSetPoint(float cmd); |
mdavis30 | 6:29cf76bb9956 | 20 | void writeSetPoint_la(float cmd); |
tzyoung | 0:2566234da01a | 21 | |
tzyoung | 0:2566234da01a | 22 | // void setConfigFlag(); |
tzyoung | 0:2566234da01a | 23 | |
tzyoung | 0:2566234da01a | 24 | protected: |
tzyoung | 0:2566234da01a | 25 | float _setPoint; |
tzyoung | 0:2566234da01a | 26 | float _Pgain; |
tzyoung | 0:2566234da01a | 27 | float _Dgain; |
tzyoung | 0:2566234da01a | 28 | float _Igain; |
tzyoung | 0:2566234da01a | 29 | |
tzyoung | 0:2566234da01a | 30 | float _error; |
tzyoung | 0:2566234da01a | 31 | |
tzyoung | 0:2566234da01a | 32 | float _integral; |
tzyoung | 0:2566234da01a | 33 | float _lastTime; |
tzyoung | 0:2566234da01a | 34 | float _dt; |
tzyoung | 0:2566234da01a | 35 | |
tzyoung | 0:2566234da01a | 36 | |
tzyoung | 0:2566234da01a | 37 | float _output; |
tzyoung | 0:2566234da01a | 38 | |
tzyoung | 0:2566234da01a | 39 | // bool configFlag; |
tzyoung | 0:2566234da01a | 40 | // int readConfiguration(); |
tzyoung | 0:2566234da01a | 41 | |
tzyoung | 0:2566234da01a | 42 | }; |
tzyoung | 0:2566234da01a | 43 | |
tzyoung | 0:2566234da01a | 44 | template <typename T> |
tzyoung | 0:2566234da01a | 45 | T clamp(T value, T min, T max) |
tzyoung | 0:2566234da01a | 46 | { |
tzyoung | 0:2566234da01a | 47 | if(value < min) { |
tzyoung | 0:2566234da01a | 48 | return min; |
tzyoung | 0:2566234da01a | 49 | } else if(value > max) { |
tzyoung | 0:2566234da01a | 50 | return max; |
tzyoung | 0:2566234da01a | 51 | } else { |
tzyoung | 0:2566234da01a | 52 | return value; |
tzyoung | 0:2566234da01a | 53 | } |
tzyoung | 0:2566234da01a | 54 | }; |
tzyoung | 0:2566234da01a | 55 | |
tzyoung | 0:2566234da01a | 56 | #endif |