@@ -197,15 +197,13 @@ A duty cycle encoder can be instantiated as follows:
197
197
198
198
.. tab-set-code ::
199
199
200
- ```java
201
- // Initializes a duty cycle encoder on DIO pins 0
202
- DutyCycleEncoder encoder = new DutyCycleEncoder(0);
203
- ` ``
200
+ .. remoteliteralinclude :: https://raw.githubusercontent.com/wpilibsuite/allwpilib/0695a4db8912a65f175c814c30075cc3e87b313f/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/snippets/dutycycleencoder/Robot.java
201
+ :language: java
202
+ :lines: 15-16
204
203
205
- ```c++
206
- // Initializes a duty cycle encoder on DIO pins 0
207
- frc::DutyCycleEncoder encoder{0};
208
- ` ``
204
+ .. remoteliteralinclude :: https://raw.githubusercontent.com/wpilibsuite/allwpilib/0695a4db8912a65f175c814c30075cc3e87b313f/wpilibcExamples/src/main/cpp/snippets/DutyCycleEncoder/cpp/Robot.cpp
205
+ :language: c++
206
+ :lines: 27-28
209
207
210
208
### Configuring Duty Cycle Encoder Range and Zero
211
209
@@ -217,19 +215,13 @@ The zero position is useful for ensuring that the measured rotation corresponds
217
215
218
216
.. tab-set-code ::
219
217
220
- ```java
221
- // Initializes a duty cycle encoder on DIO pins 0 to return a value of 4 for
222
- // a full rotation, with the encoder reporting 0 half way through rotation (2
223
- // out of 4)
224
- DutyCycleEncoder encoder = new DutyCycleEncoder(0, 4.0, 2.0);
225
- ` ``
218
+ .. remoteliteralinclude :: https://raw.githubusercontent.com/wpilibsuite/allwpilib/0695a4db8912a65f175c814c30075cc3e87b313f/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/snippets/dutycycleencoder/Robot.java
219
+ :language: java
220
+ :lines: 18-21
226
221
227
- ```c++
228
- // Initializes a duty cycle encoder on DIO pins 0 to return a value of 4 for
229
- // a full rotation, with the encoder reporting 0 half way through rotation (2
230
- // out of 4)
231
- frc::DutyCycleEncoder encoder{0, 4.0, 2.0};
232
- ` ``
222
+ .. remoteliteralinclude :: https://raw.githubusercontent.com/wpilibsuite/allwpilib/0695a4db8912a65f175c814c30075cc3e87b313f/wpilibcExamples/src/main/cpp/snippets/DutyCycleEncoder/cpp/Robot.cpp
223
+ :language: c++
224
+ :lines: 30-33
233
225
234
226
### Reading Rotation from Duty Cycle Encoders
235
227
@@ -239,31 +231,27 @@ Users can obtain the rotation measured by the encoder with the :code:`get()` met
239
231
240
232
.. tab-set-code ::
241
233
242
- ```java
243
- // Gets the rotation
244
- encoder.get();
245
- ` ``
234
+ .. remoteliteralinclude :: https://raw.githubusercontent.com/wpilibsuite/allwpilib/0695a4db8912a65f175c814c30075cc3e87b313f/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/snippets/dutycycleencoder/Robot.java
235
+ :language: java
236
+ :lines: 28-29
246
237
247
- ```c++
248
- // Gets the rotation
249
- encoder.Get();
250
- ` ``
238
+ .. remoteliteralinclude :: https://raw.githubusercontent.com/wpilibsuite/allwpilib/0695a4db8912a65f175c814c30075cc3e87b313f/wpilibcExamples/src/main/cpp/snippets/DutyCycleEncoder/cpp/Robot.cpp
239
+ :language: c++
240
+ :lines: 19-20
251
241
252
242
### Detecting a Duty Cycle Encoder is Connected
253
243
254
244
As duty cycle encoders output a continuous set of pulses, it is possible to detect that the encoder has been unplugged.
255
245
256
246
.. tab-set-code ::
257
247
258
- ```java
259
- // Gets if the encoder is connected
260
- encoder.isConnected();
261
- ` ``
248
+ .. remoteliteralinclude :: https://raw.githubusercontent.com/wpilibsuite/allwpilib/0695a4db8912a65f175c814c30075cc3e87b313f/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/snippets/dutycycleencoder/Robot.java
249
+ :language: java
250
+ :lines: 31-32
262
251
263
- ```c++
264
- // Gets if the encoder is connected
265
- encoder.IsConnected();
266
- ` ``
252
+ .. remoteliteralinclude :: https://raw.githubusercontent.com/wpilibsuite/allwpilib/0695a4db8912a65f175c814c30075cc3e87b313f/wpilibcExamples/src/main/cpp/snippets/DutyCycleEncoder/cpp/Robot.cpp
253
+ :language: c++
254
+ :lines: 22-23
267
255
268
256
## Analog Encoders - The :code: `AnalogEncoder ` Class
269
257
0 commit comments