Αισθητήρας αντικειμένων#
Εισαγωγή#
Ο Αισθητήρας Αντικειμένου είναι ένας αισθητήρας εγγύτητας υπέρυθρης (IR) που ανιχνεύει πότε ένα αντικείμενο είναι κοντά χρησιμοποιώντας ανακλώμενο υπέρυθρο φως.

This page uses object_sensor as the example Object Sensor name. Replace it with your own configured name as needed.
Παρακάτω είναι μια λίστα με τις διαθέσιμες μεθόδους:
reflectivity– Returns anintegerthat represents the amount of light reflected from the object as a percent.is_object_detected– Returns whether the Object Sensor is detecting an object.set_threshold– Sets the amount of reflected light needed before an object is considered to be detected.object_detected– Registers a function to be called whenever the Object Sensor detects a new object.object_lost– Registers a function to be called whenever the Object Sensor loses a detected object.changed– Registers a function to be called whenever the Object Sensor’s value changes.
Κατασκευαστής – Χειροκίνητη αρχικοποίηση ενός αισθητήρα αντικειμένων.
ObjectDetector– Create an Object Sensor.
ανακλαστικότητα#
reflectivity returns an integer that represents the amount of light reflected from the object as a percent.
Σημείωμα:
Η ανακλαστικότητα 0% σημαίνει ότι το αντικείμενο είναι πολύ σκοτεινό. Ο αισθητήρας βλέπει μια ακατέργαστη τιμή 3000 ή υψηλότερη.
Η ανακλαστικότητα 100% σημαίνει ότι το αντικείμενο είναι πολύ φωτεινό. Ο αισθητήρας βλέπει μια ακατέργαστη τιμή 0.
Usage:
object_sensor.reflectivity()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Drive forward when the reflectivity is greater than 50%.
while True:
if object_sensor.reflectivity() > 50:
drivetrain.drive(FORWARD)
else:
drivetrain.stop()
wait(5, MSEC)
ανιχνεύτηκε_αντικείμενο#
is_object_detected returns whether the Object Sensor is detecting an object.
True– The Object Sensor is detecting an object.False– The Object Sensor is not detecting an object.
Usage:
object_sensor.is_object_detected()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Drive forward when the object sensor is detecting an object.
while True:
if object_sensor.is_object_detected():
drivetrain.drive(FORWARD)
else:
drivetrain.stop()
wait(5, MSEC)
set_threshold#
set_threshold sets the amount of reflected light needed as a percent before an object is considered to be detected.
Usage:
object_sensor.set_threshold(value)
Παράμετροι |
Περιγραφή |
|---|---|
|
Η ποσότητα ανακλώμενου φωτός που απαιτείται για να θεωρηθεί ένα αντικείμενο ως ακέραιος αριθμός, από το 0 έως το 100. |
# Set the reflectivity threshold to 50%.
object_sensor.set_threshold(50)
# Drive forward when the object sensor is detecting an object.
while True:
if object_sensor.is_object_detected():
drivetrain.drive(FORWARD)
else:
drivetrain.stop()
wait(5, MSEC)
ανιχνευμένο_αντικείμενο#
object_detected registers a function to be called whenever the Object Sensor detects a new object.
Usage:
object_sensor.object_detected(callback, arg)
Παράμετροι |
Περιγραφή |
|---|---|
|
Μια προηγουμένως καθορισμένη συνάρτηση που εκτελείται όταν ο Αισθητήρας Αντικειμένου ανιχνεύει ένα νέο αντικείμενο. |
|
Optional. A |
def my_function():
brain.screen.print("Object detected.")
# Call my_function whenever object_sensor detects an object
object_sensor.object_detected(my_function)
αντικείμενο_χαμένο#
object_lost registers a function to be called whenever the Object Sensor loses a detected object.
Usage:
object_sensor.object_lost(callback, arg)
Παράμετροι |
Περιγραφή |
|---|---|
|
Μια προηγουμένως καθορισμένη συνάρτηση που εκτελείται όταν ο Αισθητήρας Αντικειμένου χάνει ένα ανιχνευμένο αντικείμενο. |
|
Optional. A |
def my_function():
brain.screen.print("Object lost.")
# Call my_function whenever object_sensor loses an object
object_sensor.object_lost(my_function)
άλλαξε#
changed registers a function to be called whenever the Object Sensor’s value changes.
Usage:
object_sensor.changed(callback, arg)
Παράμετροι |
Περιγραφή |
|---|---|
|
Μια προηγουμένως ορισμένη συνάρτηση που εκτελείται όταν αλλάζει η τιμή του Αισθητήρα Αντικειμένου. |
|
Optional. A |
def my_function():
brain.screen.print("Reflectivity changed.")
# Call my_function whenever object_sensor's value changes
object_sensor.changed(my_function)
Κατασκευαστές#
Constructors are used to manually create ObjectDetector objects, which are necessary for configuring Object Sensors.
ObjectDetector#
ObjectDetector creates an Object Sensor.
Usage:
ObjectDetector(port, reverse_det)
Παράμετρος |
Περιγραφή |
|---|---|
|
The 3-Wire Port that the Object Sensor is connected to:
|
|
Optional. Whether to reverse the detection logic:
|
# Create an Object Sensor in Port A
object_sensor = ObjectDetector(brain.three_wire_port.a)