Distance evaluation based on delta time : Is delta time missing in Chrono ?

94 views
Skip to first unread message

Alexandre Vinovrski

unread,
Mar 12, 2023, 10:42:32 AM3/12/23
to ProjectChrono
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?

Marcel Offermans

unread,
Mar 12, 2023, 11:03:08 AM3/12/23
to projec...@googlegroups.com

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

--
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 projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/09555871-ff73-4848-b37a-2072500e85aan%40googlegroups.com.
Message has been deleted

Alexandre Vinovrski

unread,
Mar 12, 2023, 11:36:06 AM3/12/23
to ProjectChrono
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.

Alexandre Vinovrski

unread,
Mar 13, 2023, 8:40:03 AM3/13/23
to ProjectChrono

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, marcel.o...@gmail.com a écrit :

Marcel Offermans

unread,
Mar 13, 2023, 8:57:50 AM3/13/23
to projec...@googlegroups.com

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

Alexandre Vinovrski

unread,
Mar 13, 2023, 10:14:36 AM3/13/23
to ProjectChrono
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.

Marcel Offermans

unread,
Mar 13, 2023, 10:34:49 AM3/13/23
to projec...@googlegroups.com

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

Marcel Offermans

unread,
Mar 13, 2023, 10:35:29 AM3/13/23
to projec...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages