WPILibC++
2023.4.3-108-ge5452e3
AnalogInputSim.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 "
frc/simulation/CallbackStore.h
"
10
11
namespace
frc
{
12
13
class
AnalogInput
;
14
15
namespace
sim {
16
17
/**
18
* Class to control a simulated analog input.
19
*/
20
class
AnalogInputSim
{
21
public
:
22
/**
23
* Constructs from an AnalogInput object.
24
*
25
* @param analogInput AnalogInput to simulate
26
*/
27
explicit
AnalogInputSim
(
const
AnalogInput
& analogInput);
28
29
/**
30
* Constructs from an analog input channel number.
31
*
32
* @param channel Channel number
33
*/
34
explicit
AnalogInputSim
(
int
channel);
35
36
/**
37
* Register a callback on whether the analog input is initialized.
38
*
39
* @param callback the callback that will be called whenever the analog input
40
* is initialized
41
* @param initialNotify if true, the callback will be run on the initial value
42
* @return the CallbackStore object associated with this callback
43
*/
44
[[nodiscard]]
45
std::unique_ptr<CallbackStore>
RegisterInitializedCallback
(
46
NotifyCallback
callback,
bool
initialNotify);
47
48
/**
49
* Check if this analog input has been initialized.
50
*
51
* @return true if initialized
52
*/
53
bool
GetInitialized
()
const
;
54
55
/**
56
* Change whether this analog input has been initialized.
57
*
58
* @param initialized the new value
59
*/
60
void
SetInitialized
(
bool
initialized);
61
62
/**
63
* Register a callback on the number of average bits.
64
*
65
* @param callback the callback that will be called whenever the number of
66
* average bits is changed
67
* @param initialNotify if true, the callback will be run on the initial value
68
* @return the CallbackStore object associated with this callback
69
*/
70
[[nodiscard]]
71
std::unique_ptr<CallbackStore>
RegisterAverageBitsCallback
(
72
NotifyCallback
callback,
bool
initialNotify);
73
74
/**
75
* Get the number of average bits.
76
*
77
* @return the number of average bits
78
*/
79
int
GetAverageBits
()
const
;
80
81
/**
82
* Change the number of average bits.
83
*
84
* @param averageBits the new value
85
*/
86
void
SetAverageBits
(
int
averageBits);
87
88
/**
89
* Register a callback on the amount of oversampling bits.
90
*
91
* @param callback the callback that will be called whenever the oversampling
92
* bits are changed
93
* @param initialNotify if true, the callback will be run on the initial value
94
* @return the CallbackStore object associated with this callback
95
*/
96
[[nodiscard]]
97
std::unique_ptr<CallbackStore>
RegisterOversampleBitsCallback
(
98
NotifyCallback
callback,
bool
initialNotify);
99
100
/**
101
* Get the amount of oversampling bits.
102
*
103
* @return the amount of oversampling bits
104
*/
105
int
GetOversampleBits
()
const
;
106
107
/**
108
* Change the amount of oversampling bits.
109
*
110
* @param oversampleBits the new value
111
*/
112
void
SetOversampleBits
(
int
oversampleBits);
113
114
/**
115
* Register a callback on the voltage.
116
*
117
* @param callback the callback that will be called whenever the voltage is
118
* changed
119
* @param initialNotify if true, the callback will be run on the initial value
120
* @return the CallbackStore object associated with this callback
121
*/
122
[[nodiscard]]
123
std::unique_ptr<CallbackStore>
RegisterVoltageCallback
(
124
NotifyCallback
callback,
bool
initialNotify);
125
126
/**
127
* Get the voltage.
128
*
129
* @return the voltage
130
*/
131
double
GetVoltage
()
const
;
132
133
/**
134
* Change the voltage.
135
*
136
* @param voltage the new value
137
*/
138
void
SetVoltage
(
double
voltage);
139
140
/**
141
* Register a callback on whether the accumulator is initialized.
142
*
143
* @param callback the callback that will be called whenever the accumulator
144
* is initialized
145
* @param initialNotify if true, the callback will be run on the initial value
146
* @return the CallbackStore object associated with this callback
147
*/
148
[[nodiscard]]
149
std::unique_ptr<CallbackStore>
RegisterAccumulatorInitializedCallback
(
150
NotifyCallback
callback,
bool
initialNotify);
151
152
/**
153
* Check if the accumulator has been initialized.
154
*
155
* @return true if initialized
156
*/
157
bool
GetAccumulatorInitialized
()
const
;
158
159
/**
160
* Change whether the accumulator has been initialized.
161
*
162
* @param accumulatorInitialized the new value
163
*/
164
void
SetAccumulatorInitialized
(
bool
accumulatorInitialized);
165
166
/**
167
* Register a callback on the accumulator value.
168
*
169
* @param callback the callback that will be called whenever the accumulator
170
* value is changed
171
* @param initialNotify if true, the callback will be run on the initial value
172
* @return the CallbackStore object associated with this callback
173
*/
174
[[nodiscard]]
175
std::unique_ptr<CallbackStore>
RegisterAccumulatorValueCallback
(
176
NotifyCallback
callback,
bool
initialNotify);
177
178
/**
179
* Get the accumulator value.
180
*
181
* @return the accumulator value
182
*/
183
int64_t
GetAccumulatorValue
()
const
;
184
185
/**
186
* Change the accumulator value.
187
*
188
* @param accumulatorValue the new value
189
*/
190
void
SetAccumulatorValue
(
int64_t
accumulatorValue);
191
192
/**
193
* Register a callback on the accumulator count.
194
*
195
* @param callback the callback that will be called whenever the accumulator
196
* count is changed
197
* @param initialNotify if true, the callback will be run on the initial value
198
* @return the CallbackStore object associated with this callback
199
*/
200
[[nodiscard]]
201
std::unique_ptr<CallbackStore>
RegisterAccumulatorCountCallback
(
202
NotifyCallback
callback,
bool
initialNotify);
203
204
/**
205
* Get the accumulator count.
206
*
207
* @return the accumulator count.
208
*/
209
int64_t
GetAccumulatorCount
()
const
;
210
211
/**
212
* Change the accumulator count.
213
*
214
* @param accumulatorCount the new count.
215
*/
216
void
SetAccumulatorCount
(
int64_t
accumulatorCount);
217
218
/**
219
* Register a callback on the accumulator center.
220
*
221
* @param callback the callback that will be called whenever the accumulator
222
* center is changed
223
* @param initialNotify if true, the callback will be run on the initial value
224
* @return the CallbackStore object associated with this callback
225
*/
226
[[nodiscard]]
227
std::unique_ptr<CallbackStore>
RegisterAccumulatorCenterCallback
(
228
NotifyCallback
callback,
bool
initialNotify);
229
230
/**
231
* Get the accumulator center.
232
*
233
* @return the accumulator center
234
*/
235
int
GetAccumulatorCenter
()
const
;
236
237
/**
238
* Change the accumulator center.
239
*
240
* @param accumulatorCenter the new center
241
*/
242
void
SetAccumulatorCenter
(
int
accumulatorCenter);
243
244
/**
245
* Register a callback on the accumulator deadband.
246
*
247
* @param callback the callback that will be called whenever the accumulator
248
* deadband is changed
249
* @param initialNotify if true, the callback will be run on the initial value
250
* @return the CallbackStore object associated with this callback
251
*/
252
[[nodiscard]]
253
std::unique_ptr<CallbackStore>
RegisterAccumulatorDeadbandCallback
(
254
NotifyCallback
callback,
bool
initialNotify);
255
256
/**
257
* Get the accumulator deadband.
258
*
259
* @return the accumulator deadband
260
*/
261
int
GetAccumulatorDeadband
()
const
;
262
263
/**
264
* Change the accumulator deadband.
265
*
266
* @param accumulatorDeadband the new deadband
267
*/
268
void
SetAccumulatorDeadband
(
int
accumulatorDeadband);
269
270
/**
271
* Reset all simulation data for this object.
272
*/
273
void
ResetData
();
274
275
private
:
276
int
m_index;
277
};
278
}
// namespace sim
279
}
// namespace frc
CallbackStore.h
frc::AnalogInput
Analog input class.
Definition:
AnalogInput.h:31
frc::sim::AnalogInputSim
Class to control a simulated analog input.
Definition:
AnalogInputSim.h:20
frc::sim::AnalogInputSim::RegisterAccumulatorValueCallback
std::unique_ptr< CallbackStore > RegisterAccumulatorValueCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the accumulator value.
frc::sim::AnalogInputSim::RegisterAverageBitsCallback
std::unique_ptr< CallbackStore > RegisterAverageBitsCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the number of average bits.
frc::sim::AnalogInputSim::GetAccumulatorDeadband
int GetAccumulatorDeadband() const
Get the accumulator deadband.
frc::sim::AnalogInputSim::GetAverageBits
int GetAverageBits() const
Get the number of average bits.
frc::sim::AnalogInputSim::GetInitialized
bool GetInitialized() const
Check if this analog input has been initialized.
frc::sim::AnalogInputSim::SetAccumulatorCount
void SetAccumulatorCount(int64_t accumulatorCount)
Change the accumulator count.
frc::sim::AnalogInputSim::RegisterAccumulatorDeadbandCallback
std::unique_ptr< CallbackStore > RegisterAccumulatorDeadbandCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the accumulator deadband.
frc::sim::AnalogInputSim::GetAccumulatorCenter
int GetAccumulatorCenter() const
Get the accumulator center.
frc::sim::AnalogInputSim::GetVoltage
double GetVoltage() const
Get the voltage.
frc::sim::AnalogInputSim::GetOversampleBits
int GetOversampleBits() const
Get the amount of oversampling bits.
frc::sim::AnalogInputSim::RegisterAccumulatorCenterCallback
std::unique_ptr< CallbackStore > RegisterAccumulatorCenterCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the accumulator center.
frc::sim::AnalogInputSim::SetVoltage
void SetVoltage(double voltage)
Change the voltage.
frc::sim::AnalogInputSim::SetAccumulatorInitialized
void SetAccumulatorInitialized(bool accumulatorInitialized)
Change whether the accumulator has been initialized.
frc::sim::AnalogInputSim::RegisterInitializedCallback
std::unique_ptr< CallbackStore > RegisterInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the analog input is initialized.
frc::sim::AnalogInputSim::SetInitialized
void SetInitialized(bool initialized)
Change whether this analog input has been initialized.
frc::sim::AnalogInputSim::GetAccumulatorCount
int64_t GetAccumulatorCount() const
Get the accumulator count.
frc::sim::AnalogInputSim::RegisterOversampleBitsCallback
std::unique_ptr< CallbackStore > RegisterOversampleBitsCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the amount of oversampling bits.
frc::sim::AnalogInputSim::RegisterAccumulatorCountCallback
std::unique_ptr< CallbackStore > RegisterAccumulatorCountCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the accumulator count.
frc::sim::AnalogInputSim::GetAccumulatorValue
int64_t GetAccumulatorValue() const
Get the accumulator value.
frc::sim::AnalogInputSim::AnalogInputSim
AnalogInputSim(const AnalogInput &analogInput)
Constructs from an AnalogInput object.
frc::sim::AnalogInputSim::SetAccumulatorValue
void SetAccumulatorValue(int64_t accumulatorValue)
Change the accumulator value.
frc::sim::AnalogInputSim::RegisterVoltageCallback
std::unique_ptr< CallbackStore > RegisterVoltageCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the voltage.
frc::sim::AnalogInputSim::SetAccumulatorCenter
void SetAccumulatorCenter(int accumulatorCenter)
Change the accumulator center.
frc::sim::AnalogInputSim::SetAccumulatorDeadband
void SetAccumulatorDeadband(int accumulatorDeadband)
Change the accumulator deadband.
frc::sim::AnalogInputSim::AnalogInputSim
AnalogInputSim(int channel)
Constructs from an analog input channel number.
frc::sim::AnalogInputSim::GetAccumulatorInitialized
bool GetAccumulatorInitialized() const
Check if the accumulator has been initialized.
frc::sim::AnalogInputSim::SetOversampleBits
void SetOversampleBits(int oversampleBits)
Change the amount of oversampling bits.
frc::sim::AnalogInputSim::SetAverageBits
void SetAverageBits(int averageBits)
Change the number of average bits.
frc::sim::AnalogInputSim::ResetData
void ResetData()
Reset all simulation data for this object.
frc::sim::AnalogInputSim::RegisterAccumulatorInitializedCallback
std::unique_ptr< CallbackStore > RegisterAccumulatorInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the accumulator is initialized.
Eigen::numext::int64_t
::int64_t int64_t
Definition:
Meta.h:59
frc::sim::NotifyCallback
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition:
CallbackStore.h:14
frc
Definition:
AprilTagPoseEstimator.h:15
hal::HAL_HandleEnum::AnalogInput
@ AnalogInput
frc
simulation
AnalogInputSim.h
Generated on Mon Jul 10 2023 17:02:43 for WPILibC++ by
1.9.4