Encoder Issues

Hey, so we are trying to hook up our encoders, and we have them working while they are hooked up to the Roborio, but we don’t get any values while we are hooked up to our CAN Talon. We’ve checked several diagrams and our wiring, and those don’t appear to be the issue. Any help you could supply would be greatly appreciated. Thanks!

Whenever you have a problem it is ALWAYS helpful to post code that goes with it.

Here is our execute method in our sensor-reading command:

protected void execute() {
    	SmartDashboard.putNumber("Encoder Raw", Robot.sensors.getRaw());
    	SmartDashboard.putNumber("Encoder Rate", Robot.sensors.getRate());
    	SmartDashboard.putNumber("Encoder Distance" ,Robot.sensors.getDistance());
    }

Here are the definitions for those methods in our sensor subclass:

public double getRate() {
    	return canEncoder.getRate();
    }

    public double getDistance() {
    	return canEncoder.getDistance();
    }
    
    public double getRaw() {
    	return canEncoder.getRaw();
    }


And here is where we define our Talon and Encoder:

// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
        motorsCANTalon = new CANTalon(0);
        LiveWindow.addActuator("Motors", "CAN Talon", motorsCANTalon);
        
        sensorscanEncoder = new Encoder(0, 1, false, EncodingType.k4X);
        LiveWindow.addSensor("Sensors", "canEncoder", sensorscanEncoder);
        sensorscanEncoder.setDistancePerPulse(1.0);
        sensorscanEncoder.setPIDSourceType(PIDSourceType.kRate);

    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
        motorsCANTalon.reverseSensor(true);
        motorsCANTalon.setFeedbackDevice(FeedbackDevice.QuadEncoder);
        motorsCANTalon.configEncoderCodesPerRev(360);
        motorsCANTalon.setPosition(0);
        motorsCANTalon.setForwardSoftLimit(15.0);
        motorsCANTalon.setReverseSoftLimit(-15);

Is there something we are doing wrong? Anything we need to initialize so that we’ll get values off the breakout?

Hey feoniks4505,

The Encoder class is for encoders wired to the roboRIO…

sensorscanEncoder = new Encoder(0, 1, false, EncodingType.k4X);

I think motorsCANTalon.getPosition() and motorsCANTalon.getSpeed() are what you want. Remember the sensor data comes from the Talon, to the RIO, which is where your code runs.

Checkout section 5.3 in the Talon SRX Software reference manual to see all the getters.

And when you are ready to use the internal closed-loop features of the Talon, check out the examples in section 12.

Also for the future, if anyone has a doubt of wiring-issue-versus-software-issue, use the self-test feature (Section 2.4) to see what the Talon sees for sensor data. Then you can rule out wiring versus software. Self-test works even if there is no-code.