Απόσταση#

Εισαγωγή#

Ο αισθητήρας απόστασης μπορεί να ανιχνεύσει εάν ένα αντικείμενο βρίσκεται μπροστά από τον αισθητήρα και να επιστρέψει την απόσταση που βρίσκεται αυτό το αντικείμενο.

Παρακάτω είναι μια λίστα με όλες τις διαθέσιμες μεθόδους:

Getters — Επιστρέφει εάν ένα αντικείμενο ανιχνεύεται και σε ποια απόσταση βρίσκεται.

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

Αποκτητές#

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()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

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)

Παράμετροι

Περιγραφή

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)