View Single Post
  #5   Spotlight this post!  
Unread 28-01-2004, 22:51
Larry Barello Larry Barello is offline
http://www.barello.net
#0492 (Titan Robotics Club)
Team Role: Mentor
 
Join Date: Jan 2002
Location: Bellevue, WA
Posts: 85
Larry Barello has a spectacular aura aboutLarry Barello has a spectacular aura about
Re: PID control loop/Encoder question

Quote:
Originally Posted by Zee
Hey guys, I'm a programmer for a rookie team. We're going to try to use Digikey encoders to help with velocity control. I've seen a few websites that help, like:

http://www.barello.net/Papers/Motion_Control/index.htm

http://nrg.chaosnet.org/repository/viewcode?id=0

Once I've figured out the error between requested speed and actual speed, I don't really understand what commands I would send to the motors to make the proper adjustments. Could anyone explain how that would work? Any help is appreciated.
Typically the output of the PID loop is a signed number representing the power delivered to the motor. Unfortunately for IFI they don't use a signed number: they use 0 through 127 for 100% to 0% reverse and 127 through 255 for 0% to 100% forward.

So, if you have a signed number (e.g. -127 to 0 to 127) just add 127 to that to get an IFI compatible number. The reverse can be done to convert Joystick readings into signed numbers.

Beware, you need to explicitely declare variables as signed with the Microchip C compiler. I recommend working with 'int' values to avoid overflow problems, then clipping to +/- 127 then converting for output to IFI controllers.

Figuring out the function to transform error into output power can be tricky. Simple proportional and integral terms are all you need, but, check the results. If the output is being clipped (e.g. you have hit the stops) stop accumulating integral errors!

Figuring out the constants is also tricky. It depends upon your loop rate (fixed in IFI stuff) encoder resolution, velocity, etc. The integral term usually has a fractional gain while the proportional one usually has a fairly small number (1-30) - but again, it all depends.

Last edited by Larry Barello : 28-01-2004 at 22:55.