visión#

El sensor de visión debe estar conectado a su V5 Brain y configurado en VEXcode V5 antes de poder usarlo.

Consulte estos artículos para obtener más información sobre el uso del sensor de visión.

Inicializando la clase de visión#

Un sensor de visión se crea utilizando los siguientes constructores:

The vision constructor creates a vision object in the specified port.

Parámetro

Descripción

port

Un Puerto inteligente válido al que está conectado el sensor de visión.

bright

El ajuste de brillo para el sensor de visión, de 0 a 255.

sigs

El nombre de uno o más objetos firma.

// Create a new Signature "darkBlue" with the signature class.
vision::signature darkBlue = vision::signature(1, -3911, -3435, -3673,10879, 11421, 11150,2.5, 0);
// Create a new Vision Sensor "Vision1" with the vision class.
vision Vision1 = vision(PORT1, 50, darkBlue);

This Vision1 vision object and darkBlue signature object will be used in all subsequent examples throughout this API documentation when referring to vision class methods.

Clases relacionadas

Métodos de clase#

tomarInstantánea()#

The takeSnapshot(index, count) method takes the current snapshot visible to the Vision sensor and detects the objects of a given signature, code, or signature id.

Antes de tomar una instantánea, debes configurar las firmas que el sensor de visión debe buscar.

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

Parámetros

Descripción

index

Una firma, un código o una identificación de firma.

count

Opcional. El número máximo de objetos a obtener. El valor predeterminado es 8.

Devoluciones: Ninguna.

while (true) {
  // Take a snapshot to check for detected objects.
  Vision1.takeSnapshot(darkBlue);

  // Clear the screen/reset so that we can display
  // new information.
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);

  // If objects were found, print the location.
  if (Vision1.objects[0].exists) {
    Brain.Screen.print("Center X: %d", Vision1.largestObject.centerX);
  } else {
    Brain.Screen.print("no object");
  }

  wait(0.5, seconds);
}

objeto más grande#

The largestObject property holds the largest object detected by the Vision sensor.

Luego podrá acceder a las siguientes propiedades de un objeto de visión.

Propiedades del objeto de visión

Descripción

Vision.largestObject.id

El identificador único del objeto.

Vision.largestObject.originX

La coordenada x superior izquierda del objeto.

Vision.largestObject.originY

La coordenada y superior izquierda del objeto.

Vision.largestObject.centerX

La coordenada x del centro del objeto.

Vision.largestObject.centerY

La coordenada y central del objeto.

Vision.largestObject.width

El ancho del objeto.

Vision.largestObject.height

La altura del objeto.

Vision.largestObject.angle

El ángulo del objeto.

Vision.largestObject.exists

Si la cámara Vision detecta el objeto o no.

Devuelve: Un objeto de visión.

while (true) {
  // Take a snapshot to check for detected objects.
  Vision1.takeSnapshot(darkBlue);

  // Clear the screen/reset so that we can display
  // new information.
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);

  // If objects were found, print the location.
  if (Vision1.objects[0].exists) {
    Brain.Screen.print("Center X: %d", Vision1.largestObject.centerX);
  } else {
    Brain.Screen.print("no object");
  }

  wait(0.5, seconds);
}

objectCount#

The objectCount property holds the number of objects detected in the latest snapshot taken by the Vision sensor.

Devuelve: La cantidad de objetos detectados por el sensor de visión.

while (true) {
  // Take a snapshot to check for detected objects.
  Vision1.takeSnapshot(darkBlue);

  // Clear the screen/reset so that we can display
  // new information.
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);

  // Print how many objects were detected.
  Brain.Screen.print("object count: %d", Vision1.objectCount);

  wait(0.5, seconds);
}

establecerModoLed()#

The setLedMode(mode) method changes the mode of the LED on the Vision Sensor.

Parámetros

Descripción

mode

Modo LED. El modo automático controla el color del LED mediante el firmware del sensor de visión. El modo manual permite controlar el color del LED mediante el programa del usuario.

Devuelve: Verdadero si la configuración se guardó correctamente. Falso si no.

obtenerLedMode()#

The getLedMode() method returns the mode of the LED from the Vision Sensor.

Returns: An ledMode that represents the current mode of the Vision Sensor LED.

establecerBrilloLed()#

The setLedBrightness(percent) method changes the brightness of the LED on the Vision Sensor when LED is set to manual mode.

Parámetros

Descripción

percent

Porcentaje del brillo total del LED del sensor de visión en modo manual. Los valores van de 0 a 100. 0 = LED apagado.

Devuelve: Verdadero si la configuración se guardó correctamente. Falso si no.

obtenerBrilloLed()#

The getLedBrightnesstLedMode() method returns the brightness of the LED from the Vision Sensor.

Devuelve: Un valor entre 0 y 100 que representa el brillo actual del LED del sensor de visión.

establecerColorLed()#

The setLedColor(red, green, blue) method changes the color of the LED on the Vision Sensor when LED is set to manual mode.

Parámetros

Descripción

red

Un valor de 0 a 255 que representa la intensidad del color rojo del LED.

green

Un valor de 0 a 255 que representa la intensidad del color verde del LED.

blue

Un valor de 0 a 255 que representa la intensidad del color azul del LED.

Devuelve: Verdadero si la configuración se guardó correctamente.

obtenerColorLed()#

The getLedColor(red, green, blue) method returns the color of the LED from the Vision Sensor.

Parámetros

Descripción

red

Una referencia a un valor para almacenar la intensidad del color rojo del LED.

green

Una referencia a un valor para almacenar la intensidad del color verde del LED.

blue

Una referencia a un valor para almacenar la intensidad del color azul del LED.

Devuelve: Verdadero si los valores se recibieron correctamente. Falso si no.

marca de tiempo()#

The timestamp() method requests the timestamp of the last received status packet from the Vision Sensor.

Devuelve: Marca de tiempo del último paquete de estado como un entero de 32 bits sin signo en milisegundos.

instalado()#

The installed() method checks if the Vision Sensor is connected.

Returns: true if the Vision Sensor is connected. false if it is not.