Read proximity from threaded script

Typically: "How do I... ", "How can I... " questions
Post Reply
fullmanido
Posts: 3
Joined: 23 Jul 2018, 22:02

Read proximity from threaded script

Post by fullmanido » 31 Jul 2018, 22:19

Hello, I am trying to enable a robot if the sensor is active. I have the proximity in a non-threaded script, now I need to update the signal in the threaded script. The packed table needs to be monitored, should I use a parameter?

--threaded script
setTestData=function(bool)
conveyorName='ConveyorBelt'
data=simGetStringSignal(conveyorName..'_CBS1')
if data then
CBSData=simUnpackFloatTable(data)
CBS1Sesnor1=(CBSData[1])
CBS1Sesnor2=(CBSData[2])
end
end

thanks!

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

Re: Read proximity from threaded script

Post by coppelia » 03 Aug 2018, 05:51

Hello,

not sure I understand your question. Why not simply printing the unpacked table to the status bar, e.g.:

Code: Select all

if data then
    CBSData=simUnpackFloatTable(data)
    CBS1Sesnor1=(CBSData[1])
    CBS1Sesnor2=(CBSData[2])
    print("Sensor1",CBS1Sesnor1)
    print("Sensor2",CBS1Sesnor2)
end
Cheers

fullmanido
Posts: 3
Joined: 23 Jul 2018, 22:02

Re: Read proximity from threaded script

Post by fullmanido » 03 Aug 2018, 22:01

Hello,

Thank you for your reply. I am trying to send an "OK to run" signal to the UR5 example. The proximity is located at the end if the conveyor, I don't want the robot to initialize without an object present on the conveyor. I really need a global variable that I can transfer from a Non-threaded script to a while loop in a threaded script.

---Conveyor code (not-threaded)
-- would like to send the signal to a threaded while loop
if (sim_call_type==sim_childscriptcall_actuation) then
if simReadProximitySensor(sensor)>0 then
beltVelocity=0
sensor1=1
sensor2=0
end
local data=simPackFloatTable({sensor1,sensor2})
simSetStringSignal(modelName..'_CBS1',data)
end

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

Re: Read proximity from threaded script

Post by coppelia » 06 Aug 2018, 19:20

If you need a global variable, why not use a string signal for instance?

e.g. sim.setStringSignal('signalName',sim.packTable(...))

Cheers

fullmanido
Posts: 3
Joined: 23 Jul 2018, 22:02

Re: Read proximity from threaded script

Post by fullmanido » 07 Aug 2018, 22:05

Hello, can you direct us to an example in the sample programs where this is used?

Post Reply