10 #include <hal/SimDevice.h>
12 #include "frc/ErrorBase.h"
14 #include "frc/interfaces/Accelerometer.h"
15 #include "frc/smartdashboard/Sendable.h"
16 #include "frc/smartdashboard/SendableHelper.h"
31 enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
45 explicit ADXL345_SPI(SPI::Port port, Range range = kRange_2G);
54 double GetX()
override;
55 double GetY()
override;
56 double GetZ()
override;
79 hal::SimDevice m_simDevice;
80 hal::SimEnum m_simRange;
81 hal::SimDouble m_simX;
82 hal::SimDouble m_simY;
83 hal::SimDouble m_simZ;
85 static constexpr
int kPowerCtlRegister = 0x2D;
86 static constexpr
int kDataFormatRegister = 0x31;
87 static constexpr
int kDataRegister = 0x32;
88 static constexpr
double kGsPerLSB = 0.00390625;
90 enum SPIAddressFields { kAddress_Read = 0x80, kAddress_MultiByte = 0x40 };
93 kPowerCtl_Link = 0x20,
94 kPowerCtl_AutoSleep = 0x10,
95 kPowerCtl_Measure = 0x08,
96 kPowerCtl_Sleep = 0x04
99 enum DataFormatFields {
100 kDataFormat_SelfTest = 0x80,
101 kDataFormat_SPI = 0x40,
102 kDataFormat_IntInvert = 0x20,
103 kDataFormat_FullRes = 0x08,
104 kDataFormat_Justify = 0x04
double GetZ() override
Common interface for getting the z axis acceleration.
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
ADXL345 Accelerometer on SPI.
Definition: ADXL345_SPI.h:26
ADXL345_SPI(SPI::Port port, Range range=kRange_2G)
Constructor.
virtual AllAxes GetAccelerations()
Get the acceleration of all axes in Gs.
Definition: ADXL345_SPI.h:33
Interface for 3-axis accelerometers.
Definition: Accelerometer.h:15
double GetY() override
Common interface for getting the y axis acceleration.
SPI bus interface class.
Definition: SPI.h:32
Base class for most objects.
Definition: ErrorBase.h:104
Interface for Sendable objects.
Definition: Sendable.h:17
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
void SetRange(Range range) override
Common interface for setting the measuring range of an accelerometer.
virtual double GetAcceleration(Axes axis)
Get the acceleration of one axis in Gs.
double GetX() override
Common interface for getting the x axis acceleration.
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:28
Definition: SendableBuilder.h:23