|
Re: Equation for converting potentiometer voltage into angle?
So you have a potentiometer that goes from 0 to 5 volts, right? In your code, it will read back to you that voltage, right?
A potentiometer is nothing else but a voltage divider when setup the way you do. You turn it all the way in one direction, and it shows 0V, and you start turning it the other direction and it will (hopefully) linearly go to 5V. That is, if you have a linear potentiometer.
There are to basic kinds, linear and logarithmic. Logarithmic potentiometers are usually used for audio applications since hearing is exponential in the way it is perceived.
Therefore, if you have a linear pot, it should increase linearly (in a straight line) from 0 to 5 volts.
If you're using LabVIEW, the value is returned to you as a voltage. In C++ or Java, I'm not sure... I've never used those for the new FIRST system. I'm pretty sure it's returned back as a floating point voltage from 0 to 5 volts though.
Therefore, for a 170˚ rotation potentiometer, all you need to do is figure out your scaling factor (or slope). There should be no offset (y-intercept) unless you need it.
So... at 5V, say it's at 170˚. At 0V, say it's at 0˚. Or...
(x, y): (0, 0), (5, 170)
Hopefully you know how to find slope... if not:
m = (y2 - y1) / (x2 - x1), or (170 - 0) / (5 - 0)
Simplified, it's 170 / 5, or even simpler, 34.
So finally, to get an angle, simply multiply your voltage by 34.
angle = voltage * 34
0˚ = 0V * 34
170˚ = 5V * 34
Beware of cheap potentiometers. They have a lot of dead-band near either end. For a 170˚ pot, only expect about 150˚ of it to be useful. The extremes will just stick at 0 and 5V.
Also, consider yourself lucky that the WPI lib does all the math to get you a clean voltage from 0 to 5 volts. Real world use of voltage is a lot harder to use properly.
__________________
Garnet Squadron
FRC 4901
Controls Mentor
@rnazaretian
Previous mentor and student from Team Fusion, FRC 364
Last edited by RyanN : 05-02-2013 at 11:25.
|