Skip to main content

Lesson 3: Multiple Sensor Input

In the previous Lesson, the Distance Sensor was used to determine if the VR Robot detected an object or not, and if so, drove forward toward the object. However, no sensor values were used to determine if the VR Robot was close to the edge of the Playground to stop it. Stopping the VR Robot when it was close to the edge of the Playground would prevent it from driving off of the side.

The VEXcode VR project from the previous Lesson using the Distance Sensor on the robot to detect castles, then drive to crash them, is shown on the left. On the right is the Playground Window showing a project in progress, with several castles crashed, but the VR Robot about to drive off the edge of the Playground.

As is, the project repeats the behaviors of driving forward and turning, forever. However, there is no condition to check for the red border around the Playground. Thus, the VR Robot can fall off the Playground when driving forward.

A side view of the VR Robot on the Dynamic Castle Crasher Playground, pushing a piece of a castle off the side and about to drive off the edge itself.

Another sensor is needed for the VR Robot to be able to determine if it is close to the edge of the Playground or not. The behaviors of driving forward and turning only need to repeat until the red border is detected. Thus, the [Forever] block can be replaced with the [Repeat until] block, in order to repeat the behaviors of driving forward and turning until the condition of detecting the red border is met. The Down Eye Sensor can be used to determine if the VR Robot is close to the edge of the Playground by detecting the red border around the Playground.

A VEXcode VR Color sensing block reads Down Eye detects red?.
  • Load the Unit9Lesson2 project from the previous Lesson.
The Unit 9 Lesson 2 Project. The project begins with a When started block with a forever block attached. Within the forever block is an If then block with the Front Distance found an object as the parameter. The If then branch has a comment that reads Knock over the building found using the Distance Sensor and a Drive forward block. The else branch has a comment that reads Turn to find a building using the Distance Sensor and a turn right block.
  • Rename the project Unit9Lesson3.
The project name box in the center of the VEXcode VR Toolbar, highlighted with a red box, to the left of the Select Playground button. The project name reads Unit 9 Lesson 3.
  • A block is needed to continuously check the Down Eye Sensor. The VR Robot will need to repeat these behaviors until the Down Eye Sensor detects the color red. First, remove the [Forever] block.
An overview of removing the Forever block from the project. The new project moves from the When started block to the If then else block, without the Forever loop present.
  • Add a [Repeat until] block.
An overview of adding the Repeat until block around the entirety of the If then else block. The new project begins with a When Started block, then has a Repeat until block with the parameter open. Within the C of the Repeat until block is the If then else block.
  • Add a <Color sensing> block inside the [Repeat until] block and set the parameters to ‘DownEye’ detects ‘red.’
The same project with the Down Eye Detects red set as the parameter of the Repeat until block.

A [Repeat until] block is used instead of a [Wait until] block in this project. This is because a [Wait until] block is a waiting block that will pause the flow of the project until the condition is met. If a [Wait until] block is used, the [If then else] block would not be executed until the condition of the [Wait until] is met and the [If then else] block would only be executed once.

A diagram of the project flow if a Wait until block were used instead of a Repeat until loop. The project would hold at the wait until block, until the condition reported as true, and would only then move on to the If then else block.

By using a [Repeat until] block, the [If then else] condition is constantly being checked and executed.

A diagram of the project flow with the Repeat Until block, showing that the condition of the If then else block is continually checked, and executed based on whether the object is found (True) or not found (false).
  • Add a comment to note the purpose of using the [Repeat until] block.
The same project as previously built, with a Comment block added between the When started block and the Repeat until block. The comment reads 'Look for buildings until the red border is detected.'
  • Open the Dynamic Castle Crasher Playground and run the project.
  • When this project is run, the VR Robot will drive toward a detected object and turn right otherwise. However, even though the Down Eye Sensor is looking for the red border, the VR Robot is not told what to do once it detects red, so it continues driving and eventually falls off of the Playground.

    A top down view of the Dynamic Castle Crasher Playground Window as the project is running, with several castles crashed and the VR Robot driving off the upper right side edge of the Playground in pursuit of a castle piece.

Once the condition of the [Repeat until] block is met, the project flow will execute out of the [Repeat until] block.

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