Travel Distance
Using the Front Distance Sensor to navigate the VR Robot to collect as much trash as possible in one minute, find the total number of the collected trash pieces and calculate the total travel distance of the robot.
- Select the Coral Reef Cleanup Playground.
- Code the VR Robot to collect as much trash as possible in one minute, count the number of trash pieces, and calculate the travel distance of the robot.
- Set up a timer to time the process.
- Declare variables to store the number of trash pieces and the travel distance.
- Set desired turn velocity. Use the [Turn] block to keep rotating the Drivetrain and use the Front Distance Sensor to check for trash.
- If the Front Distance Sensor detects a piece of trash, drive the VR Robot to the trash to collect it, count the drive distance, and count the number of trash pieces.
- Use the [Forever] block to keep the VR Robot constantly checking for and collecting trash.
- If one minute time runs out, exit the repeating loop immediately.
- Use the [print] block to print the total number of trash pieces and the total travel distance of the robot to the Print Console.
Helpful Hints
Use the FrontDistance found object block from the Sensing category to report if the Front Distance Sensor detects an object within its field of view.

Matching Python command:
front_distance.found_object()
Use the FrontDistance Reporter block from the Sensing category to get the distance of the nearest object from the Distance Sensor.

Matching Python command:
front_distance.get_distance(MM)
Use the reset timer block from the Sensing category to reset the timer back to 0 seconds at the beginning of your project.

Matching Python command:
brain.timer.clear()
Use the if then block from the Control category to check if the Front Distance Sensor detects a piece of trash and if the one minute time runs out.

Matching Python command:
if condition:
Use the Forever block from the Control category to keep the VR Robot constantly checking for and collecting trash.

Matching Python command:
while True:
Use the break block from the Control category to exit a repeating loop immediately.

Matching Python command:
break