@@ -41,13 +41,15 @@ private void Relative_Encoder_Example() {
4141 // and we want the position to return in meters
4242 final double input = 1 ;
4343 final double output = 6.75 ;
44- final double positionConversionFactor = (2 * Math .PI * Units .inchesToMeters (2 ) * input ) / output ;
44+ // (2 * PI * R) * (input / output)
45+ final double positionConversionFactor = (2 * Math .PI * Units .inchesToMeters (2 )) * (input / output );
4546 encoder .setPositionConversionFactor (positionConversionFactor );
4647
4748 double positionInMeters = encoder .getPosition ();
4849
4950 // Velocity Conversion Factor is the same as position but divided by 60 seconds to get meters/second
50- encoder .setVelocityConversionFactor (positionConversionFactor / 60.0 );
51+ final double velocityConversionFactor = positionConversionFactor / 60.0 ;
52+ encoder .setVelocityConversionFactor (velocityConversionFactor );
5153
5254 double speedInMetersPerSecond = encoder .getVelocity ();
5355 }
@@ -63,9 +65,13 @@ private void Absolute_Encoder_Examples() {
6365 final int canID = 20 ;
6466 CANcoder absoluteEncoder = new CANcoder (canID );
6567
66- // Conversion Factor is set in Phoenix Tuner X (same concept as a relative encoder)
68+ // Returns current rotation either from [-0.5, 0.5] or [0, 1]
69+ // depending on the selected setting
6770 // https://v6.docs.ctr-electronics.com/en/stable/docs/tuner/index.html
68- double position = absoluteEncoder .getPosition ().getValueAsDouble ();
71+ double rotations = absoluteEncoder .getPosition ().getValueAsDouble ();
72+
73+ // Get the position as an angle in degreees
74+ double angle = 360 * rotations ;
6975 }
7076
7177}
0 commit comments