PID motor controll for the biorobotics project.
Dependents: PID_example Motor_calibration Demo_mode Demo_mode ... more
pid.h@14:e5fc69651b1d, 2018-11-05 (annotated)
- Committer:
- MAHCSnijders
- Date:
- Mon Nov 05 16:03:11 2018 +0000
- Revision:
- 14:e5fc69651b1d
- Parent:
- 4:5353c5d0d2ed
Fixed constant r
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
brass_phoenix | 0:009e84d7af32 | 1 | #pragma once |
brass_phoenix | 0:009e84d7af32 | 2 | |
brass_phoenix | 0:009e84d7af32 | 3 | class PID { |
brass_phoenix | 0:009e84d7af32 | 4 | private: |
brass_phoenix | 0:009e84d7af32 | 5 | double Kp, Ki, Kd; |
brass_phoenix | 0:009e84d7af32 | 6 | double error_integral; |
brass_phoenix | 0:009e84d7af32 | 7 | double error_previous; |
brass_phoenix | 0:009e84d7af32 | 8 | double pid_period; // Time between pid updates. |
brass_phoenix | 0:009e84d7af32 | 9 | bool first_update; |
brass_phoenix | 0:009e84d7af32 | 10 | |
brass_phoenix | 3:f1067b5bb5af | 11 | // ---- Low Pass Filter variables ---- |
brass_phoenix | 3:f1067b5bb5af | 12 | double B[3]; |
brass_phoenix | 3:f1067b5bb5af | 13 | double A[2]; |
brass_phoenix | 3:f1067b5bb5af | 14 | double wz[2]; |
brass_phoenix | 0:009e84d7af32 | 15 | public: |
brass_phoenix | 0:009e84d7af32 | 16 | PID(); |
brass_phoenix | 0:009e84d7af32 | 17 | void set_period(double period); |
brass_phoenix | 0:009e84d7af32 | 18 | void set_k_values(double Kp, double Ki, double Kd); |
brass_phoenix | 4:5353c5d0d2ed | 19 | // Sets the error memory to 0. |
brass_phoenix | 4:5353c5d0d2ed | 20 | // Leaves the K values intact. |
brass_phoenix | 4:5353c5d0d2ed | 21 | void clear_state(); |
brass_phoenix | 0:009e84d7af32 | 22 | |
brass_phoenix | 0:009e84d7af32 | 23 | double update(double error); |
brass_phoenix | 4:5353c5d0d2ed | 24 | |
brass_phoenix | 4:5353c5d0d2ed | 25 | private: |
brass_phoenix | 3:f1067b5bb5af | 26 | double biquad_step(double x); |
brass_phoenix | 0:009e84d7af32 | 27 | }; |