Quote:
Originally Posted by TenaciousDrones
Hey so I've been trying to get the encoders programmed on the Toughbox Mini (am-0654) but have been running into a problem. Everytime I get a distance from the encoders it goes from 0.3 to 0.0, any suggestions?
Code:
public void takeJoystickInputs(Joystick right) {
SmartDashboard.putData("Left Encoder Distance", leftEncoder);
SmartDashboard.putData("Right Encoder Distance", rightEncoder);
if ((36+((leftEncoder.getDistance()+ -rightEncoder.getDistance())/2)) > 0) {
robotDrive2.arcadeDrive(right.getY(), -right.getX());
} else robotDrive2.drive(0, 0);
//robotDrive2.arcadeDrive(right.getY(), -right.getX());
}
|
Check the wiring of the encoders/PWMs. I know that my team has had similar issues when the PWM cables were plugged in backwards.
Also note that using the Encoder#getDistance() method requires you to have set a distance with Encoder#setDistancePerPulse(double). If you didn't set this value, you will be getting inaccurate readings. Assuming the encoders are 360 pulses/revolution (which the kit E4Ps should be), the number you need is just the distance your robot travels in one encoder revolution divided by 360.