PID motor controll for the biorobotics project.

Dependencies:   FastPWM QEI

Dependents:   PID_example Motor_calibration Demo_mode Demo_mode ... more

pid.h

Committer:
brass_phoenix
Date:
2018-10-19
Revision:
0:009e84d7af32
Child:
3:f1067b5bb5af

File content as of revision 0:009e84d7af32:

#pragma once

#include "BiQuad.h"

class PID {
private:
    double Kp, Ki, Kd;
    double error_integral;
    double error_previous;
    double pid_period; // Time between pid updates.
    bool first_update;
    
    // Filter to make sure the derivative component does not amplify the noise.
    BiQuad low_pass_filter;
public:
    PID();
    void set_period(double period);
    void set_k_values(double Kp, double Ki, double Kd);
    
    double update(double error);
};