Class ADXL345_I2C
java.lang.Object
org.wpilib.hardware.accelerometer.ADXL345_I2C
- All Implemented Interfaces:
AutoCloseable, TelemetryLoggable
ADXL345 I2C Accelerometer.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordContainer type for accelerations from all axes.static enumAccelerometer axes. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionADXL345_I2C(I2C.Port port, int range) Constructs the ADXL345 Accelerometer with I2C address 0x1D.ADXL345_I2C(I2C.Port port, int range, int deviceAddress) Constructs the ADXL345 Accelerometer over I2C. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()doubleGet the acceleration of one axis in Gs.Get the acceleration of all axes in Gs.intReturns the I2C device address.getPort()Returns the I2C port.Gets the telemetry table type.doublegetX()Returns the acceleration along the X axis in g-forces.doublegetY()Returns the acceleration along the Y axis in g-forces.doublegetZ()Returns the acceleration along the Z axis in g-forces.voidlogTo(TelemetryTable table) Logs the object to aTelemetryTable.final voidsetRange(int range) Set the measuring range of the accelerometer.
-
Field Details
-
DEFAULT_ADDRESS
public static final byte DEFAULT_ADDRESSDefault I2C device address.- See Also:
-
-
Constructor Details
-
ADXL345_I2C
Constructs the ADXL345 Accelerometer with I2C address 0x1D.- Parameters:
port- The I2C port the accelerometer is attached torange- The range (+ or -) that the accelerometer will measure. Valid values are 2, 4, 8, or 16 Gs.
-
ADXL345_I2C
Constructs the ADXL345 Accelerometer over I2C.- Parameters:
port- The I2C port the accelerometer is attached torange- The range (+ or -) that the accelerometer will measure. Valid values are 2, 4, 8, or 16 Gs.deviceAddress- I2C address of the accelerometer (0x1D or 0x53)
-
-
Method Details
-
getPort
-
getDeviceAddress
public int getDeviceAddress()Returns the I2C device address.- Returns:
- The I2C device address.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
setRange
public final void setRange(int range) Set the measuring range of the accelerometer.- Parameters:
range- The maximum acceleration, positive or negative, that the accelerometer will measure. Valid values are 2, 4, 8, or 16 Gs.
-
getX
public double getX()Returns the acceleration along the X axis in g-forces.- Returns:
- The acceleration along the X axis in g-forces.
-
getY
public double getY()Returns the acceleration along the Y axis in g-forces.- Returns:
- The acceleration along the Y axis in g-forces.
-
getZ
public double getZ()Returns the acceleration along the Z axis in g-forces.- Returns:
- The acceleration along the Z axis in g-forces.
-
getAcceleration
Get the acceleration of one axis in Gs.- Parameters:
axis- The axis to read from.- Returns:
- Acceleration of the ADXL345 in Gs.
-
getAccelerations
Get the acceleration of all axes in Gs.- Returns:
- An object containing the acceleration measured on each axis of the ADXL345 in Gs.
-
logTo
Description copied from interface:TelemetryLoggableLogs the object to aTelemetryTable.- Specified by:
logToin interfaceTelemetryLoggable- Parameters:
table- telemetry table
-
getTelemetryType
Description copied from interface:TelemetryLoggableGets the telemetry table type. Default is no specified table type (null). A mismatch in type during logging results in a reported warning, so this should always return the same value.- Specified by:
getTelemetryTypein interfaceTelemetryLoggable- Returns:
- Table type
-