Saturday, 21 November 2015

Customization scripts




Double-clicking the script icon allows opening the script editor. You can change properties of a given script, or associate it with another object via the script dialog. You can attach a new customization script to an object by selecting the object, then navigating to [menu bar --> Add --> Associated customization script].
Following are customization script's main properties:
  • they run non-threaded.
  • they are executed all the time: when simulation is running, as well as when simulation is not running.
  • they are attached to (or associated with) scene objects (i.e. they are associated scripts). Associated scripts form the basis of V-REP's distributed control architecture, and share the convenient property to be automatically duplicated if their associated object is duplicated.
  • Above properties allow customization scripts to share some of the best features of add-ons and child scripts. Customization scripts allow the creation of customizable models for instance: imagine a model that was dropped into a scene, and that is able to configure or adapt itself, even when simulation is not running. This could be a robot where the user can adjust the various link lengths with a single slider repositioning.
    Customization scripts are pass-through scripts. 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 simulator will hang. Customization scripts operate as functions, and are called by the simulator very often, so as to be able to react to various simulator state changes.
    A customization script should be segmented in several parts, as following skeleton script illustrates:
    if (sim_call_type==sim_customizationscriptcall_initialization) then
     -- this is called just after this script was created (or reinitialized)
     -- Do some initialization here
     
     -- By default we disable customization script execution during simulation, in order
     -- to run simulations faster:
     simSetScriptAttribute(sim_handle_self,
            sim_customizationscriptattribute_activeduringsimulation,false)
    end
    
    if (sim_call_type==sim_customizationscriptcall_nonsimulation) then
     -- This is called on a regular basis when simulation is not running.
     -- This is where you would typically write the main code of
     -- a customization script
    end
    
    if (sim_call_type==sim_customizationscriptcall_lastbeforesimulation) then
     -- This is called just before a simulation starts
    end
    
    if (sim_call_type==sim_customizationscriptcall_simulationactuation) then
     -- This is called by default from the main script, in the "actuation" phase.
     -- but only if you have previously not disabled this script to be active during
     -- simulation (see the script's initialization code above)
    end
    
    if (sim_call_type==sim_customizationscriptcall_simulationsensing) then
     -- This is called by default from the main script, in the "sensing" phase,
     -- but only if you have previously not disabled this script to be active during
     -- simulation (see the script's initialization code above)
    end
    
    if (sim_call_type==sim_customizationscriptcall_simulationpausefirst) then
     -- This is called just after entering simulation pause
    end
    
    if (sim_call_type==sim_customizationscriptcall_simulationpause) then
     -- This is called on a regular basis when simulation is paused
    end
    
    if (sim_call_type==sim_customizationscriptcall_simulationpauselast) then
     -- This is called just before leaving simulation pause
    end
    
    if (sim_call_type==sim_customizationscriptcall_firstaftersimulation) then
     -- This is called just after a simulation ended
    end
    
    if (sim_call_type==sim_customizationscriptcall_cleanup) then
     -- this is called just before this script gets destroyed (or reinitialized) 
     -- Do some clean-up here
    end

    1 comment: