WPILibC++ 2024.1.1-beta-4
frc::ADXL345_I2C Class Reference

ADXL345 Accelerometer on I2C. More...

#include <frc/ADXL345_I2C.h>

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

Classes

struct  AllAxes
 

Public Types

enum  Range { kRange_2G = 0 , kRange_4G = 1 , kRange_8G = 2 , kRange_16G = 3 }
 
enum  Axes { kAxis_X = 0x00 , kAxis_Y = 0x02 , kAxis_Z = 0x04 }
 

Public Member Functions

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

Protected Types

enum  PowerCtlFields { kPowerCtl_Link = 0x20 , kPowerCtl_AutoSleep = 0x10 , kPowerCtl_Measure = 0x08 , kPowerCtl_Sleep = 0x04 }
 
enum  DataFormatFields {
  kDataFormat_SelfTest = 0x80 , kDataFormat_SPI = 0x40 , kDataFormat_IntInvert = 0x20 , kDataFormat_FullRes = 0x08 ,
  kDataFormat_Justify = 0x04
}
 

Protected Attributes

I2C m_i2c
 
hal::SimDevice m_simDevice
 
hal::SimEnum m_simRange
 
hal::SimDouble m_simX
 
hal::SimDouble m_simY
 
hal::SimDouble m_simZ
 

Static Protected Attributes

static constexpr int kAddress = 0x1D
 
static constexpr int kPowerCtlRegister = 0x2D
 
static constexpr int kDataFormatRegister = 0x31
 
static constexpr int kDataRegister = 0x32
 
static constexpr double kGsPerLSB = 0.00390625
 

Additional Inherited Members

- Protected Member Functions inherited from wpi::SendableHelper< ADXL345_I2C >
 SendableHelper ()=default
 
 ~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).

The Onboard I2C port is subject to system lockups. See WPILib Known Issues page for details.

Member Enumeration Documentation

◆ Axes

Enumerator
kAxis_X 
kAxis_Y 
kAxis_Z 

◆ DataFormatFields

Enumerator
kDataFormat_SelfTest 
kDataFormat_SPI 
kDataFormat_IntInvert 
kDataFormat_FullRes 
kDataFormat_Justify 

◆ PowerCtlFields

Enumerator
kPowerCtl_Link 
kPowerCtl_AutoSleep 
kPowerCtl_Measure 
kPowerCtl_Sleep 

◆ Range

Enumerator
kRange_2G 
kRange_4G 
kRange_8G 
kRange_16G 

Constructor & Destructor Documentation

◆ ADXL345_I2C() [1/2]

frc::ADXL345_I2C::ADXL345_I2C ( I2C::Port  port,
Range  range = kRange_2G,
int  deviceAddress = kAddress 
)
explicit

Constructs the ADXL345 Accelerometer over I2C.

Parameters
portThe I2C port the accelerometer is attached to
rangeThe range (+ or -) that the accelerometer will measure
deviceAddressThe I2C address of the accelerometer (0x1D or 0x53)

◆ ~ADXL345_I2C()

frc::ADXL345_I2C::~ADXL345_I2C ( )
overridedefault

◆ ADXL345_I2C() [2/2]

frc::ADXL345_I2C::ADXL345_I2C ( ADXL345_I2C &&  )
default

Member Function Documentation

◆ GetAcceleration()

virtual double frc::ADXL345_I2C::GetAcceleration ( Axes  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 frc::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 frc::ADXL345_I2C::GetI2CDeviceAddress ( ) const

◆ GetI2CPort()

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

◆ GetX()

double frc::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 frc::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 frc::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 frc::ADXL345_I2C::InitSendable ( nt::NTSendableBuilder builder)
overridevirtual

Initializes this Sendable object.

Parameters
buildersendable builder

Implements nt::NTSendable.

◆ operator=()

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

◆ SetRange()

void frc::ADXL345_I2C::SetRange ( Range  range)

Set the measuring range of the accelerometer.

Parameters
rangeThe maximum acceleration, positive or negative, that the accelerometer will measure.

Member Data Documentation

◆ kAddress

constexpr int frc::ADXL345_I2C::kAddress = 0x1D
staticconstexprprotected

◆ kDataFormatRegister

constexpr int frc::ADXL345_I2C::kDataFormatRegister = 0x31
staticconstexprprotected

◆ kDataRegister

constexpr int frc::ADXL345_I2C::kDataRegister = 0x32
staticconstexprprotected

◆ kGsPerLSB

constexpr double frc::ADXL345_I2C::kGsPerLSB = 0.00390625
staticconstexprprotected

◆ kPowerCtlRegister

constexpr int frc::ADXL345_I2C::kPowerCtlRegister = 0x2D
staticconstexprprotected

◆ m_i2c

I2C frc::ADXL345_I2C::m_i2c
protected

◆ m_simDevice

hal::SimDevice frc::ADXL345_I2C::m_simDevice
protected

◆ m_simRange

hal::SimEnum frc::ADXL345_I2C::m_simRange
protected

◆ m_simX

hal::SimDouble frc::ADXL345_I2C::m_simX
protected

◆ m_simY

hal::SimDouble frc::ADXL345_I2C::m_simY
protected

◆ m_simZ

hal::SimDouble frc::ADXL345_I2C::m_simZ
protected

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