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);
		}
	}
});
