Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Potentiometer arm control (http://www.chiefdelphi.com/forums/showthread.php?t=64225)

Hazmatt 15-02-2008 23:41

Potentiometer arm control
 
1 Attachment(s)
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:

jgannon 15-02-2008 23:54

Re: Potentiometer arm control
 
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?

Hazmatt 16-02-2008 00:04

Re: Potentiometer arm control
 
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...

RyanN 16-02-2008 00:08

Re: Potentiometer arm control
 
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

jgannon 16-02-2008 00:11

Re: Potentiometer arm control
 
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?
Code:

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.

Hazmatt 16-02-2008 00:27

Re: Potentiometer arm control
 
And now y is the number I'm seeking, correct?

RyanN 16-02-2008 00:30

Re: Potentiometer arm control
 
Quote:

Originally Posted by Hazmatt (Post 699949)
And now y is the number I'm seeking, correct?

Pretty much

Code:

wrist_pos = (-11/5)*arm_pos + 1670;
I think that should work in your code without any problems.

jgannon 16-02-2008 00:39

Re: Potentiometer arm control
 
Quote:

Originally Posted by RyanN (Post 699953)
Pretty much

Code:

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:
Code:

wrist_pos = -11*arm_pos/5 + 1670;

RyanN 16-02-2008 00:40

Re: Potentiometer arm control
 
Quote:

Originally Posted by jgannon (Post 699958)
Not quite... (-11/5) will always evaluate to -2. Try this instead:
Code:

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.

jgannon 16-02-2008 00:43

Re: Potentiometer arm control
 
Quote:

Originally Posted by RyanN (Post 699960)
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.

RyanN 16-02-2008 00:44

Re: Potentiometer arm control
 
All right, I'll also keep that in mind in the future.

duane 16-02-2008 02:00

Re: Potentiometer arm control
 
Quote:

Originally Posted by RyanN (Post 699960)
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.

jgannon 16-02-2008 03:18

Re: Potentiometer arm control
 
Quote:

Originally Posted by duane (Post 699992)
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

Re: Potentiometer arm control
 
Quote:

Originally Posted by jgannon (Post 700011)
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

mikeqfl 01-04-2008 21:09

Re: Potentiometer arm control
 
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.


All times are GMT -5. The time now is 00:55.

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