Trigger callback functionsA child script, or a customization script can include a trigger callback function, when associated with a vision sensor, a proximity sensor, or a force/torque sensor. Some conditions apply as to the location of the trigger callback function: normally, it should be inside of a customization script, or a non-threaded child script. However, if the triggering API function (e.g. sim.handleVisionSensor or sim.handleProximitySensor) is called from within of a threaded child script, then the trigger callback function should also be located in the threaded child script. If a trigger callback function is present in a non-threaded child script as well as in a customization script, both attached to the object triggering, then the child script will be called first, and the customization script second. A vision sensor can generate the trigger signal inside of the vision callback function. The trigger callback (if present) is then called as in following example:
function sysCall_trigger(inData)
-- We have:
-- inData.handle : the handle of the vision sensor.
-- inData.packedPackets : an array of data packets, packed (use sim.unpackFloatTable to unpack)
-- the first data packet always contains 15 auxiliary values about the acquired image:
-- - minimum of {intensity, red, green blue and depth value}
-- - maximum of {intensity, red, green blue and depth value}
-- - average of {intensity, red, green blue and depth value}
local outData={}
outData.trigger=true
return outData
end
A proximity sensor generates the trigger signal when an object is detected. The trigger callback (if present) is then called as in following example:
function sysCall_trigger(inData)
-- We have:
-- inData.handle : the handle of the proximity sensor.
-- inData.detectedObjectHandle : handle of detected object
-- inData.detectedPoint : detected point, relative to sensor frame
-- inData.normalVector : normal vector at detected point, relative to sensor frame
local outData={}
outData.trigger=true
return outData
end
Following is an example of a force/torque sensor trigger callback function, where the force/torque sensor is broken::
function sysCall_trigger(inData)
-- We have:
-- inData.handle : the handle of the force/torque sensor.
-- inData.force : current force
-- inData.torque : current torque
-- inData.filteredForce : current filtered force
-- inData.filteredTorque : current filtered torque
sim.breakForceSensor(inData.handle)
end
Recommended topics |