WPILibC++ 2023.4.3
ADXL362.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <hal/SimDevice.h>
10
11#include "frc/SPI.h"
13
14namespace frc {
15
16/**
17 * ADXL362 SPI Accelerometer.
18 *
19 * This class allows access to an Analog Devices ADXL362 3-axis accelerometer.
20 */
21class ADXL362 : public Accelerometer,
22 public nt::NTSendable,
23 public wpi::SendableHelper<ADXL362> {
24 public:
25 enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
26 struct AllAxes {
27 double XAxis;
28 double YAxis;
29 double ZAxis;
30 };
31
32 public:
33 /**
34 * Constructor. Uses the onboard CS1.
35 *
36 * @param range The range (+ or -) that the accelerometer will measure.
37 */
38 explicit ADXL362(Range range = kRange_2G);
39
40 /**
41 * Constructor.
42 *
43 * @param port The SPI port the accelerometer is attached to
44 * @param range The range (+ or -) that the accelerometer will measure.
45 */
46 explicit ADXL362(SPI::Port port, Range range = kRange_2G);
47
48 ~ADXL362() override = default;
49
50 ADXL362(ADXL362&&) = default;
51 ADXL362& operator=(ADXL362&&) = default;
52
54
55 // Accelerometer interface
56 void SetRange(Range range) final;
57 double GetX() override;
58 double GetY() override;
59 double GetZ() override;
60
61 /**
62 * Get the acceleration of one axis in Gs.
63 *
64 * @param axis The axis to read from.
65 * @return Acceleration of the ADXL362 in Gs.
66 */
67 virtual double GetAcceleration(Axes axis);
68
69 /**
70 * Get the acceleration of all axes in Gs.
71 *
72 * @return An object containing the acceleration measured on each axis of the
73 * ADXL362 in Gs.
74 */
76
77 void InitSendable(nt::NTSendableBuilder& builder) override;
78
79 private:
80 SPI m_spi;
81 hal::SimDevice m_simDevice;
82 hal::SimEnum m_simRange;
83 hal::SimDouble m_simX;
84 hal::SimDouble m_simY;
85 hal::SimDouble m_simZ;
86 double m_gsPerLSB = 0.001;
87};
88
89} // namespace frc
ADXL362 SPI Accelerometer.
Definition: ADXL362.h:23
ADXL362(SPI::Port port, Range range=kRange_2G)
Constructor.
~ADXL362() override=default
virtual AllAxes GetAccelerations()
Get the acceleration of all axes in Gs.
virtual double GetAcceleration(Axes axis)
Get the acceleration of one axis in Gs.
ADXL362 & operator=(ADXL362 &&)=default
void SetRange(Range range) final
Common interface for setting the measuring range of an accelerometer.
Axes
Definition: ADXL362.h:25
@ kAxis_X
Definition: ADXL362.h:25
@ kAxis_Y
Definition: ADXL362.h:25
@ kAxis_Z
Definition: ADXL362.h:25
double GetY() override
Common interface for getting the y axis acceleration.
double GetZ() override
Common interface for getting the z axis acceleration.
ADXL362(ADXL362 &&)=default
double GetX() override
Common interface for getting the x axis acceleration.
SPI::Port GetSpiPort() const
void InitSendable(nt::NTSendableBuilder &builder) override
Initializes this Sendable object.
ADXL362(Range range=kRange_2G)
Constructor.
Interface for 3-axis accelerometers.
Definition: Accelerometer.h:12
Range
Definition: Accelerometer.h:20
@ kRange_2G
Definition: Accelerometer.h:20
SPI bus interface class.
Definition: SPI.h:27
Port
Definition: SPI.h:29
Definition: NTSendableBuilder.h:18
Interface for NetworkTable Sendable objects.
Definition: NTSendable.h:16
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:19
Definition: AprilTagFieldLayout.h:22
Definition: ADXL362.h:26
double YAxis
Definition: ADXL362.h:28
double XAxis
Definition: ADXL362.h:27
double ZAxis
Definition: ADXL362.h:29