Telémetro#
Introducción#
The sonar class is used to measure distances and detects objects in front with the Range Finder.
Constructor de clases#
sonar(
triport::port &port);
Instructor de clase#
Destroys the sonar object and releases associated resources.
virtual ~sonar();
Parámetros#
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The first 3-Wire Port of a required two-port group used by the Range Finder. The Range Finder occupies two adjacent ports (A–B, C–D, E–F, or G–H) on either the Brain or a 3-Wire Expander. Specify the first port in the pair (A, C, E, or G), written as |
Ejemplos#
// Create a sonar instance in Ports A and B
sonar RangeFinderA = sonar(Brain.ThreeWirePort.A);
Funciones de los miembros#
The sonar class includes the following member functions:
foundObject— Returns whether an object is detected by the Range Finder.distance— Returns the distance of a detected object from the Range Finder.
Before calling any sonar member functions, a sonar instance must be created, as shown below:
/* This constructor is required when using VS Code.
Range Finder configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a sonar instance in Ports A and B
sonar RangeFinderA = sonar(Brain.ThreeWirePort.A);
foundObject#
Devuelve un valor booleano que indica si el buscador de rangos encuentra un objeto.
Available Functionsbool foundObject();
Esta función no acepta ningún parámetro.
Return ValuesReturns a bool representing if an object is detected:
true— An object is found.false— An object is not found.
// Check if an object is detected.
if (RangeFinderA.foundObject()){
// Print to screen on the brain that an object was found.
Brain.Screen.print("object found");
}
distance#
Devuelve la distancia actual a la que el telémetro detecta un objeto.
Available Functionsdouble distance(
distanceUnits units );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The unit that represents the distance:
|
Returns a double representing the distance in the specified units.
// Get the Range Finder distance in millimeters.
double value = RangeFinderA.distance(mm);
// Print the current distance detected by the Range Finder to the
// Brain's screen.
Brain.Screen.print(value);