Giter Site home page Giter Site logo

`SimHooks.stepTiming()` hangs when called from a callback registered with `SimDeviceSim.registerValueChangedCallback()` if another `SimDeviceSim` has been created about allwpilib HOT 2 OPEN

brettle avatar brettle commented on September 7, 2024
`SimHooks.stepTiming()` hangs when called from a callback registered with `SimDeviceSim.registerValueChangedCallback()` if another `SimDeviceSim` has been created

from allwpilib.

Comments (2)

PeterJohnson avatar PeterJohnson commented on September 7, 2024

This is not surprising. I'm not sure why you are trying to map this through a SimDevice, but it's not really designed to interact with the low-level timing code like this.

What's important to realize about the simulation callbacks (including the SimDevice ones) is that they are called inline to whatever code made the change (they are not called from a separate thread).

StepTiming() does a lot of work that may be susceptible to deadlocks; in particular it will trigger notifiers as appropriate for the amount of stepped time. We've had a number of hard-to-isolate bugs in this code, so this may be a similar symptom that's simply more reproducible.

from allwpilib.

brettle avatar brettle commented on September 7, 2024

Thanks for the quick response! Regarding why we were trying to use a SimDevice like this, we are working with an external simulator via the ws_server extension and are trying to keep the external simulator's clocks and the robot's clock approximately in sync. Since the wpilib sim framework and the websockets extension already provides a way to communicate state between the robot and the simulator via a SimDevice, this seemed like a natural way to implement that functionality. Fwiw, we have worked around the issue by replacing the call to stepTiming() with something like:

                        Notifier pauser = new Notifier(() -> {
                            SimHooks.pauseTiming();
                        });
                        pauser.startSingle(secsBehind);
                        SimHooks.resumeTiming();

(We actually reuse a single Notifier instead of creating a new one during each callback.)

That doesn't hang, but it doesn't allow the robot code to be run faster than real time and running faster than real time can be useful for some automated testing.

Anyway, perhaps the reproducible test case will be useful in isolating the bugs you mentioned.

from allwpilib.

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.