WPILibC++ 2025.0.0-alpha-1-9-ga2beb75
BuiltInAccelerometerSim.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
9#include <hal/Accelerometer.h>
10
12
13namespace frc {
14
15class BuiltInAccelerometer;
16
17namespace sim {
18
19/**
20 * Class to control a simulated built-in accelerometer.
21 */
23 public:
24 /**
25 * Constructs for the first built-in accelerometer.
26 */
28
29 /**
30 * Constructs from a BuiltInAccelerometer object.
31 *
32 * @param accel BuiltInAccelerometer to simulate
33 */
35
36 /**
37 * Register a callback to be run when this accelerometer activates.
38 *
39 * @param callback the callback
40 * @param initialNotify whether to run the callback with the initial state
41 * @return the CallbackStore object associated with this callback
42 */
43 [[nodiscard]]
44 std::unique_ptr<CallbackStore> RegisterActiveCallback(NotifyCallback callback,
45 bool initialNotify);
46
47 /**
48 * Check whether the accelerometer is active.
49 *
50 * @return true if active
51 */
52 bool GetActive() const;
53
54 /**
55 * Define whether this accelerometer is active.
56 *
57 * @param active the new state
58 */
59 void SetActive(bool active);
60
61 /**
62 * Register a callback to be run whenever the range changes.
63 *
64 * @param callback the callback
65 * @param initialNotify whether to call the callback with the initial state
66 * @return the CallbackStore object associated with this callback
67 */
68 [[nodiscard]]
69 std::unique_ptr<CallbackStore> RegisterRangeCallback(NotifyCallback callback,
70 bool initialNotify);
71
72 /**
73 * Check the range of this accelerometer.
74 *
75 * @return the accelerometer range
76 */
78
79 /**
80 * Change the range of this accelerometer.
81 *
82 * @param range the new accelerometer range
83 */
85
86 /**
87 * Register a callback to be run whenever the X axis value changes.
88 *
89 * @param callback the callback
90 * @param initialNotify whether to call the callback with the initial state
91 * @return the CallbackStore object associated with this callback
92 */
93 [[nodiscard]]
94 std::unique_ptr<CallbackStore> RegisterXCallback(NotifyCallback callback,
95 bool initialNotify);
96
97 /**
98 * Measure the X axis value.
99 *
100 * @return the X axis measurement
101 */
102 double GetX() const;
103
104 /**
105 * Change the X axis value of the accelerometer.
106 *
107 * @param x the new reading of the X axis
108 */
109 void SetX(double x);
110
111 /**
112 * Register a callback to be run whenever the Y axis value changes.
113 *
114 * @param callback the callback
115 * @param initialNotify whether to call the callback with the initial state
116 * @return the CallbackStore object associated with this callback
117 */
118 [[nodiscard]]
119 std::unique_ptr<CallbackStore> RegisterYCallback(NotifyCallback callback,
120 bool initialNotify);
121
122 /**
123 * Measure the Y axis value.
124 *
125 * @return the Y axis measurement
126 */
127 double GetY() const;
128
129 /**
130 * Change the Y axis value of the accelerometer.
131 *
132 * @param y the new reading of the Y axis
133 */
134 void SetY(double y);
135
136 /**
137 * Register a callback to be run whenever the Z axis value changes.
138 *
139 * @param callback the callback
140 * @param initialNotify whether to call the callback with the initial state
141 * @return the CallbackStore object associated with this callback
142 */
143 [[nodiscard]]
144 std::unique_ptr<CallbackStore> RegisterZCallback(NotifyCallback callback,
145 bool initialNotify);
146
147 /**
148 * Measure the Z axis value.
149 *
150 * @return the Z axis measurement
151 */
152 double GetZ() const;
153
154 /**
155 * Change the Z axis value of the accelerometer.
156 *
157 * @param z the new reading of the Z axis
158 */
159 void SetZ(double z);
160
161 /**
162 * Reset all simulation data of this object.
163 */
164 void ResetData();
165
166 private:
167 int m_index;
168};
169} // namespace sim
170} // namespace frc
Built-in accelerometer.
Definition: BuiltInAccelerometer.h:18
Class to control a simulated built-in accelerometer.
Definition: BuiltInAccelerometerSim.h:22
void SetZ(double z)
Change the Z axis value of the accelerometer.
BuiltInAccelerometerSim(const BuiltInAccelerometer &accel)
Constructs from a BuiltInAccelerometer object.
bool GetActive() const
Check whether the accelerometer is active.
void SetRange(HAL_AccelerometerRange range)
Change the range of this accelerometer.
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 ResetData()
Reset all simulation data of this object.
std::unique_ptr< CallbackStore > RegisterRangeCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the range changes.
std::unique_ptr< CallbackStore > RegisterActiveCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run when this accelerometer activates.
double GetX() const
Measure the X axis value.
HAL_AccelerometerRange GetRange() const
Check the range of this accelerometer.
void SetY(double y)
Change the Y axis value of the accelerometer.
double GetY() const
Measure the Y axis value.
double GetZ() const
Measure the Z axis value.
std::unique_ptr< CallbackStore > RegisterYCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the Y axis value changes.
BuiltInAccelerometerSim()
Constructs for the first built-in accelerometer.
void SetX(double x)
Change the X axis value of the accelerometer.
std::unique_ptr< CallbackStore > RegisterZCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the Z axis value changes.
HAL_AccelerometerRange
The acceptable accelerometer ranges.
Definition: Accelerometer.h:18
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14
Definition: AprilTagDetector_cv.h:11