Biorobotics 7 / BioroboticsMotorControl

Dependencies:   FastPWM QEI

Dependents:   PID_example Motor_calibration Demo_mode Demo_mode ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pid.h Source File

pid.h

00001 #pragma once
00002 
00003 class PID {
00004 private:
00005     double Kp, Ki, Kd;
00006     double error_integral;
00007     double error_previous;
00008     double pid_period; // Time between pid updates.
00009     bool first_update;
00010     
00011     // ---- Low Pass Filter variables ----
00012     double B[3];
00013     double A[2];
00014     double wz[2];
00015 public:
00016     PID();
00017     void set_period(double period);
00018     void set_k_values(double Kp, double Ki, double Kd);
00019     // Sets the error memory to 0.
00020     // Leaves the K values intact.
00021     void clear_state();
00022     
00023     double update(double error);
00024 
00025 private:
00026     double biquad_step(double x);
00027 };