mit
PID.h@5:e90c8b57811c, 2018-12-24 (annotated)
- Committer:
- coldplay
- Date:
- Mon Dec 24 03:47:49 2018 +0000
- Revision:
- 5:e90c8b57811c
- Parent:
- 4:5ae9f8b3a16f
mit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
benkatz | 2:89bb6272869b | 1 | //Ben Katz, 2013 |
benkatz | 2:89bb6272869b | 2 | //PID Controller class |
benkatz | 2:89bb6272869b | 3 | |
benkatz | 2:89bb6272869b | 4 | #include "mbed.h" |
benkatz | 2:89bb6272869b | 5 | |
abuchan | 4:5ae9f8b3a16f | 6 | #ifndef PID_CONTROLLER_H |
abuchan | 4:5ae9f8b3a16f | 7 | #define PID_CONTROLLER_H |
benkatz | 2:89bb6272869b | 8 | |
abuchan | 4:5ae9f8b3a16f | 9 | class PIDController { |
abuchan | 4:5ae9f8b3a16f | 10 | public: |
abuchan | 4:5ae9f8b3a16f | 11 | PIDController(float p_gain, float d_gain, float i_gain); |
abuchan | 4:5ae9f8b3a16f | 12 | |
abuchan | 4:5ae9f8b3a16f | 13 | float command_position(float current_position); |
abuchan | 4:5ae9f8b3a16f | 14 | float command_torque(float current_current); |
abuchan | 4:5ae9f8b3a16f | 15 | float command_position_tm(float current_position, float current_current); |
abuchan | 4:5ae9f8b3a16f | 16 | |
abuchan | 4:5ae9f8b3a16f | 17 | // Process variable commanded value |
abuchan | 4:5ae9f8b3a16f | 18 | float command; |
abuchan | 4:5ae9f8b3a16f | 19 | float current_torque; |
abuchan | 4:5ae9f8b3a16f | 20 | |
abuchan | 4:5ae9f8b3a16f | 21 | void set_command(float command); |
abuchan | 4:5ae9f8b3a16f | 22 | |
abuchan | 4:5ae9f8b3a16f | 23 | private: |
abuchan | 4:5ae9f8b3a16f | 24 | float kp; |
abuchan | 4:5ae9f8b3a16f | 25 | float kd; |
abuchan | 4:5ae9f8b3a16f | 26 | float ki; |
abuchan | 4:5ae9f8b3a16f | 27 | |
abuchan | 4:5ae9f8b3a16f | 28 | // State for process variable (position for now) |
abuchan | 4:5ae9f8b3a16f | 29 | float error; |
abuchan | 4:5ae9f8b3a16f | 30 | float old_error; |
abuchan | 4:5ae9f8b3a16f | 31 | float integral_error; |
abuchan | 4:5ae9f8b3a16f | 32 | |
abuchan | 4:5ae9f8b3a16f | 33 | // Current command (fuse with command?) |
abuchan | 4:5ae9f8b3a16f | 34 | float torque_command; |
abuchan | 4:5ae9f8b3a16f | 35 | float torque_error; |
abuchan | 4:5ae9f8b3a16f | 36 | float torque_integral_error; |
abuchan | 4:5ae9f8b3a16f | 37 | float torque_history[5]; |
abuchan | 4:5ae9f8b3a16f | 38 | |
abuchan | 4:5ae9f8b3a16f | 39 | float direction; |
abuchan | 4:5ae9f8b3a16f | 40 | }; |
benkatz | 3:cae0b305d54c | 41 | |
benkatz | 2:89bb6272869b | 42 | #endif |