WPILibC++  2020.3.2-60-g3011ebe
ADXL362.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <hal/SimDevice.h>
11 
12 #include "frc/ErrorBase.h"
13 #include "frc/SPI.h"
14 #include "frc/interfaces/Accelerometer.h"
15 #include "frc/smartdashboard/Sendable.h"
16 #include "frc/smartdashboard/SendableHelper.h"
17 
18 namespace frc {
19 
20 class SendableBuilder;
21 
27 class ADXL362 : public ErrorBase,
28  public Accelerometer,
29  public Sendable,
30  public SendableHelper<ADXL362> {
31  public:
32  enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
33  struct AllAxes {
34  double XAxis;
35  double YAxis;
36  double ZAxis;
37  };
38 
39  public:
45  explicit ADXL362(Range range = kRange_2G);
46 
53  explicit ADXL362(SPI::Port port, Range range = kRange_2G);
54 
55  ~ADXL362() override = default;
56 
57  ADXL362(ADXL362&&) = default;
58  ADXL362& operator=(ADXL362&&) = default;
59 
60  // Accelerometer interface
61  void SetRange(Range range) override;
62  double GetX() override;
63  double GetY() override;
64  double GetZ() override;
65 
72  virtual double GetAcceleration(Axes axis);
73 
80  virtual AllAxes GetAccelerations();
81 
82  void InitSendable(SendableBuilder& builder) override;
83 
84  private:
85  SPI m_spi;
86  hal::SimDevice m_simDevice;
87  hal::SimEnum m_simRange;
88  hal::SimDouble m_simX;
89  hal::SimDouble m_simY;
90  hal::SimDouble m_simZ;
91  double m_gsPerLSB = 0.001;
92 };
93 
94 } // namespace frc
frc::ADXL362::SetRange
void SetRange(Range range) override
Common interface for setting the measuring range of an accelerometer.
frc::ADXL362::ADXL362
ADXL362(Range range=kRange_2G)
Constructor.
frc::ADXL362::GetY
double GetY() override
Common interface for getting the y axis acceleration.
frc::ADXL362::GetX
double GetX() override
Common interface for getting the x axis acceleration.
frc::Accelerometer
Interface for 3-axis accelerometers.
Definition: Accelerometer.h:15
frc::SPI
SPI bus interface class.
Definition: SPI.h:32
frc::ADXL362::InitSendable
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
frc::ErrorBase
Base class for most objects.
Definition: ErrorBase.h:104
frc::ADXL362::GetAccelerations
virtual AllAxes GetAccelerations()
Get the acceleration of all axes in Gs.
frc::ADXL362::GetZ
double GetZ() override
Common interface for getting the z axis acceleration.
frc::Sendable
Interface for Sendable objects.
Definition: Sendable.h:17
frc::ADXL362::GetAcceleration
virtual double GetAcceleration(Axes axis)
Get the acceleration of one axis in Gs.
frc::ADXL362::AllAxes
Definition: ADXL362.h:33
frc
A class that enforces constraints on the differential drive kinematics.
Definition: PDPSim.h:16
frc::ADXL362
ADXL362 SPI Accelerometer.
Definition: ADXL362.h:27
frc::SendableHelper
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:28
frc::SendableBuilder
Definition: SendableBuilder.h:23