Αισθητήρας απόστασης#
Εισαγωγή#
Ο Αισθητήρας Απόστασης μπορεί να ανιχνεύσει εάν ένα αντικείμενο βρίσκεται μπροστά από τον αισθητήρα και να επιστρέψει την απόσταση που βρίσκεται αυτό το αντικείμενο. Μπορεί επίσης να επιστρέψει τη σχετική ταχύτητα του ανιχνευμένου αντικειμένου και να εκτιμήσει εάν το αντικείμενο είναι μικρό, μεσαίο ή μεγάλο.
Ο αισθητήρας απόστασης λειτουργεί σε εύρος από 20 mm έως 2000 mm.
Κάτω από 200 mm, η ακρίβεια είναι περίπου ±15 mm. Πάνω από 200 mm, η ακρίβεια βελτιώνεται σε περίπου 5%.
Ο αισθητήρας απόστασης χρησιμοποιεί λέιζερ Κλάσης 1. Η ανίχνευση κατευθύνεται κατευθείαν μπροστά και είναι ασφαλής για την τάξη.

This page uses distance_sensor as the example Distance Sensor name. Replace it with your own configured name as needed.
Παρακάτω είναι μια λίστα με τις διαθέσιμες μεθόδους:
object_distance— Returns the distance between the Distance Sensor and the nearest detected object.object_velocity— Returns how quickly the detected object is moving toward or away from the Distance Sensor.object_size— Returns the estimated size of the detected object.is_object_detected— Returns whether the Distance Sensor currently detects an object.changed— Registers a function to run whenever the Distance Sensor’s value changes.
Κατασκευαστής — Μη αυτόματη αρχικοποίηση ενός αισθητήρα απόστασης.
Distance— Creates a Distance Sensor.
απόσταση_αντικειμένου#
object_distance returns the distance between the Distance Sensor and the nearest detected object as a decimal (float).
Usage:
distance_sensor.object_distance(units)
Παράμετροι |
Περιγραφή |
|---|---|
|
Optional. The distance unit: |
# Drive forward until the object is within 50 mm away
drivetrain.drive(FORWARD)
while not distance_sensor.object_distance(MM) < 50:
pass
drivetrain.stop()
ταχύτητα_αντικειμένου#
object_velocity returns the relative velocity of the detected object as a decimal (float) in m/s (meters per second).
Η ταχύτητα δείχνει πόσο γρήγορα κινείται το αντικείμενο προς ή μακριά από τον αισθητήρα απόστασης. Μια τιμή κοντά στο 0 σημαίνει ότι το αντικείμενο δεν κινείται πολύ σε σχέση με τον αισθητήρα.
Usage:
distance_sensor.object_velocity()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
μέγεθος_αντικειμένου#
object_size returns the estimated size of the object detected by the Distance Sensor.
Ο αισθητήρας απόστασης εκτιμά το μέγεθος του αντικειμένου με βάση το πόσο μεγάλο μέρος της ορατότητας του αισθητήρα καταλαμβάνεται από το ανιχνευόμενο αντικείμενο.
ObjectSizeType(0, “NONE”)— No object is detected.ObjectSizeType(1, “SMALL”)— A small object is detected.ObjectSizeType(2, “MEDIUM”)— A medium object is detected.ObjectSizeType(3, “LARGE”)— A large object is detected.
Usage:
distance_sensor.object_size()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
ανιχνεύτηκε_αντικείμενο#
is_object_detected 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_sensor.is_object_detected()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Drive forward until the object is within 50 mm away
while True:
drivetrain.drive(FORWARD)
if distance_sensor.is_object_detected():
if distance_sensor.object_distance(MM) < 50:
drivetrain.stop()
break
άλλαξε#
changed registers a function to be called whenever the Distance Sensor’s value changes.
Usage:
distance_sensor.changed(callback, arg)
Παράμετροι |
Περιγραφή |
|---|---|
|
Μια προηγουμένως ορισμένη συνάρτηση που εκτελείται όταν αλλάζει η τιμή του αισθητήρα απόστασης. |
|
Προαιρετικό. Μια πλειάδα που περιέχει ορίσματα για να μεταβιβαστούν στη συνάρτηση επανάκλησης. Δείτε Χρήση Συναρτήσεων με Παραμέτρους για περισσότερες πληροφορίες. |
def my_function():
brain.screen.print("Distance changed")
# Call my_function whenever distance_sensor's value changes
distance_sensor.changed(my_function)
Κατασκευαστής#
Constructors are used to manually create Distance objects, such as when configuring a Distance Sensor outside of VEXcode.
Distance#
Distance creates a Distance Sensor object.
Usage:
Distance(smartport)
Παράμετρος |
Περιγραφή |
|---|---|
|
The Smart Port that the Distance Sensor is connected to, written as |
# Create a Distance Sensor in Port 10
distance_sensor = Distance(Ports.PORT10)