Sensor de objetos#
Introducción#
The objectdetector class is used to measure reflectivity and detect objects by the Object Sensor.
Constructor de clases#
objectdetector(
triport::port &port,
bool bReverse = false );
Instructor de clase#
Destroys the objectdetector object and releases associated resources.
virtual ~objectdetector();
Parámetros#
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The 3-Wire Port that the Object Sensor is connected to, written as |
|
|
An optional boolean to reverse the direction of the Object Sensor:
|
Ejemplos#
// Create an objectdetector instance in Port A
objectdetector ObjectSensorA = objectdetector(Brain.ThreeWirePort.A, true);
Funciones de los miembros#
The objectdetector class includes the following member functions:
reflectivity— Returns the reflectivity detected by the Object Sensor.isObjectDetected— Returns whether the Object Sensor detects an object.setDetectionThreshold— Sets the detection range of the Object Sensor.objectDetected— Registers a function to be called when the Object Sensor detects an object.objectLost— Registers a function to be called when the Object Sensor loses an object.
Before calling any objectdetector member functions, a objectdetector instance must be created, as shown below:
// Create an objectdetector instance in Port A
objectdetector ObjectSensorA = objectdetector(Brain.ThreeWirePort.A, true);
reflectivity#
Devuelve la reflectividad medida por el sensor de objetos.
Available Functionsint32_t reflectivity(
percentUnits units = percentUnits::pct );
Parámetros |
Tipo |
Descripción |
|---|---|---|
|
|
The unit that represents the reflectivity:
|
Returns an int32_t representing the reflectivity measured by the Object Detector as a percent in the range 0 - 100%.
// Display the detected reflectivity on the Brain's screen
int32_t value = ObjectSensorA.reflectivity();
Brain.Screen.print(value);
isObjectDetected#
Indica si el detector de objetos detecta actualmente algún objeto.
Available Functionsbool isObjectDetected();
Esta función no requiere ningún parámetro.
Return ValuesDevuelve un valor booleano que indica si se ha detectado un objeto:
-
true— An object is detected. -
false— No object is detected.
setDetectionThreshold#
Establece el umbral de detección del detector de objetos a un valor específico.
Available Functionsvoid setDetectionThreshold(
int32_t threshold,
percentUnits units = percentUnits::pct );
Parámetros |
Tipo |
Descripción |
|---|---|---|
|
|
El umbral de reflectividad para la detección de objetos se encuentra en el rango de 0 a 100. |
|
|
The unit that represents the new threshold:
|
Esta función no devuelve ningún valor.
Examples// Set the reflectivity threshold to 50%
ObjectSensorA.setDetectionThreshold(50);
objectDetected#
Registra una función de devolución de llamada para cuando se detecta un objeto.
Available Functionsvoid objectDetected(void (* callback)(void));
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
La función de devolución de llamada que se invocará cuando se detecte un objeto. |
Esta función no devuelve ningún valor.
Examplesvoid detected() {
Brain.Screen.print("object detected");
}
// Run detected when the Object Detector detects an object
ObjectSensorA.objectDetected(detected);
objectLost#
Registra una función de devolución de llamada para cuando se pierde un objeto.
Available Functionsvoid objectLost(void (* callback)(void));
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
La función de devolución de llamada que se invocará cuando se pierda un objeto. |
Esta función no devuelve ningún valor.
Examplesvoid lost() {
Brain.Screen.print("object lost");
}
// Run lost when the Object Detector loses an object
ObjectSensorA.objectLost(lost);