WPILibC++ 2024.3.2
frc::ADXL345_SPI Class Reference

ADXL345 Accelerometer on SPI. More...

#include <frc/ADXL345_SPI.h>

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

Classes

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

Public Types

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

Public Member Functions

 ADXL345_SPI (SPI::Port port, Range range=kRange_2G)
 Constructor. More...
 
 ~ADXL345_SPI () override=default
 
 ADXL345_SPI (ADXL345_SPI &&)=default
 
ADXL345_SPIoperator= (ADXL345_SPI &&)=default
 
SPI::Port GetSpiPort () 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_SPI >
 SendableHelper (const SendableHelper &rhs)=default
 
 SendableHelper (SendableHelper &&rhs)
 
SendableHelperoperator= (const SendableHelper &rhs)=default
 
SendableHelperoperator= (SendableHelper &&rhs)
 

Additional Inherited Members

- Protected Member Functions inherited from wpi::SendableHelper< ADXL345_SPI >
 SendableHelper ()=default
 
 ~SendableHelper ()
 

Detailed Description

ADXL345 Accelerometer on SPI.

This class allows access to an Analog Devices ADXL345 3-axis accelerometer via SPI. This class assumes the sensor is wired in 4-wire SPI mode.

Member Enumeration Documentation

◆ Axes

Accelerometer axes.

Enumerator
kAxis_X 

X axis.

kAxis_Y 

Y axis.

kAxis_Z 

Z axis.

◆ Range

Accelerometer range.

Enumerator
kRange_2G 

2 Gs max.

kRange_4G 

4 Gs max.

kRange_8G 

8 Gs max.

kRange_16G 

16 Gs max.

Constructor & Destructor Documentation

◆ ADXL345_SPI() [1/2]

frc::ADXL345_SPI::ADXL345_SPI ( SPI::Port  port,
Range  range = kRange_2G 
)
explicit

Constructor.

Parameters
portThe SPI port the accelerometer is attached to
rangeThe range (+ or -) that the accelerometer will measure

◆ ~ADXL345_SPI()

frc::ADXL345_SPI::~ADXL345_SPI ( )
overridedefault

◆ ADXL345_SPI() [2/2]

frc::ADXL345_SPI::ADXL345_SPI ( ADXL345_SPI &&  )
default

Member Function Documentation

◆ GetAcceleration()

virtual double frc::ADXL345_SPI::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_SPI::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.

◆ GetSpiPort()

SPI::Port frc::ADXL345_SPI::GetSpiPort ( ) const

◆ GetX()

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

Initializes this Sendable object.

Parameters
buildersendable builder

Implements nt::NTSendable.

◆ operator=()

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

◆ SetRange()

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

Set the measuring range of the accelerometer.

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

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