Eje#

Introducción#

The axis class is a derived class of the controller class. It provides access to controller joystick axis values and joystick axis change callbacks.

An axis object is accessed through a controller object. It is not constructed directly.

Controlador IQ de segunda generación con los cuatro ejes del joystick resaltados. En el joystick izquierdo, el eje 3 es vertical y el eje 4 es horizontal. En el joystick derecho, el eje 1 es horizontal y el eje 2 es vertical.

Acceso#

The controller class provides the following axis objects. Each object is an instance of the axis class.

Objeto Eje

Ejemplo de uso

Descripción

Axis1

Controller.Axis1.position()

Eje horizontal del joystick derecho.

Axis2

Controller.Axis2.position()

Eje vertical del joystick derecho.

Axis3

Controller.Axis3.position()

Eje vertical del joystick izquierdo.

Axis4

Controller.Axis4.position()

Eje horizontal del joystick izquierdo.

Notas#

  • Before using an axis member function, create a controller object.

  • position returns a value from -100 to 100.

// Create a controller object
controller Controller = controller();

Funciones de los miembros#

The axis class includes the following member functions:

Obtener: Lee la posición del eje del joystick.

  • position — Returns the position of the joystick axis.

Función de devolución de llamada: ejecuta una función cuando la posición del joystick cambia a lo largo de un eje.

  • changed — Runs a function when the joystick’s position changes along that axis.

Adquiridor#

posición#

position returns the position of the joystick axis as a value from -100 to 100.

Función disponible

int32_t position(percentUnits units = percentUnits::pct) const;

Parámetro

Tipo

Descripción

units

percentUnits

Optional. The unit used for the returned axis value. The default is percentUnits::pct.

Valor de retorno

Returns an int32_t value from -100 to 100.

  • 100 — The joystick axis is fully moved in the positive direction.

  • 0 — The joystick axis is centered.

  • -100 — The joystick axis is fully moved in the negative direction.

Ejemplo

// Turn with the left joystick
while (true) {
  if (Controller.Axis4.position() > 10) {
    Drivetrain.turn(right);
  }
  else if (Controller.Axis4.position() < -10) {
    Drivetrain.turn(left);
  }
  else {
    Drivetrain.stop();
  }

  wait(20, msec);
}

Llamar de vuelta#

cambió#

changed runs a function when the joystick’s position changes along that axis.

Función disponible

void changed(void (* callback)(void)) const;

Parámetro

Tipo

Descripción

callback

void (*)(void)

Una función que se ejecutará cada vez que cambie la posición del joystick a lo largo de ese eje.

Valor de retorno

Esta función no devuelve ningún valor.

Ejemplo

Define the callback function outside of main.

// Play a sound when the left joystick moves
void playSound() {
  Brain.playSound(siren);
}

Register the callback inside main.

int main() {
  vexcodeInit();

  // Run playSound when the joystick's position changes along Axis4
  Controller.Axis4.changed(playSound);
}