WPILibC++ 2023.4.3
SPIAccelerometerSim.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 <memory>
8
10
11namespace frc::sim {
13 public:
14 /**
15 * Construct a new simulation object.
16 *
17 * @param index the HAL index of the accelerometer
18 */
19 explicit SPIAccelerometerSim(int index);
20
21 /**
22 * Register a callback to be run when this accelerometer activates.
23 *
24 * @param callback the callback
25 * @param initialNotify whether to run the callback with the initial state
26 * @return the CallbackStore object associated with this callback
27 */
28 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterActiveCallback(
29 NotifyCallback callback, bool initialNotify);
30
31 /**
32 * Check whether the accelerometer is active.
33 *
34 * @return true if active
35 */
36 bool GetActive() const;
37
38 /**
39 * Define whether this accelerometer is active.
40 *
41 * @param active the new state
42 */
43 void SetActive(bool active);
44
45 /**
46 * Register a callback to be run whenever the range changes.
47 *
48 * @param callback the callback
49 * @param initialNotify whether to call the callback with the initial state
50 * @return the CallbackStore object associated with this callback
51 */
52 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterRangeCallback(
53 NotifyCallback callback, bool initialNotify);
54
55 /**
56 * Check the range of this accelerometer.
57 *
58 * @return the accelerometer range
59 */
60 int GetRange() const;
61
62 /**
63 * Change the range of this accelerometer.
64 *
65 * @param range the new accelerometer range
66 */
67 void SetRange(int range);
68
69 /**
70 * Register a callback to be run whenever the X axis value changes.
71 *
72 * @param callback the callback
73 * @param initialNotify whether to call the callback with the initial state
74 * @return the CallbackStore object associated with this callback
75 */
76 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterXCallback(
77 NotifyCallback callback, bool initialNotify);
78
79 /**
80 * Measure the X axis value.
81 *
82 * @return the X axis measurement
83 */
84 double GetX() const;
85
86 /**
87 * Change the X axis value of the accelerometer.
88 *
89 * @param x the new reading of the X axis
90 */
91 void SetX(double x);
92
93 /**
94 * Register a callback to be run whenever the Y axis value changes.
95 *
96 * @param callback the callback
97 * @param initialNotify whether to call the callback with the initial state
98 * @return the CallbackStore object associated with this callback
99 */
100 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterYCallback(
101 NotifyCallback callback, bool initialNotify);
102
103 /**
104 * Measure the Y axis value.
105 *
106 * @return the Y axis measurement
107 */
108 double GetY() const;
109
110 /**
111 * Change the Y axis value of the accelerometer.
112 *
113 * @param y the new reading of the Y axis
114 */
115 void SetY(double y);
116
117 /**
118 * Register a callback to be run whenever the Z axis value changes.
119 *
120 * @param callback the callback
121 * @param initialNotify whether to call the callback with the initial state
122 * @return the CallbackStore object associated with this callback
123 */
124 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterZCallback(
125 NotifyCallback callback, bool initialNotify);
126
127 /**
128 * Measure the Z axis value.
129 *
130 * @return the Z axis measurement
131 */
132 double GetZ() const;
133
134 /**
135 * Change the Z axis value of the accelerometer.
136 *
137 * @param z the new reading of the Z axis
138 */
139 void SetZ(double z);
140
141 /**
142 * Reset all simulation data of this object.
143 */
144 void ResetData();
145
146 private:
147 int m_index;
148};
149} // namespace frc::sim
Definition: SPIAccelerometerSim.h:12
SPIAccelerometerSim(int index)
Construct a new simulation object.
double GetY() const
Measure the Y axis value.
void SetRange(int range)
Change the range of this accelerometer.
std::unique_ptr< CallbackStore > RegisterActiveCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run when this accelerometer activates.
std::unique_ptr< CallbackStore > RegisterXCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the X axis value changes.
void SetActive(bool active)
Define whether this accelerometer is active.
void SetY(double y)
Change the Y axis value of the accelerometer.
int GetRange() const
Check the range of this accelerometer.
std::unique_ptr< CallbackStore > RegisterYCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the Y axis value changes.
std::unique_ptr< CallbackStore > RegisterRangeCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the range changes.
double GetX() const
Measure the X axis value.
void SetX(double x)
Change the X axis value of the accelerometer.
void ResetData()
Reset all simulation data of this object.
bool GetActive() const
Check whether the accelerometer is active.
void SetZ(double z)
Change the Z axis value of the accelerometer.
double GetZ() const
Measure the Z axis value.
std::unique_ptr< CallbackStore > RegisterZCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the Z axis value changes.
const Scalar & y
Definition: MathFunctions.h:821
Definition: AnalogOutputSim.h:15
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14