1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <memory>
#include "frc/simulation/CallbackStore.h"
namespace frc {
class PWM;
class PWMMotorController;
namespace sim {
/**
* Class to control a simulated PWM output.
*/
class PWMSim {
public:
/**
* Constructs from a PWM object.
*
* @param pwm PWM to simulate
*/
explicit PWMSim(const PWM& pwm);
/**
* Constructs from a PWMMotorController object.
*
* @param motorctrl PWMMotorController to simulate
*/
explicit PWMSim(const PWMMotorController& motorctrl);
/**
* Constructs from a PWM channel number.
*
* @param channel Channel number
*/
explicit PWMSim(int channel);
/**
* Register a callback to be run when the PWM is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether the PWM has been initialized.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Define whether the PWM has been initialized.
*
* @param initialized whether this object is initialized
*/
void SetInitialized(bool initialized);
/**
* Register a callback to be run when the PWM pulse microsecond value changes.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterPulseMicrosecondCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the PWM pulse microsecond value.
*
* @return the PWM pulse microsecond value
*/
int32_t GetPulseMicrosecond() const;
/**
* Set the PWM pulse microsecond value.
*
* @param microsecondPulseTime the PWM pulse microsecond value
*/
void SetPulseMicrosecond(int32_t microsecondPulseTime);
/**
* Register a callback to be run when the PWM speed changes.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterSpeedCallback(NotifyCallback callback,
bool initialNotify);
/**
* Get the PWM speed.
*
* @return the PWM speed (-1.0 to 1.0)
*/
double GetSpeed() const;
/**
* Set the PWM speed.
*
* @param speed the PWM speed (-1.0 to 1.0)
*/
void SetSpeed(double speed);
/**
* Register a callback to be run when the PWM position changes.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterPositionCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the PWM position.
*
* @return the PWM position (0.0 to 1.0)
*/
double GetPosition() const;
/**
* Set the PWM position.
*
* @param position the PWM position (0.0 to 1.0)
*/
void SetPosition(double position);
/**
* Register a callback to be run when the PWM period scale changes.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterPeriodScaleCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the PWM period scale.
*
* @return the PWM period scale
*/
int GetPeriodScale() const;
/**
* Set the PWM period scale.
*
* @param periodScale the PWM period scale
*/
void SetPeriodScale(int periodScale);
/**
* Register a callback to be run when the PWM zero latch state changes.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterZeroLatchCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether the PWM is zero latched.
*
* @return true if zero latched
*/
bool GetZeroLatch() const;
/**
* Define whether the PWM has been zero latched.
*
* @param zeroLatch true to indicate zero latched
*/
void SetZeroLatch(bool zeroLatch);
/**
* Reset all simulation data.
*/
void ResetData();
private:
int m_index;
};
} // namespace sim
} // namespace frc