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

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 |
|---|---|---|
|
|
The 3-Wire Port the Accelerometer is connected to, written as |
|
|
Optional. Whether to enable high sensitivity mode on the Accelerometer:
|
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 Functionsdouble acceleration();
This function does not accept any parameters.
Return ValuesReturns 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();