Handling potentiometer blind spot
Posted: Sat Dec 28, 2019 2:03 pm
I'm using a 3583_0 potentiometer and a RCC1000_0 servo controller. I want to be able to turn the potentiometer clockwise until the servo reaches its MAX, and turn it counterclockwise until it reaches its MIN. It should take at least 2-3 full turns to go the full distance between MIN and MAX. My code is working except for when it hits the blind spot. The servo twitches back slightly in the opposite direction before resuming the correct direction.
Any thoughts on how to deal with this?
Any thoughts on how to deal with this?
Code: Select all
valve.addVoltageRatioChangeListener(new VoltageRatioInputVoltageRatioChangeListener() {
@Override
public void onVoltageRatioChange(VoltageRatioInputVoltageRatioChangeEvent e) {
lastValue = currentValue;
currentValue = e.getVoltageRatio();
try {
if (currentValue > lastValue) {
targetPosition = servo.getPosition() + SERVO_INCREMENT;
if ((targetPosition) < SERVO_MAX_POSITION) {
servo.setTargetPosition(targetPosition);
}
} else if (currentValue < lastValue) {
targetPosition = servo.getPosition() - SERVO_INCREMENT;
if ((targetPosition) > SERVO_MIN_POSITION) {
servo.setTargetPosition(targetPosition);
}
}
} catch (PhidgetException ex) {
System.out.println("Servo failed " + ex);
Logger.getLogger(Atlantis.class.getName()).log(Level.SEVERE, null, ex);
}
}
});