distancia#
Inicializando la clase de distancia#
Un sensor de distancia se crea utilizando el siguiente constructor:
The distance constructor creates an object of the distance Class in the specified port.
Parámetro |
Descripción |
|---|---|
|
A valid |
// Construct a Distance Sensor "Distance" with the
// distance class.
distance Distance1 = distance(PORT1);
This Distance1 object will be used in all subsequent examples throughout this API documentation when referring to distance class methods.
Métodos de clase#
objectDistance()#
The objectDistance(units) method returns the distance the Distance Sensor is currently reading. The Distance Sensor will return a large positive number if no object is detected.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devuelve: Un doble que representa la distancia al objeto detectado en las unidades especificadas.
// Get the distance detected by the Distance Sensor in inches.
double value = Distance1.objectDistance(inches);
objectSize()#
The objectSize() method returns an estimate of the size of the detected object.
Returns: A sizeType representing the estimated size of the detected object.
// Get the object size detected by the Distance Sensor.
sizeType size = Distance1.objectSize();
objectVelocity()#
The objectVelocity() method returns the velocity of the detected object. The velocity is calculated by the change in distance over the change in time.
Devuelve: Un doble que representa la velocidad del objeto detectado en metros por segundo.
isObjectDetected()#
The isObjectDetected() method returns if an object is detected.
Returns: true if an object is detected. false if an object is not detected.
changed()#
The changed(callback) method registers a callback function for when the detected object changes.
Parámetros |
Descripción |
|---|---|
|
Una función que se llamará cuando el objeto detectado cambie. |
Devoluciones: Ninguna.
// Define the distanceChanged function with a void return
// type, showing it doesn't return a value.
void distanceChanged() {
// The Brain will print that the distance changed on the
// Brain's screen.
Brain.Screen.print("distance changed");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Drive the robot forward.
Drivetrain.drive(forward);
// Run distanceChanged when the value of the distance
// detected by the Distance Sensor changes.
Distance1.changed(distanceChanged);
}
objectRawSize()#
The objectRawSize() method returns the raw value of object size the Distance Sensor is detecting.
Devuelve: Un entero con signo de 32 bits que representa el tamaño sin procesar del objeto detectado.
// Get the raw size of the object detected by the distance sensor.
int32_t size = Distance1.objectRawSize();
timestamp()#
The timestamp() method requests the timestamp of the last received status packet from the Distance Sensor.
Devuelve: Marca de tiempo del último paquete de estado como un entero de 32 bits sin signo en milisegundos.
installed()#
The installed() method returns if the Distance Sensor is connected.
Returns: true if the Distance Sensor is connected. false if it is not.