WPILibC++  2021.3.1
frc::ADXL345_SPI Class Reference

ADXL345 Accelerometer on SPI. More...

#include <frc/ADXL345_SPI.h>

Inheritance diagram for frc::ADXL345_SPI:
frc::ErrorBase frc::Accelerometer frc::Sendable frc::SendableHelper< ADXL345_SPI >

Classes

struct  AllAxes
 

Public Types

enum  Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 }
 
- Public Types inherited from frc::Accelerometer
enum  Range { kRange_2G = 0, kRange_4G = 1, kRange_8G = 2, kRange_16G = 3 }
 

Public Member Functions

 ADXL345_SPI (SPI::Port port, Range range=kRange_2G)
 Constructor. More...
 
 ADXL345_SPI (ADXL345_SPI &&)=default
 
ADXL345_SPIoperator= (ADXL345_SPI &&)=default
 
void SetRange (Range range) final
 Common interface for setting the measuring range of an accelerometer. More...
 
double GetX () override
 Common interface for getting the x axis acceleration. More...
 
double GetY () override
 Common interface for getting the y axis acceleration. More...
 
double GetZ () override
 Common interface for getting the z axis acceleration. 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 (SendableBuilder &builder) override
 Initializes this Sendable object. More...
 
- Public Member Functions inherited from frc::ErrorBase
 ErrorBase (const ErrorBase &)=default
 
ErrorBaseoperator= (const ErrorBase &)=default
 
 ErrorBase (ErrorBase &&)=default
 
ErrorBaseoperator= (ErrorBase &&)=default
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 Retrieve the current error. More...
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual void SetErrnoError (const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set error information associated with a C library call that set an error to the "errno" global variable. More...
 
virtual void SetImaqError (int success, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetErrorRange (Error::Code code, int32_t minRange, int32_t maxRange, int32_t requestedValue, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const wpi::Twine &errorMessage, Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const ErrorBase &rhs) const
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 
void ClearGlobalErrors ()
 Clear global errors.
 
- Public Member Functions inherited from frc::Accelerometer
 Accelerometer (Accelerometer &&)=default
 
Accelerometeroperator= (Accelerometer &&)=default
 
- Public Member Functions inherited from frc::SendableHelper< ADXL345_SPI >
 SendableHelper (const SendableHelper &rhs)=default
 
 SendableHelper (SendableHelper &&rhs)
 
SendableHelperoperator= (const SendableHelper &rhs)=default
 
SendableHelperoperator= (SendableHelper &&rhs)
 
std::string GetName () const
 Gets the name of this Sendable object. More...
 
void SetName (const wpi::Twine &name)
 Sets the name of this Sendable object. More...
 
void SetName (const wpi::Twine &subsystem, const wpi::Twine &name)
 Sets both the subsystem name and device name of this Sendable object. More...
 
std::string GetSubsystem () const
 Gets the subsystem name of this Sendable object. More...
 
void SetSubsystem (const wpi::Twine &subsystem)
 Sets the subsystem name of this Sendable object. More...
 

Protected Types

enum  SPIAddressFields { kAddress_Read = 0x80, kAddress_MultiByte = 0x40 }
 
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

SPI m_spi
 
hal::SimDevice m_simDevice
 
hal::SimEnum m_simRange
 
hal::SimDouble m_simX
 
hal::SimDouble m_simY
 
hal::SimDouble m_simZ
 
- Protected Attributes inherited from frc::ErrorBase
Error m_error
 

Static Protected Attributes

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

Additional Inherited Members

- Static Public Member Functions inherited from frc::ErrorBase
static void SetGlobalError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static void SetGlobalWPIError (const wpi::Twine &errorMessage, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static Error GetGlobalError ()
 Retrieve the last global error.
 
static std::vector< ErrorGetGlobalErrors ()
 Retrieve all global errors.
 
- Protected Member Functions inherited from frc::SendableHelper< ADXL345_SPI >
void SetName (const wpi::Twine &moduleType, int channel)
 Sets the name of the sensor with a channel number. More...
 
void SetName (const wpi::Twine &moduleType, int moduleNumber, int channel)
 Sets the name of the sensor with a module and channel number. More...
 
void AddChild (std::shared_ptr< Sendable > child)
 Add a child component. More...
 
void AddChild (void *child)
 Add a child component. More...
 

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.

Constructor & Destructor Documentation

◆ ADXL345_SPI()

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

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.

◆ GetX()

double frc::ADXL345_SPI::GetX ( )
overridevirtual

Common interface for getting the x axis acceleration.

Returns
The acceleration along the x axis in g-forces

Implements frc::Accelerometer.

◆ GetY()

double frc::ADXL345_SPI::GetY ( )
overridevirtual

Common interface for getting the y axis acceleration.

Returns
The acceleration along the y axis in g-forces

Implements frc::Accelerometer.

◆ GetZ()

double frc::ADXL345_SPI::GetZ ( )
overridevirtual

Common interface for getting the z axis acceleration.

Returns
The acceleration along the z axis in g-forces

Implements frc::Accelerometer.

◆ InitSendable()

void frc::ADXL345_SPI::InitSendable ( SendableBuilder builder)
overridevirtual

Initializes this Sendable object.

Parameters
buildersendable builder

Implements frc::Sendable.

◆ SetRange()

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

Common interface for setting the measuring range of an accelerometer.

Parameters
rangeThe maximum acceleration, positive or negative, that the accelerometer will measure. Not all accelerometers support all ranges.

Implements frc::Accelerometer.


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