WPILibC++  unspecified
ADXL362.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2018 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 "SPI.h"
11 #include "SensorBase.h"
12 #include "interfaces/Accelerometer.h"
13 
14 namespace frc {
15 
21 class ADXL362 : public SensorBase, public Accelerometer {
22  public:
23  enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
24  struct AllAxes {
25  double XAxis;
26  double YAxis;
27  double ZAxis;
28  };
29 
30  public:
31  explicit ADXL362(Range range = kRange_2G);
32  explicit ADXL362(SPI::Port port, Range range = kRange_2G);
33  virtual ~ADXL362() = default;
34 
35  ADXL362(const ADXL362&) = delete;
36  ADXL362& operator=(const ADXL362&) = delete;
37 
38  // Accelerometer interface
39  void SetRange(Range range) override;
40  double GetX() override;
41  double GetY() override;
42  double GetZ() override;
43 
44  virtual double GetAcceleration(Axes axis);
45  virtual AllAxes GetAccelerations();
46 
47  void InitSendable(SendableBuilder& builder) override;
48 
49  private:
50  SPI m_spi;
51  double m_gsPerLSB = 0.001;
52 };
53 
54 } // namespace frc
Definition: RobotController.cpp:14
virtual AllAxes GetAccelerations()
Get the acceleration of all axes in Gs.
Definition: ADXL362.cpp:137
Base class for all sensors.
Definition: SensorBase.h:25
double GetY() override
Common interface for getting the y axis acceleration.
Definition: ADXL362.cpp:107
SPI bus interface class.
Definition: SPI.h:31
ADXL362 SPI Accelerometer.
Definition: ADXL362.h:21
Definition: ADXL362.h:24
void SetRange(Range range) override
Common interface for setting the measuring range of an accelerometer.
Definition: ADXL362.cpp:79
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
Definition: ADXL362.cpp:164
Definition: SendableBuilder.h:23
Interface for 3-axis accelerometers.
Definition: Accelerometer.h:15
double GetX() override
Common interface for getting the x axis acceleration.
Definition: ADXL362.cpp:105
double GetZ() override
Common interface for getting the z axis acceleration.
Definition: ADXL362.cpp:109
ADXL362(Range range=kRange_2G)
Constructor.
Definition: ADXL362.cpp:39
virtual double GetAcceleration(Axes axis)
Get the acceleration of one axis in Gs.
Definition: ADXL362.cpp:117