WPILibC++ 2024.1.1-beta-4
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"
12
13namespace frc {
14
15/**
16 * ADXL362 SPI Accelerometer.
17 *
18 * This class allows access to an Analog Devices ADXL362 3-axis accelerometer.
19 */
20class ADXL362 : public nt::NTSendable, public wpi::SendableHelper<ADXL362> {
21 public:
22 enum Range { kRange_2G = 0, kRange_4G = 1, kRange_8G = 2 };
23
24 enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
25 struct AllAxes {
26 double XAxis;
27 double YAxis;
28 double ZAxis;
29 };
30
31 public:
32 /**
33 * Constructor. Uses the onboard CS1.
34 *
35 * @param range The range (+ or -) that the accelerometer will measure.
36 */
37 explicit ADXL362(Range range = kRange_2G);
38
39 /**
40 * Constructor.
41 *
42 * @param port The SPI port the accelerometer is attached to
43 * @param range The range (+ or -) that the accelerometer will measure.
44 */
45 explicit ADXL362(SPI::Port port, Range range = kRange_2G);
46
47 ~ADXL362() override = default;
48
49 ADXL362(ADXL362&&) = default;
50 ADXL362& operator=(ADXL362&&) = default;
51
53
54 /**
55 * Set the measuring range of the accelerometer.
56 *
57 * @param range The maximum acceleration, positive or negative, that the
58 * accelerometer will measure.
59 */
60 void SetRange(Range range);
61
62 /**
63 * Returns the acceleration along the X axis in g-forces.
64 *
65 * @return The acceleration along the X axis in g-forces.
66 */
67 double GetX();
68
69 /**
70 * Returns the acceleration along the Y axis in g-forces.
71 *
72 * @return The acceleration along the Y axis in g-forces.
73 */
74 double GetY();
75
76 /**
77 * Returns the acceleration along the Z axis in g-forces.
78 *
79 * @return The acceleration along the Z axis in g-forces.
80 */
81 double GetZ();
82
83 /**
84 * Get the acceleration of one axis in Gs.
85 *
86 * @param axis The axis to read from.
87 * @return Acceleration of the ADXL362 in Gs.
88 */
89 virtual double GetAcceleration(Axes axis);
90
91 /**
92 * Get the acceleration of all axes in Gs.
93 *
94 * @return An object containing the acceleration measured on each axis of the
95 * ADXL362 in Gs.
96 */
98
99 void InitSendable(nt::NTSendableBuilder& builder) override;
100
101 private:
102 SPI m_spi;
103 hal::SimDevice m_simDevice;
104 hal::SimEnum m_simRange;
105 hal::SimDouble m_simX;
106 hal::SimDouble m_simY;
107 hal::SimDouble m_simZ;
108 double m_gsPerLSB = 0.001;
109};
110
111} // namespace frc
ADXL362 SPI Accelerometer.
Definition: ADXL362.h:20
ADXL362(SPI::Port port, Range range=kRange_2G)
Constructor.
~ADXL362() override=default
void SetRange(Range range)
Set the measuring range of the accelerometer.
Range
Definition: ADXL362.h:22
@ kRange_8G
Definition: ADXL362.h:22
@ kRange_2G
Definition: ADXL362.h:22
@ kRange_4G
Definition: ADXL362.h:22
virtual AllAxes GetAccelerations()
Get the acceleration of all axes in Gs.
double GetX()
Returns the acceleration along the X axis in g-forces.
virtual double GetAcceleration(Axes axis)
Get the acceleration of one axis in Gs.
ADXL362 & operator=(ADXL362 &&)=default
Axes
Definition: ADXL362.h:24
@ kAxis_X
Definition: ADXL362.h:24
@ kAxis_Y
Definition: ADXL362.h:24
@ kAxis_Z
Definition: ADXL362.h:24
double GetY()
Returns the acceleration along the Y axis in g-forces.
ADXL362(ADXL362 &&)=default
SPI::Port GetSpiPort() const
double GetZ()
Returns the acceleration along the Z axis in g-forces.
void InitSendable(nt::NTSendableBuilder &builder) override
Initializes this Sendable object.
ADXL362(Range range=kRange_2G)
Constructor.
SPI bus interface class.
Definition: SPI.h:26
Port
Definition: SPI.h:28
A move-only C++ wrapper around a HAL simulator device handle.
Definition: SimDevice.h:644
C++ wrapper around a HAL simulator double value handle.
Definition: SimDevice.h:535
C++ wrapper around a HAL simulator enum value handle.
Definition: SimDevice.h:576
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: AprilTagPoseEstimator.h:15
Definition: ADXL362.h:25
double YAxis
Definition: ADXL362.h:27
double XAxis
Definition: ADXL362.h:26
double ZAxis
Definition: ADXL362.h:28