GithubHelp home page GithubHelp logo

Comments (6)

korken89 avatar korken89 commented on June 2, 2024

Hi, thanks for reporting.

This does not look like a bug to me. RTIC simply requires some operations to be supported on Monotonic::Instant and Monotonic::Duration for it to be valid.
In this case you are using fugit as the underlying time library, whose Instant represents a wrap-able time.
So any Instant is valid MAX/2 - 1 ticks around it. This means that your example is correct behavior, as the the new instant is within the correct span for a valid instant:

fugit::Instant::<u32, 1, 1000>::from_ticks(0xffff_ffff) + fugit::Duration::<u32, 1, 1000>::from_ticks(10)
Instant { ticks: 9 } // Correct

On the old book chapter you found, this is not valid anymore.
It was for RTIC 0.5 and the Monotonic trait replaces the old method.

Is there anything else you'd like to ask or that I should clarify?

from rtic.

Dridus avatar Dridus commented on June 2, 2024

to clarify, it's correct behavior that tasks might be executed either immediately (if now + delay wraps) or at the intended delay ± jitter, not delay ± jitter?

from rtic.

korken89 avatar korken89 commented on June 2, 2024

Sort of, it does not depend on wrapping - just if the instant is in the future or in the past.
So if an instant is in the past the task will be executed immediately, else it will be scheduled.
With fugit this means that you can represent time that is MAX/2 - 1 ticks into the future or the past compared to a specific Instant.
The library does the needed math to make this happen.

from rtic.

perlindgren avatar perlindgren commented on June 2, 2024

In principle jitter cannot be negative (besides the jitter of the HW timer). There is also a difference between a task being "released" (ready to run), and the actual execution. This may cause accumulated drift if using "now" as the timebase.

from rtic.

Dridus avatar Dridus commented on June 2, 2024

Sort of, it does not depend on wrapping - just if the instant is in the future or in the past. So if an instant is in the past the task will be executed immediately, else it will be scheduled. With fugit this means that you can represent time that is MAX/2 - 1 ticks into the future or the past compared to a specific Instant. The library does the needed math to make this happen.

But you can't represent a time up to MAX/2-1 ticks into the future relative to any specific Instant though correct? Only relative to Instant 0, otherwise it's ambiguous whether it was intended to be in the past. I think it's surprising that spawn_after / reschedule_after might end up being basically the same as spawn, depending on the current value of the clock and what duration, since the addition with wrapping is hidden in the implementation of spawn_after / reschedule_after.

In principle jitter cannot be negative (besides the jitter of the HW timer). There is also a difference between a task being "released" (ready to run), and the actual execution. This may cause accumulated drift if using "now" as the timebase.

Ah yes good clarifications, I wasn't accurate.


Overall the behavior makes sense once one knows of all the details and limitations. I do think it'd be nice to be less surprising, either by documentation or better yet some indication from the API that wrapping/as-soon-as-possible execution might occur rather than duration + jitter.

As it stands it also makes for potentially complicated calling code if one really does need the proper wait. I can't judge whether it's important often enough to justify updating the implementation to support it automatically though.

from rtic.

perlindgren avatar perlindgren commented on June 2, 2024

By extending the Monotonic timer to a u64 store, duration will be large enough for (all) practical use cases, and solves the original issue. Please re-open this issue if further clarifications are needed.

from rtic.

Related Issues (20)

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.