Can you share with us the relevant parts of your "simulation loop"?

For example (I'm using Chrono::Vehicle mostly) a lot of the vehicle related demos have a simulation loop that goes something like this:

// Simulation loop vehicle.EnableRealtime(true);
while (vis->Run()) {
    // Render scene vis->BeginScene();
    vis->Render();
    vis->EndScene();

    // Get driver inputs DriverInputs driver_inputs =driver->GetInputs();

    // Update modules (process inputs from other modules) double time 
=vehicle.GetSystem()->GetChTime();
    driver->Synchronize(time);
    vehicle.Synchronize(time,driver_inputs,terrain);
    if (add_trailer)
        trailer->Synchronize(time,driver_inputs,terrain);
    terrain.Synchronize(time);
    vis->Synchronize(time,driver_inputs);

    // Advance simulation for one timestep for all modules 
driver->Advance(step_size);
    vehicle.Advance(step_size);
    if (add_trailer)
        trailer->Advance(step_size);
    terrain.Advance(step_size);
    vis->Advance(step_size);
}

(taken from demo_VEH_WheeledJSON.cpp)

So you can see it has a flag to determine if it should pause at the end of each step to stay in realtime (assuming it finished early). It could be you're missing that flag. It could also be your loop is altogether slightly different and you need to add some form of sleep at the end of your loop manually. I have a few loops where I've done this "manually" as I wanted to have the option not just to sleep at the end of each step, but, if the simulation ran behind for a short while, to also "catch up" again. Anyway, such logic is not that hard to write yourself if you want something that suits your specific scenario.

Greetings, Marcel


On 13-Mar-23 15:14, Alexandre Vinovrski wrote:
I noticed that the simulation runs at different speeds on different machines. This is normal because it depends on the CPU frequency and on the operating system scheduling. For example if I run the simulation on my workstation it will will look slower than if I run it on my laptop where it looks significantly faster. I need a way of making sure that my simulation will run at the same speed no matter the machine.


Le lundi 13 mars 2023 à 13:57:50 UTC+1, [email protected] a écrit :

    I think you need to explain more context about what you are trying
    to do. From your original question it was not clear to me at all that:

      * You are running a simulation on multiple machines.
      * You are running that simulation in real-time (as far as I can
        interpret from your mails).
      * You want to synchronize time on multiple machines?

    Greetings, Marcel


    On 13-Mar-23 13:40, Alexandre Vinovrski wrote:

    To me it seems that the time is managed in a very poor and in an
    inadequate way in chrono. I basically need to change it at its
    source in order to achieve what I want. I would need a way to
    make the simulation run at the same frequency on all machines.
    This is normally achieved with deltaTime 'normalization'. I tried
    to do that but it doesn't work. I'm using ChFunction which, from
    looking at the source code, appears to use a hardcoded step. This
    might be the issue why my delta time calculations do not work. At
    the moment my simulation runs at different speeds on different
    machines.
    Le dimanche 12 mars 2023 à 16:03:08 UTC+1, [email protected]
    a écrit :

        Hi Alexandre,

        There are a couple of ways you can get the time:

          * system->GetChTime();
          * if your simulation runs with a fixed timestep, you can
            easily count steps in your physics loop;

        I hope that answers your question.

        Greetings, Marcel


        On 12-Mar-23 15:42, Alexandre Vinovrski wrote:
        Hello to all,
        We are a team of students working on a project for our
        university. We have to implement a genetic algorithm that
        allows an individual to walk in a physical engine.
        One of the conditions necessary for our algorithm to stop is
        the evaluation of the distance travelled based on the delta
        time. We have the impression that this essential
        functionality for our project is missing in Chrono.
        Do you know if this is available, or if there is a
        replacement for this method?
-- You received this message because you are subscribed to the
        Google Groups "ProjectChrono" group.
        To unsubscribe from this group and stop receiving emails
        from it, send an email to [email protected].
        To view this discussion on the web visit
        
https://groups.google.com/d/msgid/projectchrono/09555871-ff73-4848-b37a-2072500e85aan%40googlegroups.com
        
<https://groups.google.com/d/msgid/projectchrono/09555871-ff73-4848-b37a-2072500e85aan%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- You received this message because you are subscribed to the
    Google Groups "ProjectChrono" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to [email protected].
    To view this discussion on the web visit
    
https://groups.google.com/d/msgid/projectchrono/803bad59-c8a4-44c5-9e48-ff70feaa878cn%40googlegroups.com
    
<https://groups.google.com/d/msgid/projectchrono/803bad59-c8a4-44c5-9e48-ff70feaa878cn%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/4a574511-734b-43b6-acd4-f96103885806n%40googlegroups.com <https://groups.google.com/d/msgid/projectchrono/4a574511-734b-43b6-acd4-f96103885806n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups 
"ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/projectchrono/ab63614d-d6ca-af4d-9d64-cd103f9f19f4%40gmail.com.

Reply via email to