1. Non-Blocking Code Blocks In normal programming each code block must be executed completely before the next block is run. This means, for example, that you can only have one robot moving at a time. Sometimes, however, you want multiple robots to move together. It's possible to do this using a special type of block called Non-Blocking (NB) blocks. With a "non-blocking" block, RoboBlocky will start the block's execution and then immediately move on to the next blocks in sequence while the non-blocking block continues executing. That is, the "non-blocking" block does not block execution of later blocks.
2. The driveDistanceNB Block An example of a non-blocking block is the driveDistanceNB block:
3. The moveWait Block We also use the moveWait block with non-blocking blocks to wait for all the non-blocking action to finish before ending the program:
4. Turn Off Trace for Proper Operation IMPORTANT: When using non-blocking code blocks for moving multiple robots, it's often best to turn off the trace for the virtual robots on the screen. Leaving the trace on can cause lags in the operation of both the on-screen and hardware robots, especially when more than two robots are moving simultaneously. One way to turn off the trace is to use the trace on/off block (in the Robot menu):
You can also turn off the trace without having to use any blocks in the code. To do so open the Robot Settings section below the grid and uncheck the Trace Position checkbox:
5. The turnNB Block The turn blocks are also available in non-blocking (NB) versions (see Example 4):
For more tips on using non-blocking blocks, see the lesson linked in the More Info button at top right.
|
driveDistanceNB, moveWait, turnNB
|
Drive Robot 1 forward 10 units and Robot 2 forward 5 units at the same time. |
The example drives Robot 1 forward 10 units and Robot 2 forward 5 units at the same time. But in this example the "moveWait" block is not used at the end. So the program ends after Robot 2 reaches the end of its move, and thus Robot 1 also stops at that point without driving the full 10 units. |
The example drives Robot 1 forward 5 units and Robot 2 forward 10 units at the same time. Like in Example 2, the "moveWait" block is not used at the end, so the program ends after Robot 2 reaches the end of its move. But the Robot 1 movement is not affected because in this example it moves a shorter distance than Robot 2 and thus finishes before Robot 2 finishes. |
The example uses non-blocking driveDistanceNB and turnNB blocks to that the two robots mirror each other's movements. Because they are doing the exact same movements at the same times, moveWait blocks are not needed. This example also uses the Trace Position checkbox in the Robot Settings section to turn off the trace, instead of the trace on/off block. |
Grid Size: S M L | Simple View: | MinView: |
Coord: x-axis y-axis | Grid Lines: x-axis y-axis | |||
Grid: | 12x12 inches | 24x24 inches | 36x36 inches | |
72x72 inches | 96x96 inches | 192x192 inches | ||
1x1 inches | 2x2 inches | Fraction: | ||
xy-Range: | ||||
|
||||
|
||||
Quad: | 1 Quadrant | 4 Quadrants | 1&4 Quadrants | |
Units: | US Customary | Metric | Ruler: |
Labels: |
|
|
|
Font
px
|
|
Tics Lines: |
|
Width
px
|
Hash Lines: |
|
Width
px
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
|
|||||||||||
|
|||||||||||