Distancia#

Introducción#

El sensor de distancia puede detectar si hay un objeto delante del sensor e indicar a qué distancia se encuentra dicho objeto.

El sensor de distancia VEX IQ (1.ª generación) utiliza sonar para detectar objetos y medir distancias. El sensor de distancia VEX IQ (2.ª generación) utiliza un láser seguro para aulas y también puede proporcionar la velocidad relativa del objeto detectado y estimar si el objeto es pequeño, mediano o grande.

This page uses distance_1 as the example Distance Sensor name. Replace it with your own configured name as needed.

A continuación se muestra una lista de todos los métodos disponibles:

Obtenedores: devuelven datos del sensor de distancia.

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

Constructores: Inicialice y configure manualmente un sensor de distancia.

  • Sonar — Creates a VEX IQ Distance Sensor (1st gen).

  • Distance — Creates a VEX IQ Distance Sensor (2nd gen).

Captadores#

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()

Parámetros

Descripción

Este método no tiene parámetros.

# 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).

Nota: Este es un método del sensor de distancia VEX IQ (1.ª generación).

Usage:
distance_1.distance(units)

Parámetros

Descripción

units

Optional. The distance unit: MM (default, 24 mm to 1000 mm) or INCHES (1 inch to 40 inches).

# 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).

Nota: Este es un método del sensor de distancia VEX IQ (2.ª generación).

Usage:
distance_1.object_distance(units)

Parámetros

Descripción

units

Optional. The distance unit: MM (default, 20 mm to 2000 mm), INCHES (0.78 inches to 78 inches), or DistanceUnits.CM (2 cm to 200 cm).

# 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).

La velocidad indica la rapidez con la que el objeto se acerca o se aleja del sensor de distancia. Un valor positivo significa que el objeto se acerca al sensor, mientras que un valor negativo indica que se aleja. Un valor cercano a cero significa que el objeto apenas se mueve con respecto al sensor.

Nota: Este es un método del sensor de distancia VEX IQ (2.ª generación).

Usage:
distance_1.object_velocity()

Parámetros

Descripción

Este método no tiene parámetros.

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

El sensor de distancia estima el tamaño del objeto en función de la porción del campo de visión del sensor que ocupa el objeto detectado.

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

Nota: Este es un método del sensor de distancia VEX IQ (2.ª generación).

Usage:
distance_1.object_size()

Parámetros

Descripción

Este método no tiene parámetros.

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()

Parámetros

Descripción

Este método no tiene parámetros.

Constructores#

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)

Parámetro

Descripción

smartport

The Smart Port that the Distance Sensor is connected to, written as Ports.PORTx, where x is the port number.

# 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)

Parámetro

Descripción

smartport

The Smart Port that the Distance Sensor is connected to, written as Ports.PORTx, where x is the port number.

# Create a Distance object in Port 1
distance_1 = Distance(Ports.PORT1)