Is integration over not constant dt (∆time) a possible thing? Let's say you have a PID loop with differentiating frequency, can the integral part of it still work? (Assuming you know the dt from the last iteration)

Could I just use a variable dt (∆time) in my calculation and the PID principle would still function correctly?

  • $\begingroup$ Are we talking about minor adjustments or large variations in sampling? As long as your sample frequency is high enough it doesn't really matter but it's easy to convince yourself that if there's a step function in the error and you delay the next sample by a large amount your controller will not respond the same way. $\endgroup$ – Guy Sirton Jul 28 '14 at 3:45
  • $\begingroup$ The dt is changing just about a couple milliseconds plus minus, I guess that is not a large change. $\endgroup$ – Dan Barzilay Jul 28 '14 at 11:04

Short answer: yes, as long as you adjust for the real dt you are fine

Longer answer: In reality, we are always using discrete time approximations of continuous time concepts of derivative and integral. So a varying dt just means the accuracy of your approximation is varying over time, but that's ok. Examples of situations where you might run into problems are:

  • You are on the edge of stability and some of the slower timesteps are too slow
  • You dt doesn't change randomly and happens to interact with important system frequencies
  • $\begingroup$ Could you please explain further your second situation where I might run into a problem? How can that cause problems? $\endgroup$ – Dan Barzilay Jul 27 '14 at 20:02
  • 1
    $\begingroup$ It's pretty much just a theoretical situation. Have you ever seen videos of the Tacoma Narrows bridge? The same thing can happen to controllers, but you have to be really unlucky for dt variation to be the cause. In any hobby controller, and most industry systems, periodic variation in dt is so far down the list of concerns it never gets checked. $\endgroup$ – ryan0270 Jul 28 '14 at 2:40

Normally, it would best to fix sampling time via hardware timer interrupt.

In case this cannot be done (like using software-only looping), it will work as long as you calculate,

normalized_error = (latest_reading - set_point) / (latest_time_stamp - previous_time_stamp)

  • $\begingroup$ Could you please explain why is it best to keep a fixed dt (time sampling) and provide the negative consequences of using a variable one? $\endgroup$ – Dan Barzilay Jul 27 '14 at 20:04
  • $\begingroup$ For 'professional' (real commercial product) hard real-time control systems, normally, the processor/MCU has hardware timer to produce periodic time tick interrupt in which it will be easily program to append PID sampling task to the system time tick task. Fixed sampling make the system more predictable and have best/precise/accurate fine-tuning results. $\endgroup$ – EEd Jul 27 '14 at 21:00
  • $\begingroup$ Do not worry too much if cannot do the above. 'Normalized' will still work, to a large extend. $\endgroup$ – EEd Jul 27 '14 at 21:08

Indeed I d also go for an interrupt method. As this method allows you to execute code, do something etc.. on a very arbitrary base. Which I think youll ,due to the non constant dt

  • $\begingroup$ Welcome to Robotics, Jacques. As it stands, your response doesn't add to the Q&A - could you extend your answer? $\endgroup$ – Andrew Aug 6 '14 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.