Hello,
We’ve recently bought a brand new MA3 absolute encoder and plugged it into our RoboRIO port. However, it always reports ~360 degrees even after spinning the encoder physically. We’re putting this under “programming” since all the electronics are brand new and don’t seem to have any visible problems. Also, in terms of code, we’re just printing out the encoder values. Is there anything we have to do to set up a new MA3 absolute encoder?
Thank you!
Also, please let me know if you want further details.
Exactly which MA3 variant? I think it comes in both PWM and analog output styles. What RoboRIO port is it plugged into? How are all of its pins wired (eg power, ground, signal)? What class are you using to read it?
Exactly which MA3 variant?
Andy Mark: https://www.andymark.com/products/ma3-absolute-encoder-with-cable
What RoboRIO port is it plugged into?
An analog port. Specifically, port 2.
What class are you using to read it?
We are using WPILib’s AnalogInput class.
How are all of its pins wired (eg power, ground, signal)?
I’ll have to talk to the electronics department for this one. Sorry.
Please take a picture! 
To me this sounds like a wiring issue, either 5v is being dumped directly to signal, or it is mistakenly a digital device in an analog input.
The analog input class shouldn’t report a value in the range of 360. Are you doing additional scaling in code? Probably need to see your code as well.
Yeah, we thought so too. We tested it on a different RoboRIO and we replaced the wiring, but we still got the issue. I’ll send a photo later, when I have access to the robot again. Thanks!
Oh, yeah. We scale it in our code. Here you go:
public class AbsoluteAnalogEncoder extends AnalogInput {
private double offset; //Declare offset variable
private boolean reversed; //Declare reversed
public AbsoluteAnalogEncoder(int port, double offset, boolean reversed) {
super(port);
setOffset(offset);
this.reversed = reversed;
}
private void setOffset(double offset) {
this.offset = (offset / 360 * RobotController.getVoltage5V()) % RobotController.getVoltage5V();
if (this.offset < 0)
this.offset += RobotController.getVoltage5V();
}
@Override
public double getVoltage() {
double returnValue = super.getVoltage();
if (this.reversed) returnValue *= -1;
returnValue = (returnValue - this.offset) % RobotController.getVoltage5V();
if (returnValue < 0)
returnValue += RobotController.getVoltage5V();
return returnValue;
}
public double getRotationPercent() {
return (getVoltage() / RobotController.getVoltage5V());
}
public double getRotationDegrees() {
return getRotationPercent() * 360.0;
}
}