Decoupled position and current control working.

Dependencies:   QEI mbed-src

Committer:
abuchan
Date:
Tue Nov 24 03:56:22 2015 +0000
Revision:
4:5ae9f8b3a16f
Parent:
3:cae0b305d54c
Decoupled position and current control working.

Who changed what in which revision?

UserRevisionLine numberNew 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