How to pass signal in function sysCall_thread()

Typically: "How do I... ", "How can I... " questions
Post Reply
YZHOU035
Posts: 1
Joined: 09 Jan 2024, 20:37

How to pass signal in function sysCall_thread()

Post by YZHOU035 »

Hi Development team, I met a problem in reading signal in my Child script "/UR10". Specifically, I want to only preceed the robot motion when it get the signal indicating that the object has been put in the correct place, and the Child script of the conveyor is:

Code: Select all

--lua

sim=require'sim'

function sysCall_init()
    self=sim.getObject('.')
    sensor=sim.getObject('./_sensor')
end

function sysCall_actuation()
    --if (sim.getInt32Signal('ActivateBelt') == 1) then
        --beltVelocity=0.08
    --else
        --beltVelocity=0.0
    --end

    beltVelocity=0.08

    if sim.readProximitySensor(sensor)>0 then
        beltVelocity=0
        sim.setInt32Signal('pickup_Ready', 1)
    else
        sim.clearInt32Signal('pickup_Ready')
    end
    
    sim.writeCustomTableData(self,'__ctrl__',{vel=beltVelocity})
end
I can correctly read the signal changes using the signal monitor tool. However in my UR10 script as following (part of):

Code: Select all

function waitForSensor()
    sim.waitForSignal('pickup_Ready')
end

function sysCall_thread()

    object_picked = 0
    while object_picked < 3 do
        waitForSensor()
        -- STEP I
        goToPickPos()
        sim.wait(0.5)
        -- STEP II
        activateVacuum()
        sim.wait(0.5)
        -- STEP III
        goToDropPos()
        sim.wait(0.5)
        -- STEP IV
        releaseVacuum()
        sim.wait(0.5)
        
        object_picked = object_picked + 1
    end
    goToInitPos()
    sim.stopSimulation()
end
The waitForSensor function does not work and the robot would not move. Can anyone please help me how to fix this problem? Thanks a lot.

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

Re: How to pass signal in function sysCall_thread()

Post by coppelia »

Hello,

this works fine:

Code: Select all

-- lua

function sysCall_init()
    sim = require('sim')
    i = 0
end

function sysCall_actuation()
    i = i + 1
    if i == 1000 then
        print("Signal set")
        sim.setInt32Signal("pickup_Ready", 1)
    end
end

Code: Select all

-- lua

function waitForSensor()
    sim.waitForSignal('pickup_Ready')
end

function sysCall_init()
    sim = require('sim')
end

function sysCall_thread()
    print("Waiting")
    waitForSensor()
    print("Signal received")
end
Cheers

Post Reply