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 
start:
  error = setpoint - measured_value
  integral = integral + error*dt
  derivative = (error - previous_error)/dt
  output = Kp*error + Ki*integral + Kd*derivative
  previous_error = error
  wait(dt)
  goto start

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

3 comments:

  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!

    ReplyDelete
  2. Wow, that makes scene just give it a try to

    Buy Generic Viagra

    ReplyDelete
  3. Thanks for the GREAT info. You have helped me greatly : see more

    ReplyDelete