Handling potentiometer blind spot

Any hardware type questions or problems for all other Phidget devices.
Post Reply
SecularSurfer
Phidgetsian
Posts: 9
Joined: Tue Aug 27, 2019 9:11 am
Contact:

Handling potentiometer blind spot

Post by SecularSurfer »

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?

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);
		}
	}
});
- Tom
User avatar
mparadis
Site Admin
Posts: 660
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Handling potentiometer blind spot

Post by mparadis »

Following your program, it looks like it's designed to:

Whenever the potentiometer is moved (VoltageRatioChange event),
If the new value is higher than the previous one, increment the servo by a static amount.
If the new value is lower than the previous one, decrement the servo by a static amount.

The reason it's going backwards for a few steps each rotation isn't because of the blind spot (the small region of the potentiometer between 1.0 V/V and 0.0 V/V where no position change will occur), it's because of the transition from 0.0 V/V and 1.0 V/V that naturally occurs there. When your program sees the transition from 1.0 to 0.0 or vice versa, your program thinks the potentiometer briefly went the wrong way. To get around this, you should check the difference between the old and new values. If the difference is greater than, say, 0.75 V/V, then it's probably a wrap-around event since it would ordinarily be very difficult to spin the potentiometer fast enough to create that big of a difference in a single change event. When you detect one of these wrap-arounds, you can just increment the servo in the opposite direction that it would have normally gone.

As a side note, if you want the servo to be more responsive to the potentiometer, you should not use fixed increments and instead increment proportional to the change in voltage ratio using a formula that results in your desired 2-3 full turns per servo range. If you do this, you'll probably need some additional math to handle the wrap-arounds though.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests