Help with Programming a CIMCODER

I recently got a package of CIMCoders for our Robot’s Drivetrain. The problem is that I’ve never actually programmed encoders before; Especially, CIMCoders. So, I used the example code provided from AndyMark, but I could never get any values from the CIMCoder. I knew the CIMCoder worked because both Channel A and B flashed when I moved the motor. Please help I’m very confused! (Code I used is listed below)

package frc.robot;

import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

/**

  • The VM is configured to automatically run this class, and to call the functions corresponding to
  • each mode, as described in the TimedRobot documentation. If you change the name of this class or
  • the package after creating this project, you must also update the build.gradle file in the
  • project.
    /
    public class Robot extends TimedRobot {
    /
    *
    • This function is run when the robot is first started up and should be used for any
    • initialization code.
      */

Encoder encoder;

private static final double cpr = 64;

private static final double whd = 6;

@Override
public void robotInit() {
encoder = new Encoder(0,1);
encoder.setDistancePerPulse(Math.PIwhd/cpr); //distance per pulse is pi (wheel diameter / counts per revolution)
}

@Override
public void robotPeriodic() {
double dist = encoder.getDistance();
SmartDashboard.putNumber(“Encoder”, dist);
}

1 Like

I recommend printing the value you are sending to setDistancePerPulse. I doubt it’s what you’re expecting.

I’ve also tried that; Doesn’t work either.

UPDATE: I forgot to mention that I’ve plugged my CIMCoder into my TalonSRX. Should I try connecting it to the dio?

If the encoder is on the SRX then you need the configSelectedFeedbackSensor​ method from CTRE to set it up. Like this

TalonSRX motor = new TalonSRX(0);
//Config the CIMcoder
motor.configSelectedFeedbackSensor(FeedbackDevice.QuadEncoder, 0, 30);
//Get the position 
motor.getSelectedSensorPosition();

The encoder class from WPIlib won’t work unless the encoder is connected to the dio. The CTRE examples show more of what you can with the encoder.

1 Like

Thanks. I did not have the CIMCOder plugged into the DIO. Thank you for the help!

Thank you! I was able to wire the power and ground along with the two signal wires to the DIO Port.

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