Sensor de objetos#

Introducción#

El Sensor de Objetos es un sensor de proximidad infrarrojo (IR) que detecta la proximidad de un objeto mediante la luz infrarroja reflejada.

El sensor de objetos VEX.

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.

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

Constructor: Inicializa manualmente un sensor de objetos.

reflectividad#

reflectivity returns the amount of light reflected from the object as a percent.

Nota:

  • Una reflectividad del 0% 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)

is_object_detected#

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)

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

value

El valor de reflectividad requerido para que un objeto se considere 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)

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

callback

Una función definida previamente que se ejecuta cuando el sensor de objetos detecta un nuevo objeto.

arg

Opcional. Una tupla que contiene los argumentos que se pasarán 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

callback

Una función definida previamente que se ejecuta cuando el sensor de objetos pierde un objeto detectado.

arg

Opcional. Una tupla que contiene los argumentos que se pasarán 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)

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

callback

Una función definida previamente que se ejecuta cuando cambia el valor del sensor de objetos.

arg

Opcional. Una tupla que contiene los argumentos que se pasarán 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)

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

port

The 3-Wire Port that the Object Sensor is connected to:

  • On the EXP Brainbrain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expanderexpander.a where expander is the name of the expander instance.

reverse_det

Optional. Whether to reverse the detection logic:

  • True – When an object is lost, return that an object is detected, and when an object is detected, return that it is lost.
  • False (default) – When an object is lost, return that an object is lost, and when an object is detected, return that it is detected.

# Create an Object Sensor in Port A
object_sensor = ObjectDetector(brain.three_wire_port.a)