Results 1 to 8 of 8

Thread: PID Questions

  1. #1
    Join Date
    Apr 2008
    Location
    Sunnyvale, CA
    Posts
    378
    Images
    34
    Rep Power
    53

    PID Questions

    I'm struggling with writing my own software to control what are essentially servos. I have motors with an ESC for each one and a pot to register position. What I need is an algorithm to control the motor speed based on the difference between the current pot output and the goal. The standard solution to this problem -- a PID controller -- is a bit of a confused mess that I can't figure out.

    I've implemented the "P" part -- Proportional. If there's a big difference in angle (pot minus goal) we move fast, otherwise slow, but always in the direction of the goal. The problem with this is that there is either overshoot or, if sensitivity is tuned low which is what I want, there's a big jerk when it comes to a stop. The other terms I can't figure out.

    "Integral" -- how is that computed? Coming from a mathematical background I know that if the angle difference is zero from the start of time until now, the integral can be defined as zero. Fine. Now we set a new goal and the difference is non-zero. We respond and perhaps reach a new equilibrium where the angle difference is zero again. In any case the integral is non-zero forever from now until the end of time because of that short non-zero period. And yet that's a linear component to the control equation. How does that work?

    And derivative is not much better, at least in practical terms. What is the method to measure derivative given discrete samples? Say I read out the pot at 237 and then 10 milliseconds later the pot is still 237 -- does that mean that the derivative term is zero for that round? Then 10ms later the value is 238. Is that treated as a rate of 1/10ms or 1/20ms?

    For those who made it this far my question is: what is the practical method for damping the integral and smoothing the derivative in a PID controller?

    If someone can explain that then we'll talk about tuning the parameters.

  2. #2
    Join Date
    May 2008
    Location
    TN
    Posts
    853
    Images
    99
    Rep Power
    71

    Re: PID Questions

    I ran across a link where a guy was doing much the same thing. He lists his code and algorithms on the page:
    http://abigmagnet.blogspot.com/2008/...-part-one.html

    Found via Make:
    http://blog.makezine.com/archive/200...C-0D6B48984890

  3. #3
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    174

    Re: PID Questions

    That looks pretty simple. Seems too simple, but hey, I've been known to overthink these things a time or two. +Rep, Jes, Thanks for that link - bookmarked and stored away.
    I Void Warranties´┐Ż

  4. #4
    Join Date
    Apr 2008
    Location
    Sunnyvale, CA
    Posts
    378
    Images
    34
    Rep Power
    53

    Re: PID Questions

    Thanks for the links jes. The code there does answer the question of how people generally deal with sampling error and damping -- they don't. A controller with an integral term will always overshoot because of the need to "unwind" the integration. Actually Wescott did put an upper bound on the term in his code to reduce total possible saturation, but this reduces the effect without solving it. As for error in the differential, he mentions that it may be noisy due to uneven sampling, but doesn't really give any hints about how to mitigate that effect.

    I've been running some simulations and I really like the smooth response of an integrative controller. I've found that I can eliminate overshoot by using a differential term and by damping the integration input while the differential is non-zero. Well see how that works out in practice.

  5. #5
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    174

    Re: PID Questions

    I'm looking forward to seeing what you come up with, Meta. I haven't had occassion to give it much thought - it'd be awesome if you come up with a working algorithm and share it!
    I Void Warranties´┐Ż

  6. #6
    Join Date
    Apr 2008
    Location
    Sunnyvale, CA
    Posts
    378
    Images
    34
    Rep Power
    53

    Re: PID Questions

    So I've spent a week working on this problem and I'm now discouraged and frustrated. The theory is sound -- at least on the whiteboard. In numerical simulation it also works OK. For some reason the physical system doesn't respond the same way; no matter how I tune the constants I get overshoot or lag. Small differences in particular result in ever increasing oscillations that would be really bad if I didn't have software limits that shut the system down in that case.

    Any other references I need to be looking at? I'm thinking that perhaps I should calibrate my motors so that I can get an ideal linear response. The problem is that if the load changes -- perhaps just because the forearm is extended rather than withdrawn -- the response could change radically. It's hard to build a model that takes all the loads into account, and I was hoping not to.

  7. #7
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    125

    Re: PID Questions

    That is essentially the problem with PID, because of the inter-relatedness of the individual terms, tuning the system is nothing short of magic.

    I had meant to send this link before. http://barello.net/Papers/Motor%20Co...2020080621.pdf

    On page 4, he lays out a method for tuning:
    1. set all gains to 0
    2. increase Kp until oscillations occur, set final Kp to 2/3 of this value
    3. increase Kd until there is no overshoot and response is snappy
    4. increase Ki until to remove any residual error

    In theory it work, but of course, the terms are so inter-related, that such a system isn't guaranteed to function.

  8. #8
    Join Date
    Jul 2008
    Location
    South Sphincter Idaho
    Posts
    613
    Images
    104
    Rep Power
    65

    Re: PID Questions

    In the world of Instrumentation, loop tuning is in fact a "black art". After doing it for 30 or so years, I still learned something every time I had to tune a system. It never ceased to amaze me that 2 apparently identical systems could be very different to tune.

    There is software now that gets a person in the ball park, but it still takes the tech to do the magic.

    Here is the steps I would take for a basic loop.

    1: Set Proportional (Gain), Integral, and Derivative to 0.
    2: Set P first until you get oscillation, then back off by half. Then increase by half of what you backed off. If no Osc, increase by half of the remainder. If it oscillates, back off a tad. Eventually you arrive very close to the optimal setting.
    3: Now start with the Integral until it is just too fast acting to work, and you're back in the oscillatiion game. Do the half step thing again until it settles in. This may have an effect on the Proportional.
    4: Derivative... You may not need it. Don't mess with it unless really necessary as it adds another level of confusion.

    Not everyone will agree with my methods, as I learned the basics back in the era of pneumatics. They worked for me for a lot of years. The starting settings are arbitrary, but I wouldn't start with a really large setting.

    I like to look at a PID loop in the sense of "P" is how much correction you want to a given error. "I" How fast do you want it to react. "D" predicting the error.

    Proportional vs Gain... a matter of how you think about things. I personally always liked Proportional as it gives a number larger than 1 where gain is a decimal. They are reciprocals of one another.

    Hope this might help.
    Gary
    Team Maggot---Mechs. "Bheka" (retired), "Maggot Mk.3(A)"
    " Keep your stick on the ice ".... Red Green

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 24
    Last Post: 07-30-2008, 02:31 AM
  2. Phoenix Pre-Build Questions
    By SilverVenom in forum Humanoids, Walkers & Crawlers
    Replies: 29
    Last Post: 06-05-2008, 02:43 PM
  3. A few questions about the KHR-1HV
    By tom_chang79 in forum Humanoids, Walkers & Crawlers
    Replies: 5
    Last Post: 02-08-2008, 11:48 AM
  4. A few questions?!?
    By El Espada in forum Robotics General Discussion
    Replies: 12
    Last Post: 01-21-2008, 08:21 PM
  5. Scorpion Mini question(s)
    By xyzzy1126 in forum DYNAMIXEL & Robot Actuators
    Replies: 7
    Last Post: 02-21-2007, 03:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •