Go to Post Don’t forget the purpose of Chiefdelphi. It is to keep the community connected and to help each other out. Moderators have been working days and nights to keep this forum going years after years. Let’s keep this place professional. - Arefin Bari [more]
Home
Go Back   Chief Delphi > Technical > Electrical
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 05-02-2013, 01:45
cammy:)'s Avatar
cammy:) cammy:) is offline
Cammy
FRC #3008 (Kalani Falcons)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Hawaii
Posts: 11
cammy:) is an unknown quantity at this point
Equation for converting potentiometer voltage into angle?

Hello-- So our team has just figured out how to program the potentiometer to display the voltage on the front panel. Our next goal is to be able to convert the voltage into angle. Does anybody know of an equation where you can convert the voltage into an angle? Thanks!
__________________
☁ ☁
┏┷┷┓ ♪
▌▣﹏▣ ▌♫
  #2   Spotlight this post!  
Unread 05-02-2013, 01:54
Garrett.d.w's Avatar
Garrett.d.w Garrett.d.w is offline
Build Lead
FRC #2733 (The Pigmice)
Team Role: Alumni
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Portland
Posts: 318
Garrett.d.w is a splendid one to beholdGarrett.d.w is a splendid one to beholdGarrett.d.w is a splendid one to beholdGarrett.d.w is a splendid one to beholdGarrett.d.w is a splendid one to beholdGarrett.d.w is a splendid one to beholdGarrett.d.w is a splendid one to behold
Re: Equation for converting potentiometer voltage into angle?

The voltage that the potentiometer will put out is relative to whatever angle it is set at. The way you go about reading the potentiometer's output as an angle is to set it at the desired angle manually, read the potentiometer and save that voltage. To get the robot to set itself to that angle, you just recall the voltage that you measured earlier.

I know that this is super simplified, but its basically what you do, no fancy math involved
__________________
"A mind once stretched by a thought will never regain it's original dimensions."

Optimists think the glass is half full.
Pessimists think the glass is half empty.
Engineers realize it's twice as big as it needs to be.
  #3   Spotlight this post!  
Unread 05-02-2013, 08:01
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Equation for converting potentiometer voltage into angle?

Assuming a linear potentiomenter and straightforward mechanical motion, the formula is just the equation for a line:
y = mx + b
Read the voltage as x.
Multiply it by a scaling constant m.
Add an offset constant b.
The corresponding angle is y.

To determine the constants, read the voltage at two known angles. Put the voltage and angle in for x and y. Now you have two equations with two unknowns, and you can solve for m and b.



Or you can do what Garrett suggests and not worry about angles at all. Just use voltage in your programming. You don't need to say "put the angle at 30 degrees". You can say "move until the voltage is 1.36" instead.
  #4   Spotlight this post!  
Unread 05-02-2013, 08:19
DELurker DELurker is offline
Former Engineering Mentor
AKA: William Lydick
no team (n/a)
 
Join Date: Mar 2011
Rookie Year: 2011
Location: Delaware, US
Posts: 268
DELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant future
Re: Equation for converting potentiometer voltage into angle?

We are looking at doing something like the illustration attached. The fixed resistor is there for the zero resistance case of the pot. Points 1 and 2 are the analog inputs, with 1 being the difference from the high side of the pot to the wiper and 2 being the full drop of the pot. Using these two measurements, you can divide #1 by #2 to get a percentage (assuming a linear pot). If you know the full available angle of the pot, multiply the full angle by the percentage and (voila!) you have your angle from zero.

Of course, if there's an offset, you need to add that to get angle versus gravity or robot direction or whatever...
Attached Thumbnails
Click image for larger version

Name:	HingePot.jpg
Views:	453
Size:	17.9 KB
ID:	13805  
__________________
----------------------------------------------
With 1370 --
2012 Rutgers District Event Champions with 1676/56
2012 Lenape District Event Finalists with 2191/1691

2013 TCNJ District Event QuarterFinalists with 1143/4750, Gracious Professionalism Award
2013 Bridgewater-Raritan District Event Semi-Finalists with 4285/223
2013 MAR Championship Finalists (Backup) with 222/11/1403; Gracious Professionalism Award
  #5   Spotlight this post!  
Unread 05-02-2013, 08:24
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Equation for converting potentiometer voltage into angle?

Quote:
Originally Posted by DELurker View Post
We are looking at doing something like the illustration attached. The fixed resistor is there for the zero resistance case of the pot.
If you were using a simple variable resistor, that diagram might be appropriate. But a properly-wired potentiometer always puts the maximum resistance across the power input, and the wiper provides a voltage proportional to its travel from one end to the other.

Just wire one end of the pot to +5, the other end to 0, and the wiper to the analog signal input. All three of those are conveniently provided on the analog input pins.
  #6   Spotlight this post!  
Unread 05-02-2013, 11:21
RyanN's Avatar
RyanN RyanN is offline
RyanN
AKA: Ryan Nazaretian
FRC #4901 (Garnet Squadron)
Team Role: Mentor
 
Join Date: Jun 2006
Rookie Year: 2005
Location: Columbia, SC
Posts: 1,126
RyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond repute
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.
  #7   Spotlight this post!  
Unread 05-02-2013, 12:44
DELurker DELurker is offline
Former Engineering Mentor
AKA: William Lydick
no team (n/a)
 
Join Date: Mar 2011
Rookie Year: 2011
Location: Delaware, US
Posts: 268
DELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant futureDELurker has a brilliant future
Re: Equation for converting potentiometer voltage into angle?

Quote:
Originally Posted by Alan Anderson View Post
But a properly-wired potentiometer always puts the maximum resistance across the power input, and the wiper provides a voltage proportional to its travel from one end to the other.
This is true and absolutely correct. However, we've had people make mistakes like that before and it's just easier to put in a preventative item like that than have the team swear off pots for another four years ...
__________________
----------------------------------------------
With 1370 --
2012 Rutgers District Event Champions with 1676/56
2012 Lenape District Event Finalists with 2191/1691

2013 TCNJ District Event QuarterFinalists with 1143/4750, Gracious Professionalism Award
2013 Bridgewater-Raritan District Event Semi-Finalists with 4285/223
2013 MAR Championship Finalists (Backup) with 222/11/1403; Gracious Professionalism Award
  #8   Spotlight this post!  
Unread 05-02-2013, 13:42
philso philso is offline
Mentor
FRC #2587
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Houston, Tx
Posts: 938
philso has a reputation beyond reputephilso has a reputation beyond reputephilso has a reputation beyond reputephilso has a reputation beyond reputephilso has a reputation beyond reputephilso has a reputation beyond reputephilso has a reputation beyond reputephilso has a reputation beyond reputephilso has a reputation beyond reputephilso has a reputation beyond reputephilso has a reputation beyond repute
Re: Equation for converting potentiometer voltage into angle?

Quote:
Originally Posted by DELurker View Post
This is true and absolutely correct. However, we've had people make mistakes like that before and it's just easier to put in a preventative item like that than have the team swear off pots for another four years ...
It is not that hard to get the wiring done right. It would be sad if a team really stopped using a common type of sensor because they did not follow some simple instructions and blamed the sensor. Many pieces of industrial electronics products use exactly the same set up to control some function. I have never seen a second resisitor added as a "preventative measure" because it is just not necessary as Alan has stated. Ohm's Law applied correctly to this situation will prove this point.

I would hope that you are doing a thorough check of EACH AND EVERY wire, individually, for ALL of your circuits before turning on the power. Preferably, a second person should also check your work after you have satisfied yourself that you have found and fixed all your errors. An incorrectly wired pot will not damage the CRio but it is quite likely that an incorrectly wired motor controller can become damaged.
  #9   Spotlight this post!  
Unread 05-02-2013, 14:23
MamaSpoldi's Avatar
MamaSpoldi MamaSpoldi is offline
Programming Mentor
AKA: Laura Spoldi
FRC #0230 (Gaelhawks)
Team Role: Engineer
 
Join Date: Jan 2009
Rookie Year: 2007
Location: Shelton, CT
Posts: 305
MamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant future
Re: Equation for converting potentiometer voltage into angle?

Here is the equation we used last year:

positionDeg = (analogPot->GetAverageVoltage() - INHERENT_ZERO) * VOLTAGE_TO_DEGREES;

where INHERENT_ZERO was a value we measured and defined within our code for the position we chose to view as zero degrees;
and VOLTAGE_TO_DEGREES was a value calculated ahead of time to convert the voltage over a 90 deg travel into degrees. (This is simple to do because it is just a linear conversion. Take the difference of the pot voltage at 0 and at 90 and then divide by 90 to get this value.)

Hope that helps.
__________________
  #10   Spotlight this post!  
Unread 05-02-2013, 15:22
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,074
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Equation for converting potentiometer voltage into angle?

Quote:
Originally Posted by MamaSpoldi View Post
positionDeg = (analogPot->GetAverageVoltage() - INHERENT_ZERO) * VOLTAGE_TO_DEGREES;
Let:

y = positionDeg
m = VOLTAGE_TO_DEGREES
x = analogPot->GetAverageVoltage()
b = -VOLTAGE_TO_DEGREES*INHERENT_ZERO


then:

y = mx + b
  #11   Spotlight this post!  
Unread 05-02-2013, 15:50
MamaSpoldi's Avatar
MamaSpoldi MamaSpoldi is offline
Programming Mentor
AKA: Laura Spoldi
FRC #0230 (Gaelhawks)
Team Role: Engineer
 
Join Date: Jan 2009
Rookie Year: 2007
Location: Shelton, CT
Posts: 305
MamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant futureMamaSpoldi has a brilliant future
Re: Equation for converting potentiometer voltage into angle?

EXACTLY!
__________________
  #12   Spotlight this post!  
Unread 05-02-2013, 16:10
apalrd's Avatar
apalrd apalrd is offline
More Torque!
AKA: Andrew Palardy (Most people call me Palardy)
VRC #3333
Team Role: College Student
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Auburn Hills, MI
Posts: 1,347
apalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond repute
Re: Equation for converting potentiometer voltage into angle?

While calculating a very simple linear equation is all nice and good, I prefer to use an interpolation curve with 2 points.

Basically, you cal two pairs of numbers (an analog value and corresponding engineering unit value for each pair) and calculate M and B dynamically. I find it's easier to calibrate.


the code can then does the following (for the 2-point curve):
Code:
dx = max_ana - min_ana;
dy = max_eng - min_eng;
m = dx / dy;ana_raw = get_analog_value();
ana_offset = ana_raw - min_ana;
eng_offset = ana_offset * m;
eng = eng_offset + min_eng;
eng is the result.

Under the same basic logic, you can develop blocks to linearly interpolate a 1d input and 1d output table to generate a piecewise function which is calibrated like a pair of tables (input and output), or two 1d input tables and a 2d output table to end up with a 3d surface whichis calibrated with two axis breakpoints and the values for each cell.

Such interpolation curves and tables seem to be a staple of embedded control algorithms, since they are very easy to implement and calibrate (relative to fully modeling the system), and get 'close enough'. FRC software is usually in the 'close enough' realm anyway, so they are perfect.
__________________
Kettering University - Computer Engineering
Kettering Motorsports
Williams International - Commercial Engines - Controls and Accessories
FRC 33 - The Killer Bees - 2009-2012 Student, 2013-2014 Advisor
VEX IQ 3333 - The Bumble Bees - 2014+ Mentor

"Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function." ~ John Carmack
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:18.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi