acelerómetro#

Inicializando la clase del acelerómetro#

Un acelerómetro se crea utilizando uno de los siguientes constructores:

The accelerometer constructor creates an Accelerometer in a specified Three Wire Port with High Sensitivity Mode defaulted to false.

Parámetro

Descripción

port

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

// Create the Brain.
brain Brain;

// Construct an accelerometer "accel" with the
// accelerometer class.
accelerometer accel = accelerometer(Brain.ThreeWirePort.A);

The Accelerometer(port, sensitivity) constructor creates an Accelerometer and can enable High Sensitivity Mode.

Parámetro

Descripción

port

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

sensitivity

Enables high sensitivity mode (+/- 2g) on the Accelerometer. true to enable high sensitivity. The default sensitivity is (+/- 6g).

// Create the Brain.
brain Brain;

// Construct an accelerometer "accel" with the
// accelerometer class.
accelerometer accel = accelerometer(Brain.ThreeWirePort.A, true);

Primero se debe crear un Cerebro o un Expansor de 3 cables antes de poder usarlos para crear un objeto con el constructor de la clase Acelerómetro.

The accel object will be used in all subsequent examples throughout this API documentation when referring to accelerometer class methods.

Para una funcionalidad óptima, se recomienda utilizar acelerómetros separados para cada eje, inicializándolos individualmente:

accelerometer accel_x = accelerometer(Brain.ThreeWirePort.A);
accelerometer accel_y = accelerometer(Brain.ThreeWirePort.B);
accelerometer accel_z = accelerometer(Brain.ThreeWirePort.C);

Métodos de clase#

acceleration()#

The acceleration() method reads the value of the Accelerometer scaled to units of gravity.

Devuelve: Un doble en el rango +/- 6G, o +/-2G si está configurado el modo de alta sensibilidad.

// Drive the robot forward.
Drivetrain.drive(forward);

// Get the acceleration of accel in the range +/- 6G.
double accelerationValue = accel.acceleration();

changed()#

The changed(callback) method registers a function to be called when the value of the Accelerometer changes.

Parámetros

Descripción

llamar de vuelta

Una función que se llamará cuando cambie el valor del eje del acelerómetro.

Devuelve: Una instancia de la clase Event.

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

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

  // Drive the robot forward.
  Drivetrain.drive(forward);

  // Run accelerometerChanged when the value of the 
  // Accelerometer changes.
  accel.changed(accelerometerChanged);
}