"Simulation step" and "Simulation time"

Typically: "How do I... ", "How can I... " questions
Post Reply
martin
Posts: 44
Joined: 15 Mar 2016, 10:38

"Simulation step" and "Simulation time"

Post by martin »

Hello Coppelia,

I need your help to clarify some concepts regarding the operation of the simulator and to write properly a child script. My doubts come around the topics of "simulation step" and the "simulation dt". My following comments are based on simulation default values.

As far as I know, on the one hand, the simulator performs a "simulation step" each 5ms, and for example, functions inside child scripts, such as "sysCall_actuation" are executed each 5ms.

On the other hand, by default the "simulation dt" last 50ms, and it is the predefined timestep for running simulations in synchronous mode. That is, using a Remote API, such as Python, whatever value that I would like to change in a joint, can be updated each 50ms. That is, each "simulation dt" involves 10 simulation steps.

Then, supposing that all the previous is correct, I am trying to optimize a for loop in a Python Remote API file, which performs actuation in the simulation many times (several "simulation dt") and I would like to move these instructions to a Lua child script to optimize execution time of my experiment, passing only once the values that have to be updated each 50ms.

Pseudo example of the for loop:

Code: Select all

	Some values of the "final_angle" list that are updated after each "simulation dt"	
	for n in range (0, 100):
		sim.setJointTargetPosition(handler.jd1a, final_angle[0])
        	sim.setJointTargetPosition(handler.jd1l, final_angle[1])
        	sim.setJointTargetPosition(handler.jd3a, final_angle[2])
        	sim.setJointTargetPosition(handler.jd3l, final_angle[3])
        	sim.setJointTargetPosition(handler.ji1a, final_angle[4])
        	sim.setJointTargetPosition(handler.ji1l, final_angle[5])
        	sim.setJointTargetPosition(handler.ji3a, final_angle[6])
        	sim.setJointTargetPosition(handler.ji3l, final_angle[7])
        	client.step()
        	
Thus, my question is:

- How can I make a parameter update each 50ms using a child script with a single call to a script function with all the information needed to update the values of the parameters several time steps?

Regards!

fferri
Posts: 1231
Joined: 09 Sep 2013, 19:28

Re: "Simulation step" and "Simulation time"

Post by fferri »

martin wrote: 10 Apr 2023, 15:37 As far as I know, on the one hand, the simulator performs a "simulation step" each 5ms, and for example, functions inside child scripts, such as "sysCall_actuation" are executed each 5ms.

On the other hand, by default the "simulation dt" last 50ms, and it is the predefined timestep for running simulations in synchronous mode. That is, using a Remote API, such as Python, whatever value that I would like to change in a joint, can be updated each 50ms. That is, each "simulation dt" involves 10 simulation steps.
Your premise is wrong.


From Simulation dialog:
Image
  • Simulation dt: the simulation time step. Each time the main script is executed, the simulation time is incremented by the simulation dt. It is highly recommended to keep a default simulation dt of 50ms. Keep in mind that the simulation dt cannot be smaller than the dynamics dt (see below).
  • Dynamics dt: the time step used by the physics engine. Using large time steps results in faster but less accurate simulations. Small time steps on the other hand will lead to more precise simulations, but will take more time. It is highly recommended to keep a default dynamics dt of 5ms. Combined with a default simulation dt of 50ms, this results in 10 dynamics calculation steps per simulation pass.
Thus sysCall_actuation (which is called from the main script) is also executed every 50ms, not every 5ms.

martin
Posts: 44
Joined: 15 Mar 2016, 10:38

Re: "Simulation step" and "Simulation time"

Post by martin »

Ok, thanks for the clarification!

jumppy
Posts: 3
Joined: 31 May 2016, 01:41

Re: "Simulation step" and "Simulation time"

Post by jumppy »

Does this mean that my control loop is also 50ms as recommended? I am asking because I have a manipulator that is controlled at 1ms, I am not sure if the simulation will behave exactly like the real controller with such a larger deviation in control cycle time.

coppelia
Site Admin
Posts: 10376
Joined: 14 Dec 2012, 00:25

Re: "Simulation step" and "Simulation time"

Post by coppelia »

You can adjust the simulation step and the dynamics step individually, according to your needs. By default the simulation step is 50ms, and the dynamics step is 5ms.

If you need to control a dynamic aspect of a simulation in each dynamics step, then you should do that inside of a joint callback function or inside of the dynamics callback.
All other system callback functions that run on a regular basis are called no more than once per simulation step.

of course, you could set the simulation step to be the same as the dynamics step, but then all scripts will run more frequently (by defaut 10x) and slow things down a lot.

Cheers

Post Reply