Trigger callback functions

Child scripts, or customization scripts can include a trigger callback function (which is one of many system callback functions), 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: if a trigger callback function is present in a 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