detector de objetos#

Inicializando la clase objectdetector#

Un sensor de objetos se crea utilizando el siguiente constructor:

El constructor objectdetector crea un objeto objectdetector en el puerto de tres cables especificado con el indicador inverso establecido en el valor especificado.

Parámetro

Descripción

puerto

El puerto de 3 cables al que está conectado el sensor de objetos, ya sea un puerto en el Cerebro o un Expandedor de 3 cables.

revertir

Configure esto para invertir la lógica de detección. El valor predeterminado es false.

Primero se debe crear un Brain o un 3-Wire Expander antes de poder usarlos para crear un objeto con el constructor de clase objectdetector.

// Create the Brain.
brain Brain;
// Construct an ObjectSensor "objdet" with the
// objectdetector class.
objectdetector objdet = objectdetector(Brain.ThreeWirePort.A, true);

Este objeto objdet se utilizará en todos los ejemplos posteriores a lo largo de esta documentación de API cuando se haga referencia a los métodos de la clase objectdetector.

Métodos de clase#

reflectividad()#

El método reflectivity(units) devuelve la reflectividad medida por el sensor de objetos. Esta reflectividad es una estimación basada en el valor bruto del sensor.

Una reflectividad del 0 % es un valor bruto de 3000 o superior. Una reflectividad del 100 % es un valor bruto de 0.

Parámetros

Descripción

unidades

La única unidad válida para la reflectividad es el “porcentaje”.

Devuelve: Un número entero que representa la reflectividad medida por el sensor de objetos en el rango de 0% a 100%.

// Get Object Sensor reflectivity in range of 0% - 100%.
int value = ObjectDetectorA.reflectivity();

// Print the reflectivity to the Brain's screen.
Brain.Screen.print(value);

establecerUmbralDeDetección()#

El método setDetectionThreshold(value, units) establece el umbral de detección para el sensor de objetos en un valor específico.

Parámetros

Descripción

valor

Umbral de reflectividad para la detección de objetos. Rango de 0 a 100.

unidades

La única unidad válida para la reflectividad es el “porcentaje”.

Devoluciones: Ninguna.

// Set the reflectivity threhold to 50%.
objdet.setDetectionThreshold(50);

esObjetoDetectado()#

El método isObjectDetected() regresa si se detecta un objeto.

Devuelve: true si se detecta un objeto. false si no se detecta ninguno.

cambió()#

El método changed(callback) registra una función de devolución de llamada cuando cambia el valor de un sensor de objetos.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando cambie el valor de un sensor de objetos.

Devoluciones: Ninguna.

// Define the detectorChanged function with a void return
// type, showing it doesn't return a value.
void detectorChanged() {
  // The Brain will print that the value of the Object Sensor
  // changed on the Brain's screen.
  Brain.Screen.print("Object Sensor value changed");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run detectorChanged when the value of the Object Sensor changes.
  objdet.changed(detectorChanged);
}

objetoDetectado()#

El método objectDetected(callback) registra una función de devolución de llamada cuando se detecta un objeto.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando se detecte un objeto.

Devoluciones: Ninguna.

// Define the detected function with a void return type,
// showing it doesn't return a value.
void detected() {
  // The Brain will print that the Object Sensor detected
  // an object to the Brain's screen.
  Brain.Screen.print("object detected");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run detected when the Object Sensor detects an object.
  objdet.objectDetected(detected);
}

objetoPerdido()#

El método objectLost(callback) registra una función de devolución de llamada para cuando se pierde un objeto.

Este es un método sin espera y permite que el siguiente método se ejecute sin demora.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando se pierda un objeto.

Devoluciones: Ninguna.

// Define the lost function with a void return type,
// showing it doesn't return a value.
void lost() {
  // The Brain will print that the Object Sensor
  // lost an object to the Brain's screen.
  Brain.Screen.print("object lost");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run lost when the Object Sensor loses an object.
  objdet.objectLost(lost);
}