Skip to main content

Lesson 2: Drive to the Next Disks

Drive to the Blue Disks

The previous project has the VR Robot turn right when the Front Eye Sensor detects a green disk, which took the VR Robot through the first step in the maze. Now, we will continue to build onto the project so the VR Robot drives to the first four disks on the Disk Maze Playground.

Looking at where the VR Robot is facing after turning right at the green disk, we can see that to navigate to the next three blue disks, the VR Robot should drive forward and turn left at each blue disk. We can use the same logic of the while loop with the not condition to have the VR Robot continue to drive through the maze, and turn left when it detects a blue disk.image of the VR in the maze at the point the previous project ended, with the next steps of the path lined up

  • Add another comment into the existing project to describe the next behaviors of the VR Robot.

comment added

  • Beneath the new comment, add another while loop with a not condition. Set the condition to the detect command and set the parameters to "BLUE", since the next disk that the VR Robot will encounter is blue.front eye detect blue condition
  • Inside the while loop, drag or type the non-waiting drive command. 
    drive forward command in while not loop
  • Drag in or type a turn_for command, and set the parameters to turn left 90 degrees.
    turn for 90 degrees command
  • Run the project to see how the VR Robot moves through the Disk Maze Playground.turn left at blue
    • Notice that the VR Robot turns right when the Front Eye Sensor detects a green disk, and turns left when the Front Eye Sensor detects a blue disk.
  • Continue to build this project to drive the VR Robot to two more blue disks on the Disk Maze Playground using the Front Eye Sensor. Add the following commands to navigate the VR Robot to the next two disks then stop:full project code

Identifying a Pattern in the VR Robot's Movements

The goal of successfully navigating the Disk Maze with the Front Eye Sensor is to create a consistent pattern where the VR Robot turns right when the Front Eye Sensor detects a green disk, and left when the Front Eye Sensor detects a blue disk. Identifying patterns like this can help you simplify your projects as they grow in complexity.

turn at blue

For Your Information

Notice that there is a pattern in the sequence of commands in the project as well. There is a series of commands that are repeated three times in the project. This section of code can be condensed by using a for loop.repeated code in for loop

Using a for loop can make your project simpler and more easily readable, but containing the repetitive commands inside one loop.

  • Open the Disk Maze Playground if it is not already open, and run the project.
  • Watch the VR Robot navigate to four disks on the Disk Maze Playground.
    turn at blue
  • In this project, the VR Robot drives forward until the Front Eye Sensor detects the color green.
    • The VR Robot turns right 90 degrees and drives forward again until the color blue is detected.
    • The VR Robot then turns left and drives forward until the Front Eye Sensor detects blue. Once the color blue is detected, the VR Robot turns left again.
    • Finally, the VR Robot drives forward until the Front Eye Sensor detects blue, then stops.
  • Notice the pattern that when the Front Eye Sensor detects green, the VR Robot turns right. When the Front Eye Sensor detects blue, the VR Robot turns left in this project.

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