Skip to main content

Lesson 3: Using Reported Sensor Feedback to Pick Up Disks

This Lesson will use reported sensor feedback to solve the same challenge as Lesson 2. The VR Robot will pick up and move the first blue disk into the blue goal.

  • Start a new project in VEXcode VR and name the project Unit8Lesson3.

    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 8 Lesson 3.
  • Drag four Comment blocks into the workspace. Add comments for each of the steps necessary for the VR Robot to drive to the first disk, pick it up, and return it to the blue goal.

    A new VEXcode VR Project with four Comment blocks attached to the When started block. The comments read, in order: 1. Drive to the first blue disk; 2. Pick up the first blue disk; 3. Drive to the blue goal; 4. Drop the blue disk in the blue goal.
  • Drag a [Repeat until] block into the workspace beneath the first comment.

    The same VEXcode VR project, with a Repeat until block added after the first comment. The Repeat until block's parameter is empty.

For Your Information

The [Repeat until] block is a C block that accepts Boolean reporter blocks. The [Repeat until] block will only check the Boolean condition at the beginning of each loop. If the Boolean condition is reported as FALSE, the blocks inside will run. If the Boolean condition is reported as TRUE, the blocks inside will be skipped.

A VEXcode VR Repeat Until block from the Toolbox.
  • The <Eye Sensor near object> block reports TRUE when the VR Robot detects a colored disk on the Disk Mover Playground. Drag this block into the project.

    The same VEXcode VR project, with an Eye Sensor near object added to the parameter of the Repeat Until block. The start of the project now reads When started, with a Comment of Drive to the first blue disk, then Repeat until Front Eye is near object.
  • The disks on the Disk Mover Playground are on the floor of the Playground and cannot be detected by the Front Eye Sensor. For this reason, set the <Eye Sensor near object> block to ‘DownEye.’

    The same VEXcode VR project, with the parameter of the Eye Sensor near object block open, and Down Eye selected. The Repeat until block now reads 'Repeat until Down Eye near object'.
  • The blocks on the inside of the [Repeat until] block will run when the VR Robot does NOT detect an object. To reach one of the disks, the VR Robot will need to drive forward until the disk is detected.

    The Disk Move Playground with the VR Robot in the blue goal starting position, with the blue disk in front of it.
  • Drag a [Drive] block into the [Repeat until] block.

    The same VEXcode VR project as before, with a Drive block added within the C of the Repeat until block. The project now begins with a When started block and a comment to Drive to the first blue disk. It then reads Repeat until Down Eye detects object, drive forward.
  • When a disk is detected, the VR Robot will need to stop driving in order to pick it up. Drag a [Stop driving] block and place it beneath the [Repeat until] block.

    The same VEXcode VR project, with a stop driving block added between the Repeat Until block and the second Comment.
  • Now, instruct the VR Robot to pick up the disk with the Electromagnet by placing an [Energize Electromagnet] block below the second comment.

    The same VEXcode VR project with an Energize Electromagnet block added beneath the second comment. The project now reads When started, Drive to the first blue disk; Repeat driving forward until Down eye detects object, then stop driving. Then Pick up the first blue disk, energize magnet to boost..
  • Open the Disk Mover Playground if it is not already open and run the project.
  • The VR Robot drives forward until the first blue disk is detected by the Down Eye Sensor, stops driving, and energizes the Electromagnet to pick up the disk.

    VR Robot on the Disk Mover Playground with the first blue Disk attached to the Electromagnet of the robot.
  • Notice how the [Repeat until] block works in this project.
    • Once the Down Eye Sensor on the VR Robot detects an object, the project moves to the next block in the stack below the [Repeat until] block.
    • In this project, that meant the VR Robot stopped driving and energized the Electromagnet.
A diagram of the project flow with the Repeat until block, showing that the VR Robot will start by driving forward, and will continue to drive forward until the Down Eye detects an object and that boolean parameter reports as true. Then the project moves on to stop driving and energize the Electromagnet to boost.

Using Switch Blocks 

The image below displays this Lesson's workflow graphic using Switch blocks. Comparing this graphic to the graphic above can help you better understand the workflow of the new Switch Python commands you are learning. 

A diagram of the project flow for the same project using Switch blocks. The VR Robot will start by driving forward, and will continue to drive forward until the Down Eye detects an object and that boolean parameter reports as true. Then the project moves on to stop driving and energize the Electromagnet to boost.

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