We use this encoder for our swerve modules to read rotation and they work just fine, but this year we’ve been trying to use one on our elevator and have ran into issues.
First and foremost the swerve encoders take up all four of the roboRIO’s analogIN ports so we have to use one of the analogIN ports on the navX-MXP for the elevator. The problem with these ports is that roboRIO analog ports read values from 0 - 4096 whereas these read from really weird values, the lowest we could read being 143 and the most being 858.
Another difference from the swerve encoders is that the shaft must rotate 6 or 7 times for the whole span of the elevator, so we had to make a counter to tell when the encoder makes a full rotation.
The problem we’re facing is that the encoder value in relation to the physical position of the elevator drifts as we drive it, our rotation counter seems to work at first but if you go up and down a few times the value it reads at the bottom shifts upwards from what it initially read, sometimes even jumping by up to a full rotation.
We’ve thoroughly inspected the physical mechanisms and the chain isn’t slipping nor the coupling from the shaft to the encoder, so we don’t know if it’s a problem with the rotation counter or the navx ports being different, but we’re fairly sure it’s programmatical.
Here’s the code for our counter
public static double getAngle(){
startAngle = getRawAngle();
f((startAngle > 155 && startAngle < 255) && (lastAngle > >750 && lastAngle < 850)){
revolutions++;
}
else if((startAngle > 750 && startAngle < 850) && (lastAngle >> 155 && lastAngle < 255)){
revolutions–;
}
angle = startAngle + (revolutions*695);
lastAngle = startAngle;
return angle;
}
This is ran constantly 100 times per second while the robot is enabled, the value this returns is what is drifting, and “getRawAngle()” is a simple method getting the value from the encoder.