Acelerómetro#

Introducción#

The accelerometer class measures the acceleration of the robot along one or more axes. The sensor outputs an analog voltage that changes based on acceleration in G-forces (G).

Un puente en el acelerómetro determina su rango de sensibilidad:

  • 2G - Mide la aceleración de -2G a +2G.

  • 6G - Mide la aceleración de -6G a +6G.

El acelerómetro analógico VEX EXP.

Constructor de clases#

accelerometer(
  triport::port &port,
  bool           bHighSensitivity = false);

Instructor de clase#

Destroys the accelerometer object and releases associated resources.

virtual ~accelerometer();

Parámetros#

Parámetro

Tipo

Descripción

port

triport::port &

The 3-Wire Port the Accelerometer is connected to, written as Brain.ThreeWirePort.X or ExpanderName.X, where X is the port letter (for example, Brain.ThreeWirePort.A or Expander1.A).

bHighSensitivity

bool

Optional. Whether to enable high sensitivity mode on the Accelerometer:

  • true - Enables high sensitivity (+/- 2G).
  • false (default) - Enables low sensitivity (+/- 6G).

Ejemplos#

// Create a 6G accelerometer instance in Port A
accelerometer Accel6GA = accelerometer(Brain.ThreeWirePort.A);

// Create a 2G accelerometer instance in Port A
accelerometer Accel2GA = accelerometer(Brain.ThreeWirePort.A, true);

Funciones de los miembros#

The accelerometer class includes the following member functions:

  • acceleration — Returns the acceleration measured by the Accelerometer in Gs.

Before calling any accelerometer member functions, an accelerometer instance must be created, as shown below:

/* This constructor is required when using VS Code.
Accelerometer configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create a 2G accelerometer instance in Port A
accelerometer Accel2GA = accelerometer(Brain.ThreeWirePort.A, true);

acceleration#

Devuelve la aceleración medida en Gs.

Available Functions
double acceleration();

Parameters

Esta función no acepta ningún parámetro.

Return Values

Returns a double representing the acceleration measured in Gs.

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

// Get the acceleration measured by the Accelerometer.
double accelerationValue = Accel2GA.acceleration();