Απόσταση#
Εισαγωγή#
Ο αισθητήρας απόστασης μπορεί να ανιχνεύσει εάν ένα αντικείμενο βρίσκεται μπροστά από τον αισθητήρα και να επιστρέψει την απόσταση που βρίσκεται αυτό το αντικείμενο.
Ο αισθητήρας απόστασης VEX IQ (1ης γενιάς) χρησιμοποιεί σόναρ για την ανίχνευση αντικειμένων και τη μέτρηση της απόστασης. Ο αισθητήρας απόστασης VEX IQ (2ης γενιάς) χρησιμοποιεί ένα λέιζερ ασφαλές για σχολική τάξη και μπορεί επίσης να επιστρέψει τη σχετική ταχύτητα του ανιχνευμένου αντικειμένου και να εκτιμήσει εάν το αντικείμενο είναι μικρό, μεσαίο ή μεγάλο.
This page uses distance_1 as the example Distance Sensor name. Replace it with your own configured name as needed.
Παρακάτω είναι μια λίστα με όλες τις διαθέσιμες μεθόδους:
Λήπτες — Επιστρέφουν δεδομένα από τον αισθητήρα απόστασης.
is_object_detected— (VEX IQ Distance Sensor (1st gen) or (2nd gen)) Returns whether the Distance Sensor currently detects an object.distance— (VEX IQ Distance Sensor (1st gen)) Returns the distance between the Distance Sensor and the nearest detected object.object_distance— (VEX IQ Distance Sensor (2nd gen)) Returns the distance between the Distance Sensor and the nearest detected object.object_velocity— (VEX IQ Distance Sensor (2nd gen)) Returns how quickly the detected object is moving toward or away from the Distance Sensor.object_size— (VEX IQ Distance Sensor (2nd gen)) Returns the estimated size of the detected object.installed— (VEX IQ Distance Sensor (1st gen) or (2nd gen)) Returns whether the Distance Sensor is installed and connected.
Κατασκευαστές — Μη αυτόματη αρχικοποίηση και διαμόρφωση ενός αισθητήρα απόστασης.
Αποκτητές#
is_object_detected#
is_object_detected returns whether the Distance Sensor currently detects an object within range.
True— The Distance Sensor detects an object.False— The Distance Sensor does not detect an object.
Usage:
distance_1.is_object_detected()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Turn until an object is detected
drivetrain.turn(RIGHT)
while not distance_1.is_object_detected():
wait(15, MSEC)
drivetrain.stop()
brain.screen.print("Object detected!")
distance#
distance returns the distance between the Distance Sensor and the nearest detected object as a decimal (float).
Σημείωση: Αυτή είναι μια μέθοδος αισθητήρα απόστασης VEX IQ (1ης γενιάς).
Usage:
distance_1.distance(units)
Παράμετροι |
Περιγραφή |
|---|---|
|
Optional. The distance unit: |
# Display the distance to an object
if distance_1.is_object_detected():
print("Distance: ")
print(distance_1.distance(MM))
else:
print("No object detected")
object_distance#
object_distance returns the distance between the Distance Sensor and the nearest detected object as a decimal (float).
Σημείωση: Αυτή είναι μια μέθοδος αισθητήρα απόστασης VEX IQ (2ης γενιάς).
Usage:
distance_1.object_distance(units)
Παράμετροι |
Περιγραφή |
|---|---|
|
Optional. The distance unit: |
# Drive forward until an object is 200 mm away
while distance_1.object_distance(MM) > 200:
drivetrain.drive(FORWARD)
drivetrain.stop()
object_velocity#
object_velocity returns the relative velocity of the detected object as a decimal (float) in m/s (meters per second).
Η ταχύτητα δείχνει πόσο γρήγορα κινείται το αντικείμενο προς ή μακριά από τον αισθητήρα απόστασης. Μια θετική τιμή σημαίνει ότι το αντικείμενο κινείται προς τον αισθητήρα απόστασης. Μια αρνητική τιμή σημαίνει ότι το αντικείμενο απομακρύνεται. Μια τιμή κοντά στο 0 σημαίνει ότι το αντικείμενο δεν κινείται πολύ σε σχέση με τον αισθητήρα.
Σημείωση: Αυτή είναι μια μέθοδος αισθητήρα απόστασης VEX IQ (2ης γενιάς).
Usage:
distance_1.object_velocity()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Display the velocity of a moving object
while True:
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
brain.screen.print("Velocity: ")
brain.screen.print(distance_1.object_velocity())
wait(100, MSEC)
object_size#
object_size returns the estimated size of the object detected by the Distance Sensor.
Ο αισθητήρας απόστασης εκτιμά το μέγεθος του αντικειμένου με βάση το πόσο μεγάλο μέρος της ορατότητας του αισθητήρα καταλαμβάνεται από το ανιχνευόμενο αντικείμενο.
ObjectSizeType.NONE— No object is detected.ObjectSizeType.SMALL— A small object is detected.ObjectSizeType.MEDIUM— A medium object is detected.ObjectSizeType.LARGE— A large object is detected.
Σημείωση: Αυτή είναι μια μέθοδος αισθητήρα απόστασης VEX IQ (2ης γενιάς).
Usage:
distance_1.object_size()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
installed#
installed returns whether the Distance Sensor is installed and connected.
True— The Distance Sensor is installed and connected.False— The Distance Sensor is not installed or not connected.
Usage:
distance_1.installed()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
Κατασκευαστές#
Constructors are used to manually create Distance and Sonar objects, such as when configuring a Distance Sensor outside of VEXcode.
Sonar#
Sonar creates a VEX IQ Distance Sensor (1st gen) object.
Usage:
distance_1 = Sonar(smartport)
Παράμετρος |
Περιγραφή |
|---|---|
|
The Smart Port that the Distance Sensor is connected to, written as |
# Create a Sonar object in Port 1
distance_1 = Sonar(Ports.PORT1)
Distance#
Distance creates a VEX IQ Distance Sensor (2nd gen) object.
Usage:
distance_1 = Distance(smartport)
Παράμετρος |
Περιγραφή |
|---|---|
|
The Smart Port that the Distance Sensor is connected to, written as |
# Create a Distance object in Port 1
distance_1 = Distance(Ports.PORT1)