Skip to main content

The Trash Picker

Use [Drive for] and [Turn] blocks, and the Front Distance Sensor to drive the VR Robot to collect as much trash as possible before the batteries run out.

  • Select the Coral Reef Cleanup Playground.
  • Code the VR Robot to collect as much trash as possible before the batteries run out.
    • 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 for the distance between the robot and the piece of trash to collect it.
    • Use the [Forever] block to keep the VR Robot constantly checking for and collecting trash.

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 if then block from the Control category to check if the Front Distance Sensor detects a piece of trash and run the code to collect the piece of trash if the Boolean condition is true.

    Empty VEXcode If then block containing a boolean Distance found object block that reads all together 'if FrontDistance found an object then'.

    • Matching Python command:

      if front_distance.found_object():
  • 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: