Sensor de distancia#
Introducción#
The sonar class is used with the VEX IQ Distance Sensor (1st gen). The distance class is used with the VEX IQ Distance Sensor (2nd gen).
Ambos sensores de distancia pueden detectar si un objeto se encuentra frente a ellos e indicar su distancia. El sensor de distancia VEX IQ (2.ª generación) también puede indicar la velocidad relativa del objeto detectado y estimar si este es pequeño, mediano o grande.
Constructores de clases#
1 — Este constructor crea un sensor de distancia VEX IQ (1.ª generación).
sonar( int32_t index);
2 — Este constructor crea un sensor de distancia VEX IQ (2.ª generación).
distance( int32_t index);
Instructor de clase#
Destroys the distance object and releases associated resources.
1 — Destruye un sensor de distancia VEX IQ (1.ª generación).
~sonar();
2 — Destruye un sensor de distancia VEX IQ (2.ª generación).
~distance();
Parámetros#
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The Smart Port that the Distance Sensor is connected to, written as |
Ejemplos#
1 — Crea una instancia de VEX IQ Distance Sensor (1.ª generación) en el puerto 1.
sonar Distance1 = sonar(PORT1);
2 — Crea una instancia de VEX IQ Distance Sensor (2nd gene) en el puerto 1.
distance Distance1 = distance(PORT1);
Funciones de los miembros#
The sonar class includes the following member functions:
foundObject— Returns whether the Distance Sensor currently detects an object.distance— Returns the distance between the Distance Sensor and the nearest detected object.
The distance class includes the following member functions:
objectDistance— Returns the distance between the Distance Sensor and the nearest detected object.objectVelocity— Returns how quickly the detected object is moving toward or away from the Distance Sensor.objectSize— Returns the estimated size of the detected object.isObjectDetected— Returns whether the Distance Sensor currently detects an object.changed— Registers a callback function that runs when the detected distance value changes.installed— Returns whether the Distance Sensor is installed and connected.
Before calling any distance or sonar member functions, a distance or sonar instance must be created, as shown below:
/* This constructor is required when using VS Code.
Distance Sensor configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a VEX IQ Distance Sensor (2nd gen) instance in Port 1
distance Distance1 = distance(PORT1);
foundObject#
Indica si el sensor de distancia detecta actualmente un objeto.
Available Functionsbool foundObject();
Esta función no requiere ningún parámetro.
Return ValuesDevuelve un valor booleano que indica si el sensor de distancia detecta un objeto:
-
true— The Distance Sensor detects an object. -
false— The Distance Sensor does not detect an object.
distance#
Devuelve la distancia entre el sensor de distancia y el objeto detectado más cercano.
Available Functionsdouble distance( distanceUnits units );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The distance unit:
|
Returns a double representing the distance between the Distance Sensor and the nearest detected object in the specified units.
objectDistance#
Devuelve la distancia entre el sensor de distancia y el objeto detectado más cercano.
Available Functionsdouble objectDistance( distanceUnits units );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The distance unit:
|
Returns a double representing the distance between the Distance Sensor and the nearest detected object in the specified units.
objectVelocity#
Devuelve la velocidad relativa del objeto detectado.
La velocidad indica la rapidez con la que el objeto se acerca o se aleja del sensor de distancia. Un valor cercano a 0 significa que el objeto no se mueve mucho con respecto al sensor.
Available Functionsdouble objectVelocity();
Esta función no requiere ningún parámetro.
Return ValuesReturns a double representing the relative velocity of the detected object in m/s (meters per second).
objectSize#
Devuelve el tamaño estimado del objeto detectado por el sensor de distancia.
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.
Available FunctionssizeType objectSize();
Esta función no requiere ningún parámetro.
Return ValuesReturns a sizeType indicating the estimated size of the detected object:
-
none— No object is detected. -
small— A small object is detected. -
medium— A medium object is detected. -
large— A large object is detected.
isObjectDetected#
Indica si el sensor de distancia detecta actualmente un objeto.
Available Functionsbool isObjectDetected();
Esta función no requiere ningún parámetro.
Return ValuesDevuelve un valor booleano que indica si el sensor de distancia detecta un objeto:
-
true— The Distance Sensor detects an object. -
false— The Distance Sensor does not detect an object.
changed#
Registra una función de devolución de llamada que se ejecuta cuando cambia el valor de distancia detectado.
Available Functionsvoid changed( void (* callback)(void) );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
A pointer to a function that will be called when the detected distance value changes. The function must take no parameters and return |
Esta función no devuelve ningún valor.
Notes - This is a VEX IQ Distance Sensor (1st gen) or (2nd gen) function.installed#
Indica si el sensor de distancia está instalado y conectado.
Available Functionsbool installed();
Esta función no requiere ningún parámetro.
Return ValuesDevuelve un valor booleano que indica si el sensor de distancia está instalado y conectado:
-
true— The Distance Sensor is installed and connected. -
false— The Distance Sensor is not installed or not connected.