Accelerometer#

Introduction#

The accelerometer class measures acceleration detected by the Accelerometer at different sensitivities.

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

Sets the created Accelerometer to either a 2G or 6G Accelerometer by setting the high sensitivity mode:

  • false (default) — Creates a 2G Accelerometer
  • true — Creates a 6G Accelerometer

Examples#

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

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

Member Functions#

The accelerometer class includes the following member functions:

  • acceleration — Returns the acceleration detected by the Accelerometer.

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 6G accelerometer instance in Port A
accelerometer Accel6GA = accelerometer(Brain.ThreeWirePort.A, true);

acceleration#

Returns the value of the Accelerometer scaled to units of gravity.

Available Functions
double acceleration();

Parameters

This function does not accept any parameters.

Return Values

Returns a double in the range +/- 6G for a 6G Accelerometer, or +/-2G for a 2G Accelerometer.

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

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