Skip to main content

Lesson 3: When Color Red Detected

There are no commands to tell the VR Robot what to do once it detects the color red. In order to avoid the red border, the VR Robot should reverse and turn once it detects the color red.

A close up side view of the upper right corner of the Playground, showing the VR Robot touching a castle piece along the red border of the Playground. There are arrows from the back of the robot, indicating the intended movement of the robot to reverse and turn to avoid the edge.
  • Add a [Drive for] and [Turn for] block to the end of the code to allow the VR Robot to reverse and turn once the Down Eye Sensor detects the color red.
The same VEXcode VR project with a Comment and two Drivetrain blocks added below the Repeat until block, at the bottom of the stack. The three additional blocks are a Comment that reads Reverse and turn when red border is detected; then Drive reverse for 300mm, and turn right for 90 degrees.
  • Open the Dynamic Castle Crasher Playground and run the project.
  • When this project is run, there are two conditions that are checked. The first is the condition of the Down Eye Sensor detecting the color red inside of the [Repeat until] block. Note that the project flow moves onto the next condition of an object being detected ONLY if the Down Eye Sensor does not see the color red. If the Down Eye Sensor does detect red, the project flow skips the [If then else] block and jumps to driving in reverse and turning.
A diagram showing the project flow of the current project. The If then block will repeatedly be checked and executed until the Down Eye Sensor detects red, and that condition reports as true. Then the project will break out of that loop and execute the blocks at the bottom of the stack to drive reverse and turn right to avoid falling off the Playground.
  • Once the Down Eye Sensor detects the color red, the VR Robot will drive in reverse, turn, then stop since that is the end of the project flow. There is no block used to repeat the behaviors again.

    A top down view of the Dynamic Castle Crasher Playground when the VR Robot stopped moving, showing several castles knocked over and some still standing, but the VR Robot is stopped along the lower right portion of the Playground, facing the center.
  • A [Forever] block is needed in order for the behaviors to repeat on a loop. Add a [Forever] block to the code.
An overview of adding a Forever loop to the current project so that the Forever block is attached to the When started block, and the entirety of the project is inside of it.
  • When this project is run, the VR Robot will drive toward a detected building and turn right if no buildings are reported. Once the Down Eye Sensor detects the color red, the VR Robot drives in reverse, turns, and continues driving toward another building.

    Top down view of the Dynamic Castle Crasher Playground with the VR Robot on the way to crash the final castle, and all other castles successfully knocked over.

Questions

Please select a link below to access the lesson quiz.

Google Doc / .docx / .pdf