The method of controlling the gripper action not to be executed together with the mechanical arm action

Typically: "How do I... ", "How can I... " questions
Post Reply
lumeqi
Posts: 29
Joined: 04 Dec 2023, 06:20

The method of controlling the gripper action not to be executed together with the mechanical arm action

Post by lumeqi »

Hello,
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
This is the code I used to control the closure of the gripper:

Code: Select all

sim.setInt32Signal("UR10", 0)
Thank you for your help.

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: The method of controlling the gripper action not to be executed together with the mechanical arm action

Post by coppelia »

Hello,

it is normal that the gripper does not close instantaneously. Otherwise it would not work. But instead, you should trigger the gripper close action, then wait a moment until the gripper is closed (or wait for a signal that the gripper is now not moving anymore). But I don't know how your robot arm movement is triggered, if your script runs threaded or not, etc., so I can't give more details.

Cheers

lumeqi
Posts: 29
Joined: 04 Dec 2023, 06:20

Re: The method of controlling the gripper action not to be executed together with the mechanical arm action

Post by lumeqi »

Hello,
I also encountered a similar problem: I first set the joint position of the robotic arm using sim.setJointPosition, and then let the robotic arm move through motion planning. I want the robotic arm to move to the target joint position first, and then perform motion planning. But the reality is that these two actions are executed simultaneously. I use the ZMQ Remote API and my program is executed sequentially, without using multithreading. I cannot use time.sleep() to stop for a period of time because it will cause the entire simulation to stop.
Thank you for solving my problem.

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: The method of controlling the gripper action not to be executed together with the mechanical arm action

Post by coppelia »

Sorry, I am not sure I understand. If you are trying to move a dynamically enabled joint in a realistic fashion, you cannot use sim.setJointPosition, since motion would be instantaneous. You should use instead sim.setJointTargetPosition, and the joint will try to reach the desired position when in position control.

Often you will need to e.g. check for collision before executing a motion to a specific configuration. In that case, best would be to use a second robot that is not dynamically enabled and hidden. Or you could use the same robot (not ideal) and sim.setJointPosition, by making sure to reset the position to what it was prior to the checking.

Cheers

Post Reply