Accelerometers - measuring acceleration and tilt

Accelerometers measure acceleration in one or more axis. One typical usage is to measure robot acceleration. Another common usage is to measure robot tilt, in this case it measures the acceleration due to gravity.

Two-axis analog accelerometer

Two-axis analog accelerometer

A commonly used part (shown in the picture above) is a two-axis accelerometer. This device can provide acceleration data in the X and Y-axes relative to the circuit board. The WPI Robotics Library you treats it as two separate devices, one for the X- axis and the other for the Y-axis. The accelerometer can be used as a tilt sensor – by measuring the acceleration of gravity. In this case, turning the device on the side would indicate 1000 milliGs or one G. Shown is a 2-axis accelerometer board connected to two analog inputs on the robot. Note that this is not the accelerometer provided in the 2014 KOP.

Analog Accelerometer code example

Analog Accelerometer code example

A brief code example is shown above which illustrates how to set up an analog accelerometer connected to analog module 1, channel 1. The sensitivity and zero voltages were set according to the datasheet (assumed part is ADXL193, zero voltage set to ideal. Would need to determine actual offset of specific part being used).

ADXL345 Accelerometer

ADXL345 Accelerometer

The ADXL345 is a three axis accelerometer provided as part of the sensor board in the 2012-2014 KOP. The ADXL345 is capable of measuring accelerations up to +/- 16g and communicates over I2C or SPI. Wiring instructions for either protocol can be found in the FRC component datasheet. Additional information can be found in the Analog Devices ADXL345 datasheet. WPILib provides a separate class for each protocol which handles the details of setting up the bus and enabling the sensor.

ADXL345 Code Example

ADXL345 Code Example

A brief code example is shown above illustrating the use of the ADXL345 connected to the I2C bus on Digital Module 1. The accelerometer has been set to operate in +/- 2g mode. The example illustrates both the single axis and all axes methods of getting the sensor values, in practice select one or the other depending on whether you need a single axis or all three. SPI operation is similar, refer to the Javadoc/Doxygen for the ADXL345_SPI class for additional details on using the sensor over SPI.