Skip to main content

Lesson 2: Using the [Wait until] Block

In this Lesson, you will create a project using the Bumper Sensor and [Wait until] block. In the mini-challenge, you will apply these skills to navigate from the beginning of the Wall Maze to the letter ‘A.’

Side view of the Wall Maze Playground with the VR Robot directly in front of a wall, showing that the walls are three dimensional and the robot can collide with them.

Learning Outcomes

  • Identify that non-waiting blocks have the stack continue even if the block's behavior is not yet complete.
  • Identify that a waiting block pauses the stack until that block's behavior has been completed.
  • Identify that the highlighting of the project's execution visualizes waiting vs non-waiting blocks.
  • Identify that the [Wait until] block is a Control block that accepts Boolean values.
  • Identify that the [Wait until] block will repeatedly check a Boolean condition and will not move to the next block until the condition reports TRUE.
  • Identify that the [Wait until] block is used with a non-waiting block (e.g. Drive) in order to check the sensor condition.
  • Identify that the <Pressing bumper> block reports a TRUE or FALSE value in a [Wait until] block.
  • Identify how the [Drive for] and [Turn for] blocks are special blocks that can be either waiting or non-waiting.
  • Describe how to create a project that has a VR Robot drive forward until the Bumper Sensor is pressed.

Name and Save the Project

  • Start a new project in VEXcode VR and name the project Unit4Lesson2.
Project name box in the center of the VEXcode VR Toolbar, highlighted with a red box, to the left of the Select Playground button.

[Wait until] Blocks

The [Wait until] block is a Control block that accepts Boolean conditions. [Wait until] blocks repeatedly check a Boolean condition and control the project flow. A project will not move to the next block in the stack until the condition in the [Wait until] block reports as TRUE. The [Wait until] blocks are used in conjunction with non-waiting blocks such as [Drive] or [Turn].

For Your Information

Non-waiting and waiting blocks determine when the next block begins a behavior. Waiting blocks, like [Drive for] and [Turn for], complete their behaviors before moving onto the next block in the stack. Non-waiting blocks, such as [Drive] and [Turn], continue to move to the next block in the stack even if the behavior of the non-waiting block is not complete.

Certain blocks, like [Drive for] and [Turn for] can be waiting or non-waiting blocks. Selecting the arrow on the block will turn the block from waiting into a non-waiting block.

A drive for block is shown with the arrow at the right of the block closed and open. On top, a drive for block reads Drive forward for 200mm. On the bottom, the same block is extended to read Drive forward for 200mm and don't wait.

Using Switch Blocks

The Switch non-waiting block adds a "wait=False" parameter at the end of the block. "wait=False" is the Python command that tells the block not to wait and to continue to move to the next blocks in the stack.

The equivalent Switch block is shown with the drive for command as a waiting and non-waiting command. On top, the Python command in the Switch block reads drivetrain dot drive_for (FORWARD, 200, MM).. On the bottom, the same command is extended to read drivetrain dot drive _ for (FORWARD, 200, MM, wait = false).

  • Drag the [Drive] non-waiting block into the workspace.

    A new VEXcode VR project With a When started block with a drive block attached and set to forward.
  • Attach a [Wait until] block beneath the [Drive] block.

    The same project with a wait until block added to the bottom of the stack. The parameter of the Wait until block is empty.
  • The [Wait until] block accepts Boolean conditions. This project will use the Bumper Sensor to drive through the Wall Maze Playground. Drag the <Pressing bumper> Boolean block into the [Wait until] block.

    The same project with a Bumper pressed block added to the parameter of the Wait until block. The project now reads When started, drive forward, wait until Left bumper pressed.
  • Drag in a [Stop driving] block and add it to the project.

    The same project with a stop driving block added beneath the wait until block. The project now reads When started, drive forward, wait until left bumper pressed, then stop driving.
  • Launch the Wall Maze Playground if it is not already open and run the project.
  • Watch the VR Robot drive from the start of the Wall Maze and stop when the Bumper Sensor is pressed by the wall.
  • The [Drive] block allows the VR Robot to keep driving forward while checking the condition of the Bumper Sensor with the <Pressing bumper> block. Once the <Pressing bumper> reports as TRUE, the VR Robot will move to the next block in the stack and stop driving.

    VEXcode VR project from this lesson broken apart to show project flow. The When started block is followed by the drive forward block. A gold arrow points downwards from the drive forward block at the Wait until left bumper pressed block. To the right of the block are 2 curved red arrows indicating a circular motion and the words "not pressed (false)" showing what happens when the robot drives forward and the bumper switch is not pressed. Underneath the Wait until block, a green arrow pointing down at the stop driving block with the words "pressed (true)" indicates that the project will move to the stop driving block when the bumper switch is pressed.

    For Your Information

    To follow a visualization of waiting versus non-waiting blocks, watch the code execution highlighting function in VEXcode VR. At the beginning of this project, the green highlight will appear around the [Wait until] block until the condition is met. This is because the [Wait until] block is a waiting block. The green highlight will appear to skip the non-waiting blocks because these commands are quickly executed.

    VEXcode VR project from this lesson with a red callout box around the Wait until block, indicating it is a waiting block.

     

    Using Switch Blocks 

    This is the Switch block containing the [Wait until] command with the <Bumper pressed>  Boolean reporter.

    VEXcode VR project as above, but with the Wait until block replaced with a Switch block. The Python command in the Switch block reads while not left_bumper.pressed(): on the first line. Then indented underneath the Python block reads wait (5, msec).

    while not left_bumper.pressed(): is the Python command that checks whether the left bumper is currently being pressed.

    wait (5, MSEC) is a Python command that pauses the execution of the check for 5 milliseconds (MSEC), so the project checks whether or not the left bumper is pressed every 5 MSEC. This line of code is indented underneath the first line of code because this command is the behavior that will repeat until the condition (in this case, the left bumper pressed) is met.

    In VEXcode VR, a wait command is always added with a conditional loop. The purpose of the wait command is to ensure that VEXcode VR can properly run the project as intended, due to the web-based nature of the VEXcode VR platform. The wait command should never be deleted when using a conditional loop, because your project may not run as intended.

    Once the left bumper is pressed, the robot will stop driving.

Select the Next button to continue with the rest of this Lesson.