Shop OBEX P1 Docs P2 Docs Learn Events
Rudementary PID — Parallax Forums

Rudementary PID

mountaineermountaineer Posts: 27
edited 2006-04-11 11:20 in BASIC Stamp
I'm working on a robot and would like to create a PID loop that will control the drive motors. The motor controller I'm using has 7bits of resolution(0-127) plus negative, meaning signed byte. Anyhoo, I don't think I have the processing power(BS2 OEM) nor the time(I'm trying to keep the program lean), so I'm planning to only do the Proportional part of the loop. Should I invest the processing power to add either the I or D parts? In other words how much would they help? I have a separate microcontroller handling the encoder counting and timing loop, so I plan to have the actual velocity in the same terms as the intended velocity. What is the math(code?) that I would need to implement this? I think it is just this:

Vcurrent = Vcurrent + Vdesired - Vactual



Second portion of the question:
Since the current value is just a byte and basic stamp math is done in word size, I need to limit the result of the equation above to (-128, 127). Is there some way of doing this with a native command or do I just need to put it in IF statements?

Thanks In Advance, mountainieer2000

Comments

  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-04-08 17:37
    You should certainly start out with only the proportional part and get it working. If at the end you find that the robot overshoots the intended value, or if it oscillates drunkenly, or if the response is too slow, then by all means look to adding I and D terms. People who are more familiar with robot dynamics may know offhand or point you to references.

    I'm not clear on what "Vactual" is in comparison to "Vcurrent" in your formula. Error = Vcurrent - Vdesired? or Error = Vactual - Vdesired?

    If there is a chance of values <-128 or >127, you will probably want to clamp them at -128 and at 127. The MIN and MAX operators work with only positive numbers. The easiest way to deal with that is to offset the computation. Suppose controlVariable comes in at some value that can range +/- 200, and you want to clamp it at +/- 127.

    controlVariable = controlVariable + 10000 MAX 10127 MIN 9873 - 10000

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 4/8/2006 6:04:18 PM GMT
  • edited 2006-04-11 00:12
    PID isn't all that hard to implement with the BASIC Stamp.· Here is a link to a tutorial:

    http://forums.parallax.com/showthread.php?p=529609

    Post Edited (Andy Lindsay (Parallax)) : 4/11/2006 12:17:41 AM GMT
  • BeanBean Posts: 8,129
    edited 2006-04-11 11:20
    From my experience "PI" controllers seem to be more common than "PD" controllers.
    As Tracy said, I would get the "P" term working first, then add the "I" term, then the "D" term (if needed).
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module"·available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module"·available from Parallax for only·$49.95 http://www.parallax.com/detail.asp?product_id=30015
    Product web site: www.sxvm.com

    Available now! Cheap 4-digit LED display with driver IC·www.hc4led.com

    "I reject your reality, and substitute my own." Mythbusters
    ·
Sign In or Register to comment.