Sunday, January 26, 2014

PID Controllers

I have a few ongoing projects where a feedback loop that considers a moving goal and adjusts to achieve that goal is essential. One of these projects is a two wheeled self balancing robot. This type of problem is perfect for a PID control loop. I have been procrastinating biting the PID bullet because I was under the impression that PID was not easy to learn or implement. Thankfully, after much searching, I have found a very straightforward and intuitive overview of PID.

After the above overviews I dug around to find some PID Controller pseudocode.
previous_error = 0
integral = 0 
  error = setpoint - measured_value
  integral = integral + error*dt
  derivative = (error - previous_error)/dt
  output = Kp*error + Ki*integral + Kd*derivative
  previous_error = error
  goto start

I am no longer intimidated by PID. Should be fun.

1 comment:

  1. I don't know where you find the time! This is good stuff; I did something similar several years ago in building a gyro camera stabilizer. Turning a significant flywheel @18000RPM and trying to keep it from surging...
    Wish we could share notes!