Execution order
Wandelscript execution happens step-by-step, consecutively.
home = (-153.3, -538.1, 454.9, 3.068, -0.623, -0.13)
move via p2p() to home
wait(500)
print("Home reached.")
First, home is declared, second the robot moves to home, and after 500 milliseconds "Home reached." is printed.
There are a couple of commands that can influence the execution order:
- Bundling of movements
- Blending with
write
- Explicit
sync
- Explicit
sync
withread
Bundling of movements
The exception to the rule are movement commands. Although they are executed in step-by-step order, they are planned together. This means they are collected in a motion queue to be processed together at a later stage.
Take the following code:
tcp("Flange")
home = (-153.3, -538.1, 454.9, 3.068, -0.623, -0.13)
move via p2p() to home
move via line to (139.9, -37.3, 319.8, -0.9, -2.5, -1.1)
Without the queued motion bundling, the robot would move to home, then pause, and then move to the next position.
Movement settings like blending
would not be possible.
Blending with write
blending
sets the blending time in millimeters to the indicated target pose.
tcp("Flange")
home = (-153.3, -538.1, 454.9, 3.068, -0.623, -0.13)
move via p2p() to home with blending(50)
write(controller, "key", "value")
move via line to (139.9, -37.3, 319.8, -0.9, -2.5, -1.1)
To simplify things, imagine a triangle. The robot moves from the current position over home to another position, in this case (139.9, -37.3, 319.8, -0.9, -2.5, -1.1)
.
The indicated blending means that the robot will not reach home but approach home within the blending zone of 50 mm.
write
is executed once the second movement is started so with blending, this naturally leaves the question: When is write
executed?
The write
command will be executed after the robot as reached the closest point to home within the blending zone and thus the blending has reached its peak.
But as write
acts without explicit synchronization, it is possible to finish executing write
before the robot has reached the second position. Depending on what follows the write
command, this can influence further movements.
Explicit sync
But how do you control when write
is executed?
As mentioned earlier, motions are bundled.
The sync
command gives you the control over when the bundled motions are planned and executed on the robot.
Until sync
is executed, no motion is sent to the robot hence the robot does not move.
Lets take a closer look on what the motion queue looks like when each of these commands are executed.
move frame("Flange") via p2p() to (150, -355, 389, 0, 0, 0)move frame("Flange") via line() to (-95, -363, 387)write(io, "digital_out[7]", True)print("write finished")sync
The script starts by bundling the motions into a queue, then writes to a device and syncs. Since the write
command is within the sync
block, it is triggered right after the motion queue.
If you want to make sure that write
only gets executed after the motions have been completed, place the write
command after the sync
:
tcp("Flange")
move via p2p() to (150, -355, 389, 0, 0, 0)
move via line() to (-95, -363, 387)
sync
write(io, "digital_out[7]", True)
print("write finished")
More on how to implement sync
with reading IOs can be found below.
Wandelscript written after the sync
is executed after the motions are completed.
Implicit sync
Next to explicitly declaring sync
, there are two exceptions where Wandelscript commands implicitly sync:
- End of file: If your script terminates successfully, a
sync
will be executed and clear the motion queue. do with robot:
: At the end of ado with robot:
statement, async
will be executed which sends the bundled motions to the robot.
Thus removing the explicit sync
from the end of the code will result in the same outcome:
move frame("Flange") via p2p() to (150, -355, 389, 0, 0, 0)move frame("Flange") via line() to (-95, -363, 387)write(io, "digital_out[7]", True)
The same is true for do with robot:
without and explicit sync
:
do with controller[0]: move flange_0 via p2p() to (100, 200, 300, 0.1, 0.2, 0.3) move flange_0 via p2p() to (100, 400, 500, 0.1, 0.2, 0.3) move flange_0 via p2p() to (100, 600, 700, 0.1, 0.2, 0.3)print("movement finished")
Explicit sync
with read
As read
reads values, it is often used to execute motions based on the read value. To ensure all previously executed commands are finished before the read value is used, place sync
before read
.
tcp("Flange")
move via p2p() to home
sync
dist = read(sensor, "key")
move via line() to home :: (dist, 0, 0)
If sync
is not added before read
, it is possible that the robot will try to execute the second movement before the read values are available as both move
commands will be bundled.
The explicit synchronization ensures that the robot will only execute the second move
once the read value is available.