Programming a Potentiometer

My team wants to program a potentiometer to limit how far a mini-CIM is to spin. I can’t seem to find any WPILib javadocs on them, or any other resources online.

I need to know how to get the reading from the potentiometer, and know how much to limit the mini-CIM.

Any help, including commands or links would be awesome.

Thanks,
Ram

1 Like

A potentiometer is just a voltage divider, so at one end of the dial its output is your input voltage (5V probably), and at the other end your output is 0V. Wire this output into your analog module, and use an AnalogChannel and its getAverageVoltage() method to read the output. You should experiment to see what the voltage should be for the limits.

As Ginto said, you can use an AnalogChannel object to represent your potentiometer but the Java API also has an AnalogPotentiometer class that you can use as well (wpi api link).

When our team uses potentiometers, we tend to correlate the different positions that we are interested in to readings from the potentiometer (e.g. when the arm is in the “up” position, the potentiometer has a reading of x) and then we use a PIDController to get a motor/speed controller to move the mechanism into position. This sounds like what you are talking about but I am not sure.

If you have some more questions, can you give us some specific details on how you are trying to use the potentiometer and what type of potentiometer it is (single-turn-270-degrees or 10-turn or a string potentiometer)? I am assuming that you will be monitoring something other than the output shaft of the mini-cim, like an arm that rotates or an output shaft on a gearbox…but I am sure that more help will come if you can provide a few more details.

Thanks for the responses!

So, what we’e doing is using the mini-CIM to wind a winch, using a ratchet to make sure it only goes one way. We want to be able to wind the winch to a certain amount, to ready our spring-shooter. So we’ll most likely use a PID related code in the end, to have a setpoint that on button push, will wind up to a certain amount (via readings from the pot), then stop.

I’ll fill you in on more precise details when I’m at robotics tomorrow afternoon.

Would the only way to get readings to actually test with the pot, or is there some way to show that, x degrees of turning = y voltage?

You can map the values from the potentiometer without testing them, but I would only feel really good about it after verifying the numbers on the pot itself. You can map the values by taking the range of the pot’s motion (for a 270 degree pot, this would be 270) and dividing it by the max output power (probably 5 Volts).

270/5 gives you 54 degrees per volt. One end of the pot will read 0 volts and a rotation of 54 degrees should give you a reading of 1 volt. This assumes that it is a linear pot (as opposed to a logarithmic pot).

With the AnalogChannel class, you can get the voltage or the scaled analog value (which is in the range 0 to 1023). The AnalogPotentiometer class gives the voltage by default and has a constructor that allows you to scale the values to more meaningful units.

Sorry if this is scattered…I am doing it between bits of teaching :slight_smile:

Thanks a ton! This actually makes sense to me now :stuck_out_tongue:

It’s my first year programming our robot hands on, so I was a bit confused, but this helped clear it up. I’ll be in robotics around 4, so I’ll check which type of pot we have then.

So, ours are 10-turn potentiometers.

Any help on that? Does it work by turn. So x angle = y turns?

Thanks again.

A 10 turn potentiometer means that it can fully rotate 10 times before hitting its hard stops. If you slowly turn the knob on the potentiometer, it should turn smoothly and easily until you rotate it to the hard stop (either direction). If you then rotate it in the other directions, you should be able to get 10 full rotations before hitting the other hard stop. One of the hard stops corresponds to a signal of 5 volts and the other stop is a signal of 0 volts (don’t worry too much about which is which).

10 turns * 360 degrees per turn gives 3600 total degrees of rotation. Divide that by 5 volts and you will get 720 degrees per volt. If you use the AnalogChannel class, the get() method will return a number in the range of 0 to 1023. Dividing 3600 degrees by 1024 values gives you something like 3.6 degrees per value.

When you mount the potentiometer, try to “center” the 10 turns in the center of your range of motion…you don’t want to drive the potentiometer against its hard stops (that will break it). This also means that the shaft/arm/thingamajig that you are monitoring should need to rotate more than 10 times in its normal operating mode.

Good luck! I hope to see how it turns out in Las Vegas!

Thanks!
That makes it much easier for our thingamajig to work. :stuck_out_tongue:
What exactly is the AnalogChannel class?
I clicked that link, and I couldn’t figure out what it was used for.

Thanks

The link from the post above is to the java api (application programming interface). It lists the various ways to construct an object and the methods supported by the class. If you google “java FRC api”, you can find many sites with the full api (here).

The AnalogChannel class in particular is, I believe, a class that allows you to gather values from any generic sensor that provides analog input (e.g. a gyro or a potentiometer).