Giter Site home page Giter Site logo

Time component for outputRampRate about minipid HOT 2 OPEN

zhivko avatar zhivko commented on August 30, 2024
Time component for outputRampRate

from minipid.

Comments (2)

tekdemo avatar tekdemo commented on August 30, 2024

I don't think the CPU speed is super important. When running a PID, the important detail isn't raw speed, but consistency. Running at shorter delays has some utility in certain cases, but most systems don't care if they're driven at 4ms, 40ms, or sometimes even 4s. However PIDs are not tolerant of big swings in execution time on the same system (known as jitter).

For Arduino code, an optimal method is that seen in the BlinkWithoutDelay example sketch. This lets you call the PID functions at set intervals, regardless of CPU speed. Once called at a fixed interval, a given CPU will complete the PID operations in the same amount of time, achieving consistency.

If you're not calling it at constant time intervals, a lot of nasty variables sneak in and cause problems. This applies not just to outpurRampRate, but also the I and D terms. If you're using a delay(millis) method of time keeping, you'll see this a lot, as the Arduino framework does not inherently operate on strict timing. Not only will most general code have inconsistent run time, the Arduino framework will do background stuff at random times, making loop cycles inconsistently timed.

Later this year I do plan on adding improved time handling in the math. I've discovered that in one of my main use cases, there's enough jitter in the timekeeping framework that I'm getting really nasty values of 2-3x my expected loop time, and it's causing problems.

I won't be adding any Arduino dependencies though. While I personally use this library for Arduino projects, I feel it's more valuable to keep it dependency free for use in other systems (especially since I maintain a twin version in Java). So, the time component will be implemented such that you provide 2 parameters, which is all that's needed to handle this:

  • The expected time loop (or 1 for a non-time dependent system)
  • The current time or time delta from the last update (or, default to 1 if you don't use time).

The hard part is doing it without a bunch of floating point division, which is ridiculously slow and nondeterministic on systems without hard floating point cores (eg, arduino). As a PID needs to be fast and deterministic, I've strenuously avoided this operation in the main loop. I also would like to leave it operating without a strict time dependence, as much of the time the systems I work don't require this level of precision, and it would just muck up the code.

from minipid.

zhivko avatar zhivko commented on August 30, 2024

I am using esp32 arduino (esp32 itself having 32bit floating point unit ) and I can call it via rtos task that is causing fairly precise timing.

from minipid.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.