Explicit and non-explicit calls

Some objects, such as proximity sensors, normally require handling or calculations to be performed once per simulation step, to reflect a possible change in the scene. This handling can be done implicitly or explicitly, and those objects have a special setting related to that: an explicit handling flag. By default that flag is unchecked, which means that the object will be implicitly handled via the main script. Indeed the following main script code will be executed and handle said objects once per simulation step:

sim.handleProximitySensor(sim.handle_all_except_explicit)

Above code will perform proximity sensor computations, and any other script can then read the up-to-date calculation results with:

calculationResult = sim.readProximitySensor(sensorHandle)

Above code, unlike the previous, will not compute anything, but just read the calculation result. This is very convenient when calculation need to happen exactly once per simulation step and/or the calculation result is required by several scripts.

If however, an object requires less or more frequent calculations (e.g. several calculations within a same simulation step), then above mechanism does not work. In that case, the object should be flagged as explicit handling: from that moment on, the main script will not handle that object anymore, and it is the responsibility of another script to do this. For instance if the proximity sensor should only be handled once every other simulation step, a child script could include following code:

#python def sysCall_init(): sim = require('sim') self.sensorHandle = sim.getObject('/myProximitySensor') self.handleSensor = False def sysCall_sensing(): self.handleSensor = not self.handleSensor if self.handleSensor: sim.handleProximitySensor(self.sensorHandle) --lua function sysCall_init() sim = require('sim') sensorHandle = sim.getObject('/myProximitySensor') end function sysCall_sensing() handleSensor = not handleSensor if handleSensor then sim.handleProximitySensor(sensorHandle) end end

If new calculations need to be performed several times within a same simulation step (e.g. because an object or the sensor itself is moved more frequently), one could write:

#python def sysCall_init(): sim = require('sim') self.sensorHandle = sim.getObject('/myProximitySensor') def sysCall_sensing(): for i in range(1, 11): pos = sim.getObjectPosition(self.sensorHandle) pos[2] = i / 10.0 sim.setObjectPosition(self.sensorHandle, pos) calculationResults = sim.handleProximitySensor(self.sensorHandle) --lua function sysCall_init() sim = require('sim') sensorHandle = sim.getObject('/myProximitySensor') end function sysCall_sensing() for i = 1, 10, 1 do local pos = sim.getObjectPosition(sensorHandle) pos[3] = i / 10 sim.setObjectPosition(sensorHandle, pos) -- e.g. move the sensor local calculationResults = sim.handleProximitySensor(sensorHandle) end end