CS Level 1 - VEXcode VR Python

Unit 8 - Moving Disks with Loops

# Lesson 3: Using Sensors with the Electromagnet

In the previous Lesson, you used the energize command and Drivetrain commands to pick up and move disks on the Disk Mover Playground with the VR Robot. This Lesson will solve the same challenge using reported sensor feedback and while loops.

## Learning Outcomes

• Identify that the down_eye.near_object command reports if the Down Eye Sensor is close enough to an object to detect a color.
• Identify that the turn_to_heading command turns a drivetrain to a specific heading, using the Gyro Sensor.
• Identify that the turn_to_heading command will determine which direction to turn based on the current heading of the Gyro Sensor.
• Explain why a turn_to_heading command would be used instead of a turn or a turn_for command.
• Describe the flow of a project that uses a while loop with a not condition with the Electromagnet to pick up and move a disk.

## Why Use Sensors to Solve the Disk Mover Problem?

In Lesson 2, the VR Robot drove a specified distance using the drive_for command to pick up and move a blue disk back to the goal. The distance between the VR Robot and the first blue disk was estimated and checked using the dimensions of grid squares on the Disk Mover Playground. While this did solve the challenge, there is much room for error in duplicating the process to pick up multiple disks at various distances, which is necessary to solve the Disk Mover Challenge at the end of this Unit. Using reported sensor feedback is a more efficient way to solve this challenge, while also optimizing the project by using fewer commands.

What if the VR Robot collides with a disk and is knocked off course? What if the disks are in slightly different locations from the goal? Feedback from sensors can be used to precisely pick up and move disks without knowing their exact location on the Disk Mover Playground.

The steps to solve the challenge can be used to help determine which sensors to use in the project.

• First: The VR Robot will drive to the first disk.
• The disks are on the ground of the Playground. To determine where a disk is located, the Down Eye Sensor can be used with the down_eye.near_object command. Notice the position of the Down Eye Sensor in relation to the Electromagnet on the VR Robot.
• Second: The VR Robot will use the Electromagnet to pick up the first disk.
• Third: The VR Robot will drive back to the goal.
• While driving back to the goal, the VR Robot can use the Distance Sensor to determine when to stop driving. The Distance Sensor can be used to determine how far away the front of the VR Robot is from the wall of the Playground. Using the get_distance command, the Distance Sensor can drive and stop when it is a specified distance from the wall, positioning the VR Robot in the goal space.
• Finally: The VR Robot will use the Electromagnet to drop the disk into the goal.

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