WPILibC++ 2023.4.3
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]] std::unique_ptr<CallbackStore> RegisterActiveCallback(
44 NotifyCallback callback, bool initialNotify);
45
46 /**
47 * Check whether the accelerometer is active.
48 *
49 * @return true if active
50 */
51 bool GetActive() const;
52
53 /**
54 * Define whether this accelerometer is active.
55 *
56 * @param active the new state
57 */
58 void SetActive(bool active);
59
60 /**
61 * Register a callback to be run whenever the range changes.
62 *
63 * @param callback the callback
64 * @param initialNotify whether to call the callback with the initial state
65 * @return the CallbackStore object associated with this callback
66 */
67 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterRangeCallback(
68 NotifyCallback callback, bool initialNotify);
69
70 /**
71 * Check the range of this accelerometer.
72 *
73 * @return the accelerometer range
74 */
75 HAL_AccelerometerRange GetRange() const;
76
77 /**
78 * Change the range of this accelerometer.
79 *
80 * @param range the new accelerometer range
81 */
82 void SetRange(HAL_AccelerometerRange range);
83
84 /**
85 * Register a callback to be run whenever the X axis value changes.
86 *
87 * @param callback the callback
88 * @param initialNotify whether to call the callback with the initial state
89 * @return the CallbackStore object associated with this callback
90 */
91 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterXCallback(
92 NotifyCallback callback, bool initialNotify);
93
94 /**
95 * Measure the X axis value.
96 *
97 * @return the X axis measurement
98 */
99 double GetX() const;
100
101 /**
102 * Change the X axis value of the accelerometer.
103 *
104 * @param x the new reading of the X axis
105 */
106 void SetX(double x);
107
108 /**
109 * Register a callback to be run whenever the Y axis value changes.
110 *
111 * @param callback the callback
112 * @param initialNotify whether to call the callback with the initial state
113 * @return the CallbackStore object associated with this callback
114 */
115 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterYCallback(
116 NotifyCallback callback, bool initialNotify);
117
118 /**
119 * Measure the Y axis value.
120 *
121 * @return the Y axis measurement
122 */
123 double GetY() const;
124
125 /**
126 * Change the Y axis value of the accelerometer.
127 *
128 * @param y the new reading of the Y axis
129 */
130 void SetY(double y);
131
132 /**
133 * Register a callback to be run whenever the Z axis value changes.
134 *
135 * @param callback the callback
136 * @param initialNotify whether to call the callback with the initial state
137 * @return the CallbackStore object associated with this callback
138 */
139 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterZCallback(
140 NotifyCallback callback, bool initialNotify);
141
142 /**
143 * Measure the Z axis value.
144 *
145 * @return the Z axis measurement
146 */
147 double GetZ() const;
148
149 /**
150 * Change the Z axis value of the accelerometer.
151 *
152 * @param z the new reading of the Z axis
153 */
154 void SetZ(double z);
155
156 /**
157 * Reset all simulation data of this object.
158 */
159 void ResetData();
160
161 private:
162 int m_index;
163};
164} // namespace sim
165} // namespace frc
Built-in accelerometer.
Definition: BuiltInAccelerometer.h:21
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.
const Scalar & y
Definition: MathFunctions.h:821
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14
Definition: AprilTagFieldLayout.h:22