Shop OBEX P1 Docs P2 Docs Learn Events
New Object for the Exchange- PID Loops — Parallax Forums

New Object for the Exchange- PID Loops

crgwbrcrgwbr Posts: 614
edited 2007-09-27 23:24 in Propeller 1
Hey Everyone,
I finally got some spare time, so I decided to write a PID loop for the propellor. It implements the Proportional, Integral, and Derivative equations. If your application doesn't require on of those functions, just comment it out of the code. It can be found on the object exchange here.

Hope this helps someone out,
Craig

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"... one of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs." -

"If Python is executable pseudocode, then perl is executable line noise."

"The best accelerator available for a Mac is one that causes it to go at 9.81 m/s2."

"My software never has bugs. It just develops random features."

"Windows isn't a virus, viruses do something."

"Programmers are tools for converting caffeine into code."

"Enter any 11-digit prime number to continue."

Comments

  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-09-26 15:10
    Shouldn't each term have its own gain?

    Graham
  • crgwbrcrgwbr Posts: 614
    edited 2007-09-26 15:25
    Some apps do require individual gains, but most of things I have worked on do not need this. They seem to work just fine with just one gain.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "... one of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs." -

    "If Python is executable pseudocode, then perl is executable line noise."

    "The best accelerator available for a Mac is one that causes it to go at 9.81 m/s2."

    "My software never has bugs. It just develops random features."

    "Windows isn't a virus, viruses do something."

    "Programmers are tools for converting caffeine into code."

    "Enter any 11-digit prime number to continue."
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-09-26 16:24
    I guess it will just depend on the performance required and on the stability of the system, I did control from a very abstract end looking at root loci in the s-plane, this can make you worry unduly [noparse]:)[/noparse]

    Graham
  • SkogsgurraSkogsgurra Posts: 231
    edited 2007-09-26 18:19
    OK, one gain may be fine if you just want to run a demo. But you need to adjust P, D and I separately when you run an actual application with hardware connected.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • rjo_rjo_ Posts: 1,825
    edited 2007-09-26 19:06
    Craig,

    PID and quad encoding are two issues that have remained at a distance for me. Your very nice code and a visit to the Wikipedia on PID have cleared up PID... really simple when it is done right[noparse]:)[/noparse]

    I really wish you or one of the other regulars would document a physical implentation using both PID and quad encoding, with commonly available parts.

    Thanks again.

    Rich
  • crgwbrcrgwbr Posts: 614
    edited 2007-09-26 19:27
    As far as quadrature encoding, I don't have much experience. I use quadrature output encoders all the time, but the rotary encoder object always seems to work perfectly for what I need to do. As far as a real life PID example goes, it's coming, but give me a couple weeks to write the app notes on it; I'm really busy at work right now. Skoggsgurra, I'm sure that there are some applications that require separate gain controls on P, I, and D; I just haven't run into anything that needs it yet. But please, feel free to modify the code as you please and post it here. All I ask is that you leave me a little credit for the base code in the top header.

    Regards,
    Craig

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "... one of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs." -

    "If Python is executable pseudocode, then perl is executable line noise."

    "The best accelerator available for a Mac is one that causes it to go at 9.81 m/s2."

    "My software never has bugs. It just develops random features."

    "Windows isn't a virus, viruses do something."

    "Programmers are tools for converting caffeine into code."

    "Enter any 11-digit prime number to continue."
  • SkogsgurraSkogsgurra Posts: 231
    edited 2007-09-27 08:28
    It is a mystery to me why a simple addition of an error term, its integral and derivative has such an air of "mystery" around it. I think it is the way unexperienced teachers introduce the subject in schools. Enhanced by the introduction of pole-placing, Nyquist and Bode. The following article (there are hundreds of similar articles) is a good summary and also shows that there are many shades of PID. As a matter of fact, I have seldom used the D action in my 40+ years of drive and drive systems engineering. Multiple time constants are usually better handled by a "divide-and-conquer" method aka cascade control.

    The link: http://members.aol.com/pidcontrol/pid_algorithm.html

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-09-27 08:57
    Rich, a quadrature encoder has only 4 wires, two are power and two are the two phases, connect these to prop, run one of the quadrature encoder programs, enjoy,

    But if you wanted to combine quadrature encoding, PID and some PWM for good luck then this would do the trick: http://ww1.microchip.com/downloads/en/AppNotes/00964A.pdf but with an encoder instead of a potentiometer (would need an index pulse too).

    Graham
  • rjo_rjo_ Posts: 1,825
    edited 2007-09-27 14:29
    Graham,

    I am only slightly confused by the encoding... the hardware is unknown territory. I need to google some more[noparse]:)[/noparse]

    Rich
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-09-27 15:16
    try usdigital, they do cheap encoders
  • rjo_rjo_ Posts: 1,825
    edited 2007-09-27 17:53
    will do, thanks.
  • MumfyMumfy Posts: 4
    edited 2007-09-27 23:24
    I use encoders all the time at the Science Museum. Exhibit developers have a nasty habit of using carbon pots as interfaces for interactive exhibits...
    After a couple of thousand school kids the pots get all scratchy and useless.

    Quadrature encoders last many times longer and are mechanically compatible with pots also if you get the right kind a lot less torque is required to spin.
    Making the signal useful is the interesting part.

    Generally I use a jk flipflop (usually a 4013) to give a direction signal and clean up the clock then, I either pop on a digital pot (ad5330 or similar), or
    use a micro controller with a hall effect sensor to set a centre point. From there some form of DAC.

    ~mumfy
Sign In or Register to comment.