Simulation scripts

A simulation script executes code handling a particular function in a simulation. Double-clicking the script icon opens the script editor.

Simulation scripts should exclusively be used to handle simulation-time tasks, since they only run when simulation is running. Their entrance functions are callback functions. Functions that are not running threaded should not be blocking. This means that every time they are called, they should perform some task and then return control. If control is not returned, then the whole simulation halts. Simulation script functions are called at least twice per simulation step from the main script's actuation and sensing functions. The system will also call other system callback functions where appropriate (e.g. during script initialization, clean-up, etc).

Simulation scripts follow a precise calling or execution order and are typically segmented into system callback functions, the most important ones are:

  • sysCall_init. This function is executed just one time, the first time the script is called. Usually you would put some initialization code in this part.
  • sysCall_thread. This function is the entrance to the script's threaded execution code. Threaded code is interrupted (and later resumed) on a regular basis by CoppeliaSim, by default. This behaviour can however be adjusted via sim.setStepping. See also the other thread-related API functions for more details.
  • sysCall_actuation. This function is executed in each simulation step, during the actuation phase of a simulation step. Refer to the main script default code for more details about the actuation phase, but typically, you would do some actuation in this part (no sensing).
  • sysCall_sensing. This function is executed in each simulation step, during the sensing phase of a simulation step. Refer to the main script default code for more details about the sensing phase, but typically, you would only do sensing in this part (no actuation).
  • sysCall_cleanup. This function is executed one time just before the script state is destroyed (e.g. when simulation ends, or when the script is removed).