jiexuan fan / ServoController_2

Dependencies:   QEI mbed-src

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PID.h Source File

PID.h

00001 //Ben Katz, 2013
00002 //PID Controller class
00003 
00004 #include "mbed.h"
00005 
00006 #ifndef PID_CONTROLLER_H
00007 #define PID_CONTROLLER_H
00008 
00009 class PIDController {
00010     public:
00011         PIDController(float p_gain, float d_gain, float i_gain);
00012     
00013         float command_position(float current_position);
00014         float command_torque(float current_current);
00015         float command_position_tm(float current_position, float current_current);
00016         
00017         // Process variable commanded value
00018         float command;
00019         float current_torque;
00020         
00021         void set_command(float command);
00022     
00023     private:
00024         float kp;
00025         float kd;
00026         float ki;
00027         
00028         // State for process variable (position for now)
00029         float error;
00030         float old_error;
00031         float integral_error;
00032         
00033         // Current command (fuse with command?)
00034         float torque_command;
00035         float torque_error;
00036         float torque_integral_error;
00037         float torque_history[5];
00038         
00039         float direction;
00040 };
00041 
00042 #endif