Is there a method to immediately close or open the gripper? When I set the signal for the gripper to close, it will not immediately close. If I have the code for the movement of the robotic arm after setting the gripper closing signal, it will move and close at the same time. But I want the gripper to close first, and then perform the next action after completing the closure.
This is my code for gripper:
Code: Select all
sim=require'sim'
function sysCall_init()
motorHandle=sim.getObject('./openCloseJoint')
centerJoint=sim.getObject('./centerJoint')
motorVelocity=0.15 -- m/s
motorForce=20 -- N
sim.setInt32Signal('UR10',1)
connector=sim.getObject('./attachPoint')
objectSensor=sim.getObject('./attachProxSensor')
lock = true
end
function sysCall_actuation()
local v=-motorVelocity
local data=sim.getInt32Signal('UR10')
--print("data:", data)
if data and data~=0 then
v=motorVelocity
openingGripper()
else
if lock then
closingGripper()
end
end
sim.setJointTargetForce(motorHandle,motorForce)
sim.setJointTargetVelocity(motorHandle,v)
end
function sysCall_joint(inData)
if inData.handle==centerJoint then
local error=(-sim.getJointPosition(motorHandle)/2)-inData.currentPos
local ctrl=error*20
local velocityToApply=ctrl
if (velocityToApply>inData.maxVel) then
velocityToApply=inData.maxVel
end
if (velocityToApply<-inData.maxVel) then
velocityToApply=-inData.maxVel
end
local forceOrTorqueToApply=inData.maxForce
local outData={vel=velocityToApply,force=forceOrTorqueToApply}
return outData
end
end
function closingGripper()
index = 0
while true do
shape = sim.getObjects(index, sim.object_shape_type)
if (shape == -1) then
break
end
if (sim.getObjectInt32Param(shape, sim.shapeintparam_static) == 0) and (sim.getObjectInt32Param(shape, sim.shapeintparam_respondable) ~= 0) and (sim.checkProximitySensor(objectSensor, shape) == 1) then
attachedShape = shape
sim.getObjectParent(attachedShape, connector, true)
lock = false
break
end
index = index + 1
end
end
function openingGripper()
child = sim.getObjectChild(connector, 0)
if child ~= -1 then
sim.getObjectParent(child, -1, true)
lock = true
end
end
Code: Select all
sim.setInt32Signal("UR10", 0)