Distance#

Introduction#

The Distance Sensor can detect whether an object is in front of the sensor and return how far away that object is.

Below is a list of all available methods:

Getters — Return whether an object is detected and how far away it is.

  • found_object — Returns whether the Distance Sensor currently detects an object.

  • get_distance — Returns the distance between the Distance Sensor and the nearest detected object.

Getters#

found_object#

found_object returns whether the Distance Sensor currently detects an object.

  • True — The Distance Sensor detects an object.

  • False — The Distance Sensor does not detect an object.

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 between the Distance Sensor and the nearest detected object.

Usage:
distance.get_distance(units)

Parameters

Description

units

The distance unit: MM or INCHES.

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)