Skip to main content

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.

    VEXcode Distance found object block that reads 'FrontDistance found an object?'.

    • 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.

    VEXcode Distance from block that reads 'FrontDistance in mm'.

    • 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.

    VEXcode Reset timer block that reads 'reset timer'.

    • 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.

    Empty VEXcode If then block that reads 'if then'.

    • Matching Python command:

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

    Empty VEXcode Forever block that reads 'forever'.

    • Matching Python command:

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

    VEXcode Break block that reads 'break'.

    • Matching Python command:

      break