metaform3d

11-09-2008, 02:36 AM

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.

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.