Simulation

A simulation in CoppeliaSim 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]

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 loop

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

[Main simulation loop]


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

[Real-time simulation loop]


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

void initializationCallback
{
// do some initialization here } void loopCallback
{
if ( (simGetSimulationState()&sim_simulation_advancing)!=0 )
{
if ( (simGetRealTimeSimulation()!=1)||(simIsRealTimeSimulationStepNeeded()==1) )
{
if ((simHandleMainScript()&sim_script_main_script_not_called)==0)
simAdvanceSimulationByOneStep();
}
}
} void deinitializationCallback
{
// do some clean-up here }

Depending on the simulation complexity, performance of the computer and simulation settings, real-time simulation might not always be possible.


Simulation speed

In non real-time simulations, the simulation speed (i.e. the perceived speed) is mainly dependent on two factors: the simulation time step and the number of simulation passes for one rendering pass (see the simulation dialog for more details). 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 (a too small simulation time step might not be compatible with the real-time character of a simulation because of the limited calculation power of the computer). During simulation, the simulation speed can be adjusted with following toolbar buttons:

[Simulation speed adjustment toolbar buttons]

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 speed adjustment mechanism for real-time simulations]

By default, each simulation cycle is composed by following sequential operations:

  • Executing the main script
  • Rendering the scene