Use Encoder connected to Talon SRX in WPILib encoder class

Our team has used the CTRE mag encoders with our drive system. We were wondering if there is any way to use those with the WPILib encoder class(for use with trajectory following). Thanks!

I just rewrote the encoder calls as Talon.getSelectedSensorPosition. Still don’t know if it works.

After looking into this for hours I could not find a solution, however, after posting on CD I somehow immediately found this class. It seems to provide similar methods, so I’ll try that!

Both DutyCycleEncoder and the normal Encoder class are for sensors plugged directly into the roboRIO. Neither will work if the sensor is hooked into a Talon. However, on that example, lines 68 and 69 are the 2 lines that call encoder functions. The 2 getDistance calls there can just be replaced with getSelectedSensorPosition on the talon objects. The m_odometry.update function just takes numbers in, so the position values can be from any device, as long as you call the right function on the device.

3 Likes

I’ve done some further reading and I think you are right, @Amicus1, I might just write my own method for the .getRate() method.

We are working through the same problem right now.

Here’s what we did and it seems to be working:

  public DifferentialDriveWheelSpeeds getWheelSpeeds() {
    return new DifferentialDriveWheelSpeeds(
        stepsPerDecisecToMetersPerSec(leftMaster.getSelectedSensorVelocity()),
        stepsPerDecisecToMetersPerSec(rightMaster.getSelectedSensorVelocity()));
  }

  public static double stepsToMeters(int steps) {
    return (WHEEL_CIRCUMFERENCE_METERS / 4096) * steps;
  }

  public static double stepsPerDecisecToMetersPerSec(int stepsPerDecisec) {
    return stepsToMeters(stepsPerDecisec * 10);
  }
1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.