Questions about the AnalogPotentiometer class

Hello all,

We have been having trouble with WPILIB’s AnalogPotentiometer class recently. Some facts about our potentiometer.

1.) It’s an analog potentiometer.
2.) It’s made by rev robotics.
3.) It’s complete range of motion is 270 degrees.
4.) We use it to measure the angle of an arm whose resting position is at an angle of 23.4 degrees from vertical (straight down).
5.) We want to zero the potentiometer (23.4 degrees → 0 degrees).
6.) We want the full range of motion for our arm to be from 0 degrees to 93 degrees.

However, we’ve noticed some issues using the analog potentiometer class like this:
armPotentiometer = new AnalogPotentiometer(RobotMap.ELEVATOR_POTENTIOMETER, 93, -51);

For some reason, the entire range of motion is not from 0-93, but from 0-31. Therefore, we’ve been having to multiply by 3. However, we think something is up. Does it have to do with the fact it is a 3.3 v potentiometer, not 5 volts. We’re not sure.

I totally understand if I’m missing important details. Please let me know if you need anymore details.

Thank you

The parameters to AnalogPotentiometer are full range and offset. And the full range is for 0-5V. So you’ll need to scale the full range value of 270 by 3.3/5. AnalogPotentiometer (WPILib API 2023.4.2)

Hi,

I’m a teammate of @somerandomuser. Thank you for your help! Just to clarify, the full range value is multiplied by voltage-reading/5V right? To scale to 3.3 V shouldn’t we multiply by 5/3.3 to cancel the denominators? Am I misunderstanding?

Once again, thanks!

Here’s the code that does the scaling:

So yes, you’re correct re: the fullScale value (it should be 270 * 5.0 / 3.3). Note the offset is just added in at the end so should be in degrees, and not scaled.

Thanks for your help! Everything here makes sense. However, one question: shouldn’t our full range be 93, not 270? In other words, does the full range parameter of the potentiometer class represent the entire range of our potentiometer or our desired range.

It represents the entire range.

Got it. We’ll try it out later today. Thank you for all your help :slightly_smiling_face:

Hello,

So, we tried to multiply our full range by 5.0/3.3 but we ran into issues. Here is our code. We were eventually able to get it to work, but we had to change the full range from 270 to 93 and we had to multiply by 2.305. We guessed and checked to find 2.305. This is probably not the best way to use this class.

public class ElevatorPotentiometer {
    private static ElevatorPotentiometer instance; 
    private AnalogPotentiometer elevatorPotentiometer; 

    public ElevatorPotentiometer() { //always make sure this is on the right scale: 0-93 degrees.
        //elevatorPotentiometer = new AnalogPotentiometer(RobotMap.ELEVATOR_POTENTIOMETER, 93*(5/3.3), -126); //90,-72; 93,-74
        elevatorPotentiometer = new AnalogPotentiometer(RobotMap.ELEVATOR_POTENTIOMETER, 93*(5/3.3), -124); //0-35 units
    }

    public static ElevatorPotentiometer getInstance() {
        if (instance == null) {
            instance = new ElevatorPotentiometer();
        }
        return instance; 
    }

    public double getArmAngle() {
        //return (int) (-(2.4)*elevatorPotentiometer.get()); //We cast to an int because the potentiometer does not reach 0
        return (int) (-2.305*elevatorPotentiometer.get()); 
    }
}

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.