Distance#

Introduction#

The Distance Sensor allows the robot to detect the presence of an object and measure its distance.

Below is a list of all available methods:

Getters – Return if objects are detected and their distances.

  • found_object – Return a Boolean indicating if an object is detected.

  • get_distance – Return the distance of the closest object to the Distance Sensor.

Getters#

found_object#

found_object returns a Boolean indicating whether or not an object is detected by the Distance Sensor.

  • True – An object is detected.

  • False – An object is not detected.

Usage:
distance.found_object()

Parameters

Description

This method has no parameters.

def main():
    # Stop turning when an object is detected
    drivetrain.turn(RIGHT)
    while True:
        wait(5, MSEC)
        if front_distance.found_object():
            drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)

get_distance#

get_distance returns the distance of the object closest to the Distance Sensor.

Usage:
distance.get_distance(units)

Parameters

Description

units

The unit that represents the distance:

  • INCHES
  • MM – millimeters
def main():
    # Drive forward until an object is 200 mm away
    while front_distance.get_distance(MM) > 200:
        wait(5, MSEC)
        drivetrain.drive(FORWARD)
    drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)