Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 26

V-Rep. Presentation no.

13

SIMULATION
Simulation
A simulation in V-REP can be started, paused and
stopped with [Menu bar --> Simulation -->
Start/Pause/Stop simulation] or through the related
toolbar buttons:

[Simulation start/pause/stop toolbar buttons]


Simulation |

Internally, the simulator will use additional intermediate states in order to correctly inform
scripts or programs about what will happen next. Following state diagram illustrates the
simulator's internal states:

[Simulation state diagram]


Simulation |

Scripts and programs should alwaysreact according to the current


system call function and possibly the simulation state in order to
behave correctly. It is good practice to divide each control code
into at least 4 system call functions (e.g. for non-threaded child
scripts):
Simulation |

• Initialization function: sysCall_init: the function is called only when the


script is initialized.
• Actuation function: sysCall_actuation: the function is called when
actuation should happen.
• Sensing function: sysCall_sensing: this function is called when sensing
should happen.
• Clean-up function: sysCall_cleanup: the function is called just before the
script is de-initialized (e.g. at simulation end, or when the script is
destroyed).
Simulation |

Simulation loop
The simulator operates by advancing the simulation time at constant time
steps. Following figure illustrates the main simulation loop:

[Main simulation loop]


Simulation |Simulation loop

Real-time simulation is supported by trying to keep the simulation time synchronized with the real
time:

[Real-time simulation loop]


Simulation |Simulation loop

Following represents a very simplified main client application (messaging, plugin handling and other
details have been omitted for clarity purpose):
Simulation |

Simulation speed
In the case of a real-time simulation, the simulation speed mainly depends
on the real-time multiplication coefficient, but also to a certain degree of the
simulation time step. During simulation, the simulation speed can be
adjusted with following toolbar buttons:

[Simulation speed adjustment mechanism for non real-time simulations]


Simulation |Simulation speed

The simulation speed is adjusted in a way so that the initial simulation time step is never increased
(because this might have as consequence the breaking of a mechanism for example). Following two
figures illustrate the simulation speed adjustment mechanisms:

[Simulation speed adjustment mechanism for non real-time simulations]


Simulation |Simulation speed

The simulation speed is adjusted in a way so that the initial simulation time step is never increased
(because this might have as consequence the breaking of a mechanism for example). Following two
figures illustrate the simulation speed adjustment mechanisms:

[Simulation speed adjustment mechanism for non real-time simulations]


Simulation |Simulation speed

[Simulation speed adjustment mechanism for real-time simulations]


Simulation |

Threaded rendering
The rendering operation will always increase the simulation cycle duration,
thus also slowing down simulation speed. For those situations, a threaded
rendering mode can be activated via the user settings, or via the following
toolbar button:

[Threaded rendering toolbar button]


Simulation |Threaded rendering

When the threaded rendering mode is activated, a simulation cycle will only
consist in execution of the main script, thus simulations will run at maximum
speed. Rendering will happen via a different thread, and not slow down the
simulation task. The drawbacks have however to be considered. When
threaded rendering is activated, then:
Simulation |Threaded rendering

• Rendering will happen asynchronously to the simulation loop, and visual


glitches might appear
• The video recorder will not operate at constant speed (some frames might
get skipped)
• The stability of the application might be reduced
• Some operations (e.g. erasing an object, etc.) require to wait for the
rendering thread to finish work, before being able to execute, and vice-
versa. In those situations, cycles could take more time than in the sequential
rendering mode.
Simulation |

Simulation dialog
The simulation dialog can be accessed with [Menu bar --> Simulation -->
Simulation settings] or by clicking following toolbar button:

[Simulation toolbar button]


Simulation |Simulation dialog

[Simulation settings dialog]


Simulation |Simulation dialog

• Time step: the simulation time step. Each time the main script was
executed, the simulation time is incremented by the simulation time step.
Using large time steps results in fast but inaccurate/unstable simulations.
Small time steps on the other hand will (generally) lead to more precise
simulations, but will take more time. It is highly recommended to keep a
default time step.
Simulation |Simulation dialog

• Simulation passes per frame (ppf): the number of simulation passes for
one rendering pass. A value of 10 would mean that the main script is
executed 10 times (10 simulation steps) before the screen is refreshed. If
you have a slow graphic card, you can choose to display only one frame
out of two for instance.
Simulation |Simulation dialog

• Pause when simulation time higher than: allows specifying a simulation


time at which the simulation will be paused (e.g. to be able to analyze
some results at a specific simulation time).

• Pause on script error: if enabled, then a simulation will be paused when a


script error occurs.
Simulation |Simulation dialog

• Full screen at simulation start: if enabled, then simulation starts in full


screen mode. Be aware that in full screen mode, dialogs and messages
won't appear or won't be visible, and only the left mouse button will be
active. For that reason that mode is only recommended once a scene is
properly configured and final.
• Full screen mode can be left with the esc-key, and toggled via the
boolean parameter sim_booparam_fullscreen during simulation.
Simulation |Simulation dialog

• Real-time simulation, multiplication factor: if selected,


then the simulation time will try to follow the real-time.
A multiplication factor of X would try to run a simulation
X times faster than real-time.
Simulation |Simulation dialog

• Try catching up when behind: during real-time simulation, it can


happen that the simulation time is not able to follow the real-
time (e.g. because of some momentarily heavy calculations). In
that case, if this check-box is selected, then the simulation time
will try catching up the lost time (e.g. when the calculation load is
again reduced), which results in an apparent speed-up.
Simulation |Simulation dialog

• Reset scene to initial state: when selected, then all objects will
be reset to their initial state: this includes the object local
position, local orientation and its parent, joint and path intrinsic
positions, floating view positions and sizes, etc. This means that
the next simulation run will execute in a same way as previous
one, unless heavy changes were undertaken (shape scaling,
object removal, etc.).

• Some minor settings are ignored by this item.


Simulation |Simulation dialog

• Remove new objects: when selected, then scene objects added


during a simulation run will be removed at the end of the
simulation

You might also like