Skip to content

Commit 2f300a6

Browse files
authored
Update Encoder article to use DutyCycleEncoder snippets (#3024)
1 parent e3fba50 commit 2f300a6

File tree

1 file changed

+24
-36
lines changed

1 file changed

+24
-36
lines changed

source/docs/software/hardware-apis/sensors/encoders-software.rst

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,13 @@ A duty cycle encoder can be instantiated as follows:
197197

198198
.. tab-set-code::
199199

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
204203

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
209207

210208
### Configuring Duty Cycle Encoder Range and Zero
211209

@@ -217,19 +215,13 @@ The zero position is useful for ensuring that the measured rotation corresponds
217215

218216
.. tab-set-code::
219217

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
226221

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
233225

234226
### Reading Rotation from Duty Cycle Encoders
235227

@@ -239,31 +231,27 @@ Users can obtain the rotation measured by the encoder with the :code:`get()` met
239231

240232
.. tab-set-code::
241233

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
246237

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
251241

252242
### Detecting a Duty Cycle Encoder is Connected
253243

254244
As duty cycle encoders output a continuous set of pulses, it is possible to detect that the encoder has been unplugged.
255245

256246
.. tab-set-code::
257247

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
262251

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
267255

268256
## Analog Encoders - The :code:`AnalogEncoder` Class
269257

0 commit comments

Comments
 (0)