Sensor de objetos#
Introducción#
El Sensor de objetos es un sensor de proximidad infrarrojo que detecta cuando un objeto está cerca mediante luz infrarroja reflejada.

This page uses object_sensor as the example Object Sensor name. Replace it with your own configured name as needed.
A continuación se muestra una lista de los métodos disponibles:
reflectivity– Returns the amount of light reflected from the object.set_threshold– Sets the amount of reflected light needed before an object is considered to be detected.is_object_detected– Returns whether the Object Sensor is detecting an object.changed– Registers a function to be called whenever the Object Sensor’s value changes.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.
Constructor – Inicializa manualmente un sensor de objetos.
ObjectDetector– Create an Object Sensor.
reflectividad#
reflectivity returns the amount of light reflected from the object as a percent.
Nota:
Un 0 % de reflectividad significa que el objeto es muy oscuro. El sensor detecta un valor bruto de 3000 o superior.
Una reflectividad del 100 % significa que el objeto es muy brillante. El sensor detecta un valor bruto de 0.
Usage:
object_sensor.reflectivity()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# 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)
establecer_umbral#
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)
Parámetros |
Descripción |
|---|---|
|
El valor de reflectividad necesario antes de que se considere que un objeto ha sido detectado, de 0 a 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)
se ha detectado un objeto#
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()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# 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)
cambió#
changed registers a function to be called whenever the Object Sensor’s value changes.
Usage:
object_sensor.changed(callback, arg)
Parámetros |
Descripción |
|---|---|
|
Una función previamente definida que se ejecuta cuando cambia el valor del sensor de objetos. |
|
Opcional. Una tupla que contiene los argumentos que se pasan a la función de devolución de llamada. Consulte Funciones con parámetros para obtener más información. |
def my_function():
brain.screen.print("Reflectivity changed.")
# Call my_function whenever object_sensor's value changes
object_sensor.changed(my_function)
objeto_detectado#
object_detected registers a function to be called whenever the Object Sensor detects a new object.
Usage:
object_sensor.object_detected(callback, arg)
Parámetros |
Descripción |
|---|---|
|
Una función previamente definida que se ejecuta cuando el sensor de objetos detecta un nuevo objeto. |
|
Opcional. Una tupla que contiene los argumentos que se pasan a la función de devolución de llamada. Consulte Funciones con parámetros para obtener más información. |
def my_function():
brain.screen.print("Object detected.")
# Call my_function whenever object_sensor detects an object
object_sensor.object_detected(my_function)
objeto_perdido#
object_lost registers a function to be called whenever the Object Sensor loses a detected object.
Usage:
object_sensor.object_lost(callback, arg)
Parámetros |
Descripción |
|---|---|
|
Una función previamente definida que se ejecuta cuando el sensor de objetos pierde un objeto detectado. |
|
Opcional. Una tupla que contiene los argumentos que se pasan a la función de devolución de llamada. Consulte Funciones con parámetros para obtener más información. |
def my_function():
brain.screen.print("Object lost.")
# Call my_function whenever object_sensor loses an object
object_sensor.object_lost(my_function)
Constructores#
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)
Parámetro |
Descripción |
|---|---|
|
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)