Accelerometer#

Introduction#

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).

A jumper on the Accelerometer determines its sensitivity range:

  • 2G - Measures acceleration from -2G to +2G

  • 6G - Measures acceleration from -6G to +6G

The VEX EXP Analog accelerometer.

Class Constructor#

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

Class Destructor#

Destroys the accelerometer object and releases associated resources.

virtual ~accelerometer();

Parameters#

Parameter

Type

Description

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).

Examples#

// 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);

Member Functions#

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#

Returns the acceleration measured in Gs.

Available Functions
double acceleration();

Parameters

This function does not accept any parameters.

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();