WPILibC++  unspecified
ADXL362.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2017 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 <memory>
11 #include <string>
12 
13 #include "LiveWindow/LiveWindowSendable.h"
14 #include "SPI.h"
15 #include "SensorBase.h"
16 #include "interfaces/Accelerometer.h"
17 #include "networktables/NetworkTableEntry.h"
18 
19 namespace frc {
20 
21 class DigitalInput;
22 class DigitalOutput;
23 
29 class ADXL362 : public Accelerometer, public LiveWindowSendable {
30  public:
31  enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
32  struct AllAxes {
33  double XAxis;
34  double YAxis;
35  double ZAxis;
36  };
37 
38  public:
39  explicit ADXL362(Range range = kRange_2G);
40  explicit ADXL362(SPI::Port port, Range range = kRange_2G);
41  virtual ~ADXL362() = default;
42 
43  ADXL362(const ADXL362&) = delete;
44  ADXL362& operator=(const ADXL362&) = delete;
45 
46  // Accelerometer interface
47  void SetRange(Range range) override;
48  double GetX() override;
49  double GetY() override;
50  double GetZ() override;
51 
52  virtual double GetAcceleration(Axes axis);
53  virtual AllAxes GetAccelerations();
54 
55  std::string GetSmartDashboardType() const override;
56  void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
57  void UpdateTable() override;
58  void StartLiveWindowMode() override {}
59  void StopLiveWindowMode() override {}
60 
61  private:
62  SPI m_spi;
63  double m_gsPerLSB = 0.001;
64 
65  nt::NetworkTableEntry m_xEntry;
66  nt::NetworkTableEntry m_yEntry;
67  nt::NetworkTableEntry m_zEntry;
68 };
69 
70 } // namespace frc
void InitTable(std::shared_ptr< nt::NetworkTable > subtable) override
Initializes a table for this sendable object.
Definition: ADXL362.cpp:170
Definition: Timer.cpp:18
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:17
virtual AllAxes GetAccelerations()
Get the acceleration of all axes in Gs.
Definition: ADXL362.cpp:139
double GetY() override
Common interface for getting the y axis acceleration.
Definition: ADXL362.cpp:109
std::string GetSmartDashboardType() const override
Definition: ADXL362.cpp:166
SPI bus interface class.
Definition: SPI.h:28
ADXL362 SPI Accelerometer.
Definition: ADXL362.h:29
Definition: ADXL362.h:32
void SetRange(Range range) override
Common interface for setting the measuring range of an accelerometer.
Definition: ADXL362.cpp:81
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: ADXL362.h:59
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: ADXL362.h:58
Class to write to digital outputs.
Definition: DigitalOutput.h:27
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: ADXL362.cpp:183
NetworkTables Entry.
Definition: NetworkTableEntry.h:30
Interface for 3-axis accelerometers.
Definition: Accelerometer.h:15
Class to read a digital input.
Definition: DigitalInput.h:29
double GetX() override
Common interface for getting the x axis acceleration.
Definition: ADXL362.cpp:107
double GetZ() override
Common interface for getting the z axis acceleration.
Definition: ADXL362.cpp:111
ADXL362(Range range=kRange_2G)
Constructor.
Definition: ADXL362.cpp:41
virtual double GetAcceleration(Axes axis)
Get the acceleration of one axis in Gs.
Definition: ADXL362.cpp:119