Hello, I'm writing code where i want to communicate between several components, so i can control cooperation between them. When I'm setting string signal in IRB4600#1 on 122'th line of script, then IRB4600#2 receives that signal and perform as expected, but when i set string signal any further in my IRB4600#1 (script line > 122) then IRB4600#2 still receives that signal, but doesn't move (target moves, but robot doesn't follow).
I came across this problem before, but i solved it by setting signal earlier in the code and sim.wait() in another robot. What am I doing wrong or don't understand? Maybe there is a better way to communicate between several robots and components?
Here is my scene: http://s000.tinyupload.com/index.php?fi ... 2897558066
Why place where i set string signal affects robot movement?
Re: Why place where i set string signal affects robot movement?
Hello,
signals should be used carefully, since you should see then as global variables. If you set that variable several times before another script runs, then only the last set variable will be read (i.e. signals are variables, not buffers). If you want robot1 be able to send data to robot2 without losing intermediate states, then you can use something like (in case you wish to use signals):
Cheers
signals should be used carefully, since you should see then as global variables. If you set that variable several times before another script runs, then only the last set variable will be read (i.e. signals are variables, not buffers). If you want robot1 be able to send data to robot2 without losing intermediate states, then you can use something like (in case you wish to use signals):
Code: Select all
Robot1:
function writeValue(newValue)
-- sim.setThreadAutomaticSwitch(false) -- if in a threaded child script
local val=sim.getStringSignal('myCommunicationChannel') -- read existing data
if not val then
val={}
else
val=sim.unpackTable(val)
end
val[#val+1]=newValue -- append new data
sim.setStringSignal('myCommunicationChannel',sim.packTable(val)) -- write updated data
-- sim.setThreadAutomaticSwitch(true) -- if in a threaded child script
end
Robot2:
function readValue()
-- sim.setThreadAutomaticSwitch(false) -- if in a threaded child script
local retVal=nil
local val=sim.getStringSignal('myCommunicationChannel') -- read data
if val then
val=sim.unpackTable(val)
if #val>0 then
retVal=table.remove(val,1) -- remove one data item
sim.setStringSignal('myCommunicationChannel',sim.packTable(val)) -- write updated data
end
end
-- sim.setThreadAutomaticSwitch(true) -- if in a threaded child script
return retVal
end
Re: Why place where i set string signal affects robot movement?
Thank you for your answer. I found that using sim.waitForSignal and setting integer signals in another robot gives me the best results.