How to use the Suction pad

Typically: "How do I... ", "How can I... " questions
Post Reply
dyu
Posts: 6
Joined: 29 Jan 2021, 15:25

How to use the Suction pad

Post by dyu »

Hi,
I'm trying to use the built in suction cup to pick up an object. Does the object I am trying to pick up have to be both respondable and dynamic for this to work? Or will it work if it is neither, or only respondable?

The object I have right now is respondable and dynamic, but I'm not being able to pick it up. Here is the suction pad child script:

Code: Select all

function sysCall_init() 
    s=sim.getObjectHandle('suctionPadSensor')
    l=sim.getObjectHandle('suctionPadLoopClosureDummy1')
    l2=sim.getObjectHandle('suctionPadLoopClosureDummy2')
    b=sim.getObjectHandle('suctionPad0')
    suctionPadLink=sim.getObjectHandle('suctionPadLink')

    infiniteStrength=sim.getScriptSimulationParameter(sim.handle_self,'infiniteStrength')
    maxPullForce=sim.getScriptSimulationParameter(sim.handle_self,'maxPullForce')
    maxShearForce=sim.getScriptSimulationParameter(sim.handle_self,'maxShearForce')
    maxPeelTorque=sim.getScriptSimulationParameter(sim.handle_self,'maxPeelTorque')

    sim.setLinkDummy(l,-1)
    sim.setObjectParent(l,b,true)
    m=sim.getObjectMatrix(l2,-1)
    sim.setObjectMatrix(l,-1,m)
end

function sysCall_cleanup() 
    sim.setLinkDummy(l,-1)
    sim.setObjectParent(l,b,true)
    m=sim.getObjectMatrix(l2,-1)
    sim.setObjectMatrix(l,-1,m)
end 

function sysCall_sensing() 
    parent=sim.getObjectParent(l)
    if (sim.getScriptSimulationParameter(sim.handle_self,'active')==false) then
        if (parent~=b) then
            sim.setLinkDummy(l,-1)
            sim.setObjectParent(l,b,true)
            m=sim.getObjectMatrix(l2,-1)
            sim.setObjectMatrix(l,-1,m)
        end
    else
        if (parent==b) then
            -- Here we want to detect a respondable shape, and then connect to it with a force sensor (via a loop closure dummy dummy link)
            -- However most respondable shapes are set to "non-detectable", so "sim.readProximitySensor" or similar will not work.
            -- But "sim.checkProximitySensor" or similar will work (they don't check the "detectable" flags), but we have to go through all shape objects!
            index=0
            while true do
                shape=sim.getObjects(index,sim.object_shape_type)
                if (shape==-1) then
                    break
                end
                if (shape~=b) and (sim.getObjectInt32Parameter(shape,sim.shapeintparam_respondable)~=0) and (sim.checkProximitySensor(s,shape)==1) then
                    -- Ok, we found a respondable shape that was detected
                    -- We connect to that shape:
                    -- Make sure the two dummies are initially coincident:
                    sim.setObjectParent(l,b,true)
                    m=sim.getObjectMatrix(l2,-1)
                    sim.setObjectMatrix(l,-1,m)
                    -- Do the connection:
                    sim.setObjectParent(l,shape,true)
                    sim.setLinkDummy(l,l2)
                    break
                end
                index=index+1
            end
        else
            -- Here we have an object attached
            if (infiniteStrength==false) then
                -- We might have to conditionally beak it apart!
                result,force,torque=sim.readForceSensor(suctionPadLink) -- Here we read the median value out of 5 values (check the force sensor prop. dialog)
                if (result>0) then
                    breakIt=false
                    if (force[3]>maxPullForce) then breakIt=true end
                    sf=math.sqrt(force[1]*force[1]+force[2]*force[2])
                    if (sf>maxShearForce) then breakIt=true end
                    if (torque[1]>maxPeelTorque) then breakIt=true end
                    if (torque[2]>maxPeelTorque) then breakIt=true end
                    if (breakIt) then
                        -- We break the link:
                        sim.setLinkDummy(l,-1)
                        sim.setObjectParent(l,b,true)
                        m=sim.getObjectMatrix(l2,-1)
                        sim.setObjectMatrix(l,-1,m)
                    end
                end
            end
        end
    end
end 

What is the correct way to activate this suction pad? Could you please provide an example lua script?
Thank you for your time
coppelia
Site Admin
Posts: 10747
Joined: 14 Dec 2012, 00:25

Re: How to use the Suction pad

Post by coppelia »

Hello,

so it seems you are using the suction pad model that comes with CoppeliaSim. You can see that there is a proximity sensor (very small, and hidden in a hidden layer) that checks if a shape is detected. So the first question: does your shape get detected?

The script you are referring to specifically checks for non-static, respondable shapes. But technically, you could also check only for non-static shapes.

Cheers
dyu
Posts: 6
Joined: 29 Jan 2021, 15:25

Re: How to use the Suction pad

Post by dyu »

It turns out my shape doesn't even get detected. It's a respondable, dynamic shape.
Here is my scene:
https://drive.google.com/file/d/1GIrRgp ... sp=sharing

What could be going wrong?
Note for the scene: I just need one suction to work, the others are dummies. I've been testing with suctionPad0
coppelia
Site Admin
Posts: 10747
Joined: 14 Dec 2012, 00:25

Re: How to use the Suction pad

Post by coppelia »

In your scene nothing is moving. What shape is supposed to get detected? And how does the movement look like?
Of course if the proximity sensor of your suction pad doesn't get close enough to touch the object, it won't be detected. Make visually sure that the ray-type proximity sensor intersects with the shape you want to detect. Output some text here and there in the child script of the suction pad, to make sure that the code executes as expected. You can also try to adjust the volume properties of the proximity sensor, e.g. to make it longer.

Cheers
dyu
Posts: 6
Joined: 29 Jan 2021, 15:25

Re: How to use the Suction pad

Post by dyu »

Thanks! It turned out that the proximity sensor was too far inside the suction pad, and therefore the object wasn't getting detected. I adjusted it's position and now it works fine.
mecabot
Posts: 4
Joined: 07 May 2024, 05:34

Re: How to use the Suction pad

Post by mecabot »

How can I detach the object from the suctionPad?
coppelia
Site Admin
Posts: 10747
Joined: 14 Dec 2012, 00:25

Re: How to use the Suction pad

Post by coppelia »

Just change the parent of the linked dummy, the one attached to your object:

i.e. from:

Code: Select all

pickedPart --> linkedDummyB
to:

Code: Select all

pickedPart
You'd do that with sim.setObjectParent. But normally the suction pad code does that for you: in that code, you have an enabled variable that you should turn to false.

Cheers
Post Reply