WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
wpi::ADXL345_I2C Class Reference

ADXL345 Accelerometer on I2C. More...

#include <wpi/hardware/accelerometer/ADXL345_I2C.hpp>

Inheritance diagram for wpi::ADXL345_I2C:
wpi::nt::NTSendable wpi::util::SendableHelper< ADXL345_I2C > wpi::util::Sendable

Classes

struct  AllAxes
 Container type for accelerations from all axes. More...

Public Types

enum class  Axis { X = 0x00 , Y = 0x02 , Z = 0x04 }
 Accelerometer axes. More...

Public Member Functions

 ADXL345_I2C (I2C::Port port, int range=2, int deviceAddress=DEFAULT_ADDRESS)
 Constructs the ADXL345 Accelerometer over I2C.
 ~ADXL345_I2C () override=default
 ADXL345_I2C (ADXL345_I2C &&)=default
ADXL345_I2Coperator= (ADXL345_I2C &&)=default
I2C::Port GetI2CPort () const
int GetI2CDeviceAddress () const
void SetRange (int range)
 Set the measuring range of the accelerometer.
double GetX ()
 Returns the acceleration along the X axis in g-forces.
double GetY ()
 Returns the acceleration along the Y axis in g-forces.
double GetZ ()
 Returns the acceleration along the Z axis in g-forces.
virtual double GetAcceleration (Axis axis)
 Get the acceleration of one axis in Gs.
virtual AllAxes GetAccelerations ()
 Get the acceleration of all axes in Gs.
void InitSendable (wpi::nt::NTSendableBuilder &builder) override
 Initializes this Sendable object.
Public Member Functions inherited from wpi::nt::NTSendable
void InitSendable (wpi::util::SendableBuilder &builder) override
 Initializes this Sendable object.
Public Member Functions inherited from wpi::util::Sendable
virtual constexpr ~Sendable ()=default
Public Member Functions inherited from wpi::util::SendableHelper< ADXL345_I2C >
constexpr SendableHelper (const SendableHelper &rhs)=default
constexpr SendableHelperoperator= (const SendableHelper &rhs)=default

Static Public Attributes

static constexpr int DEFAULT_ADDRESS = 0x1D
 Default I2C device address.

Additional Inherited Members

Protected Member Functions inherited from wpi::util::SendableHelper< ADXL345_I2C >
constexpr ~SendableHelper ()

Detailed Description

ADXL345 Accelerometer on I2C.

This class allows access to a Analog Devices ADXL345 3-axis accelerometer on an I2C bus. This class assumes the default (not alternate) sensor address of 0x1D (7-bit address).

Member Enumeration Documentation

◆ Axis

enum class wpi::ADXL345_I2C::Axis
strong

Accelerometer axes.

Enumerator

X axis.

Y axis.

Z axis.

Constructor & Destructor Documentation

◆ ADXL345_I2C() [1/2]

wpi::ADXL345_I2C::ADXL345_I2C ( I2C::Port port,
int range = 2,
int deviceAddress = DEFAULT_ADDRESS )
explicit

Constructs the ADXL345 Accelerometer over I2C.

Parameters
portThe I2C port the accelerometer is attached to
rangeThe range (+ or -) that the accelerometer will measure; valid values are 2, 4, 8, or 16 Gs. The default is 2 Gs.
deviceAddressThe I2C address of the accelerometer (0x1D or 0x53)

◆ ~ADXL345_I2C()

wpi::ADXL345_I2C::~ADXL345_I2C ( )
overridedefault

◆ ADXL345_I2C() [2/2]

wpi::ADXL345_I2C::ADXL345_I2C ( ADXL345_I2C && )
default

Member Function Documentation

◆ GetAcceleration()

virtual double wpi::ADXL345_I2C::GetAcceleration ( Axis axis)
virtual

Get the acceleration of one axis in Gs.

Parameters
axisThe axis to read from.
Returns
Acceleration of the ADXL345 in Gs.

◆ GetAccelerations()

virtual AllAxes wpi::ADXL345_I2C::GetAccelerations ( )
virtual

Get the acceleration of all axes in Gs.

Returns
An object containing the acceleration measured on each axis of the ADXL345 in Gs.

◆ GetI2CDeviceAddress()

int wpi::ADXL345_I2C::GetI2CDeviceAddress ( ) const

◆ GetI2CPort()

I2C::Port wpi::ADXL345_I2C::GetI2CPort ( ) const

◆ GetX()

double wpi::ADXL345_I2C::GetX ( )

Returns the acceleration along the X axis in g-forces.

Returns
The acceleration along the X axis in g-forces.

◆ GetY()

double wpi::ADXL345_I2C::GetY ( )

Returns the acceleration along the Y axis in g-forces.

Returns
The acceleration along the Y axis in g-forces.

◆ GetZ()

double wpi::ADXL345_I2C::GetZ ( )

Returns the acceleration along the Z axis in g-forces.

Returns
The acceleration along the Z axis in g-forces.

◆ InitSendable()

void wpi::ADXL345_I2C::InitSendable ( wpi::nt::NTSendableBuilder & builder)
overridevirtual

Initializes this Sendable object.

Parameters
buildersendable builder

Implements wpi::nt::NTSendable.

◆ operator=()

ADXL345_I2C & wpi::ADXL345_I2C::operator= ( ADXL345_I2C && )
default

◆ SetRange()

void wpi::ADXL345_I2C::SetRange ( int range)

Set the measuring range of the accelerometer.

Parameters
rangeThe maximum acceleration, positive or negative, that the accelerometer will measure. Valid values are 2, 4, 8, or 16 Gs.

Member Data Documentation

◆ DEFAULT_ADDRESS

int wpi::ADXL345_I2C::DEFAULT_ADDRESS = 0x1D
staticconstexpr

Default I2C device address.


The documentation for this class was generated from the following file: