Hello all,
First of all sorry if my questions is too simple, but I can not find a proper response from the scene examples.
Can I control or command a movement of a robot, from the script of a conveyor belt, for example?
The situation is as follows:
1.- In my scene, I have a robot and a conveyor belt. Each element has its own script.
2.- In the coveyor belt, I use a proximity sensor to detect that a part is in position and to stop the coveyor belt.
3.- the the robot performs operations over that part and I want to start again the coveyor belt once the robot has reached a safe position.
How can I command the robot to go to the safe position from the conveyor belt? OR in another way, how can I be notified in the conveyor belt script that the robot has reached the safe position, so that I can start the conveyor belt again?
Thank you very much in advance,
Alberto
Controlling elements from other elements´ scripts
Re: Controlling elements from other elements´ scripts
Certainly you can control the conveyor (or anything else) from your robot's child script.
However, this leads to "spaghetti code", where it is difficult for a third person (or you, in the future) to understand why an object behaves the way it does.
It would be better to decouple the objects, enforcing a modular design.
One way to tho this, is to use signals. From the documentation:
And in the conveyor script (perhaps in the actuation callback):
However, this leads to "spaghetti code", where it is difficult for a third person (or you, in the future) to understand why an object behaves the way it does.
It would be better to decouple the objects, enforcing a modular design.
One way to tho this, is to use signals. From the documentation:
For example, you can use in robot's script:Signals can be seen as global variables. Three types of signals are currently supported: integer-type signals, floating-type signals and string-type signals. Signals can be defined, redefined, read and cleared. At simulation end, all signals created by the main script or any child script will be cleared.
Code: Select all
-- robot writes 1 to signal "startConveyor":
sim.setIntegerSignal("startConveyor",1)
Code: Select all
-- conveyor reads the data from the signal "startConveyor":
local signalData=sim.getIntegerSignal("startConveyor")
if signalData == 1 then
-- clear the signal so this code won't be executed again, repeatedly:
sim.clearIntegerSignal("startConveyor")
-- do the right things to start the conveyor
-- ...
end