View Full Version : Potentiometer arm control
Hello again. I've finally got pots mounted on my arm but I need a little help adapting them to my code. The arm has two pivot points, with a potentiometer mounted at each. The goal of my program is to make the motors move to keep the arm level until it's above the overpass at which point I'll press a button and have the ball get "flipped" over. I'm sort of stuck, and if someone could give me a hint on how to achieve this then that would be great.
Here's a picture of what's happening:
You understand how to make a joint seek to a certain position, yes? The next step would be to find a list of pairs of joint values between (350,900) and (600,350), maybe 20 or 30 clicks apart, all of which keep the ball level. Then instead of going directly to the target, you instead target each intermediate point until you reach your goal. I'm having a little bit of trouble putting this into words... does it make sense?
Yes, I understand what you're saying, but is there a way to put these numbers into a function to tell me what the wrist position should be at any given arm position? I would rather not program 30 different positions if I didn't have to...
Remember Algebra I? Use that to make an equation that will work. It's just like x and y components. Hopefully that helps. (Find the slope using (y2-y1)/(x2-x1), then use y1 = m(x1) + b) That should get you setup. At least, I think that should work.
EDIT: Since I really love math, I had to figure it out myself to be content :D.
Wrist Position = (-11/5)Arm Position + 1670
I'm pretty confident that a linear approximation should do nicely... in terms of real angles (not pot values), you're trying to make it so that theta1+theta2 is always constant. How does this look?
int wristPos(int elbow)
{
return elbow*(350-900)/(600-350)+1670;
}
Calculate the slope of the line, multiply it by x, add the intercept, and that gives you y.
And now y is the number I'm seeking, correct?
And now y is the number I'm seeking, correct?
Pretty much
wrist_pos = (-11/5)*arm_pos + 1670;
I think that should work in your code without any problems.
Pretty much
wrist_pos = (-11/5)*arm_pos + 1670;
I think that should work in your code without any problems.
Not quite... (-11/5) will always evaluate to -2. Try this instead:
wrist_pos = -11*arm_pos/5 + 1670;
Not quite... (-11/5) will always evaluate to -2. Try this instead:
wrist_pos = -11*arm_pos/5 + 1670;
It will not try to use floating point or just use that fraction and multiply it? I thought that would work.
It will not try to use floating point or just use that fraction and multiply it? I thought that would work.
-11 and 5 are both integers, so it will do integer division. It might work if you explicitly made one of them a float (i.e. -11.0), but floating point is a mess on these controllers, so my integer solution is a pretty reasonable approach.
All right, I'll also keep that in mind in the future.
It will not try to use floating point or just use that fraction and multiply it? I thought that would work.
As already mentioned, integers do integer method. In order to maintain precision with integer math, you want to do division with the largest numbers possible. Division will always loose precision.
What was shown will work, but you might even get a little better precision by doing...
wrist_pos = (-11*arm_pos + 1670*5) / 5;
This maximizes the numerator before dividing by the denominator.
What was shown will work, but you might even get a little better precision by doing...
wrist_pos = (-11*arm_pos + 1670*5) / 5;
This maximizes the numerator before dividing by the denominator.
Can you explain how that would work? I'm reasonably confident that you would get exactly the same result for any given value of arm_pos (discounting any overflow issues).
Ziaholic
19-03-2008, 14:29
Can you explain how that would work? I'm reasonably confident that you would get exactly the same result for any given value of arm_pos (discounting any overflow issues).
They're just trying to maximize the value in the numerator, prior to doing the division, which will truncate the decimals back to an integer. The larger the numerator, the less of a truncation error.
Using ArmPosition = 501, here's what you'd get with all 3 methods:
First Method:
wrist_pos = -11/5*arm_pos + 1670 = (-2)*501+1670 = 668
2nd method:
wrist_pos = -11*arm_pos/5 + 1670 = (-5511)/5 + 1670 = -1102+1670=568
3rd method:
wrist_pos = (-11*arm_pos + 1670*5 )/ 5 = 2850/5 = 567.8 = 567
A little off subject but could anyone recommend a model of Pot to use for this type of arm control. We had an arm last year and we used pure manual control , it was very jumpy to say the least. Trying to figure what type of pot and how to mount it on the arm to pick up position. Pre planning for next year I guess. Pictures of a mounting would be nice as well. Thanks.
My recommendation is to NOT BUY RADIOSHACK POTS!!!! They are very cheap and have a lot of dead band. We've been using 10-turn pots for the past 2 years, and they seem to work great. You can buy them from many websites, and possibly from a local store.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.