@@ -32,6 +32,7 @@ public class MockedEncoder implements AbsoluteEncoder, AnalogInput, AutoCloseabl
3232 protected final SimBoolean init ;
3333 protected final int countsPerRev ;
3434 protected final boolean absolute ;
35+ protected final boolean useRps ;
3536 protected double positionConversionFactor = 1.0 ;
3637 protected double velocityConversionFactor = 1.0 ;
3738 protected double positionOffset = 0.0 ;
@@ -41,11 +42,28 @@ public class MockedEncoder implements AbsoluteEncoder, AnalogInput, AutoCloseabl
4142 * @param device The device to retrieve position and velocity data from
4243 * @param countsPerRev The value that this.getCountsPerRevolution() should return
4344 * @param analog Whether the encoder is an analog sensor
44- * @param absolute Whether the encoder is an absolute encoder.
45- * This flag caps the position to one rotation via. {@link MathUtil#inputModulus(double, double, double)},
46- * disables {@link #setPosition(double)}, and enables {@link #setZeroOffset(double)}.
45+ * @param absolute Whether the encoder is an absolute encoder. This flag caps the position to
46+ * one rotation via. {@link MathUtil#inputModulus(double, double, double)}, disables
47+ * {@link #setPosition(double)}, and enables {@link #setZeroOffset(double)}.
48+ *
49+ * {@link #getVelocity()} will return a value in rpm.
4750 */
48- public MockedEncoder (SimDevice device , int countsPerRev , boolean analog , boolean absolute ) {
51+ public MockedEncoder (SimDevice device , int countsPerRev , boolean analog ,
52+ boolean absolute ) {
53+ this (device , countsPerRev , analog , absolute , false );
54+ }
55+
56+ /**
57+ * @param device The device to retrieve position and velocity data from
58+ * @param countsPerRev The value that this.getCountsPerRevolution() should return
59+ * @param analog Whether the encoder is an analog sensor
60+ * @param absolute Whether the encoder is an absolute encoder. This flag caps the position to
61+ * one rotation via. {@link MathUtil#inputModulus(double, double, double)}, disables
62+ * {@link #setPosition(double)}, and enables {@link #setZeroOffset(double)}.
63+ * @param useRps Whether getVelocity() should return rps instead of rpm.
64+ */
65+ public MockedEncoder (SimDevice device , int countsPerRev , boolean analog ,
66+ boolean absolute , boolean useRps ) {
4967 this .device = device ;
5068 position = device .createDouble ("position" , Direction .kInput , 0 ); // Rotations
5169 velocity = device .createDouble ("velocity" , Direction .kInput , 0 ); // Rotations per *second*
@@ -56,6 +74,7 @@ public MockedEncoder(SimDevice device, int countsPerRev, boolean analog, boolean
5674 }
5775 this .countsPerRev = countsPerRev ;
5876 this .absolute = absolute ;
77+ this .useRps = useRps ;
5978 init = device .createBoolean ("init" , Direction .kOutput , true );
6079 }
6180
@@ -105,7 +124,8 @@ public double getPosition() {
105124
106125 @ Override
107126 public double getVelocity () {
108- return velocity .get () * 60 * (inverted ? -1 : 1 ) * velocityConversionFactor ;
127+ return velocity .get () * (useRps ? 1 : 60 ) * (inverted ? -1 : 1 )
128+ * velocityConversionFactor ;
109129 }
110130
111131 @ Override
0 commit comments