Rudementary PID
mountaineer
Posts: 27
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
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
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
http://forums.parallax.com/showthread.php?p=529609
Post Edited (Andy Lindsay (Parallax)) : 4/11/2006 12:17:41 AM GMT
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
·