Calculating angles neccessary to reach a position on a 2D plane for two robot arms in a row

3k Views Asked by At

I ran into a problem I am unable to solve while constructing a simplish robot with two arms connected in a row. It is simple to find what point the arms will reach given the angles.

Lengths of the arms $a, b$ are constant. Angles $\alpha, \beta$ are variables.

$$\begin{align} x &= a\cos(\alpha ) + b\cos(\alpha + \beta)\\ y &= a\sin(\alpha ) + b\sin(\alpha + \beta) \end{align}$$

enter image description here

I would like to calculate the opposite of this: $\alpha$ and $\beta$ given $x$ and $y$.

I believe this can have 0-2 solutions, but that is about as far as I got. Any help would be awesome, a complete solution even better. This is not homework, just a project of mine.

2

There are 2 best solutions below

5
On BEST ANSWER

Here are a few pointers.

  • Your equations for $x$ and $y$ are not quite correct, given your diagram.

enter image description here

In my diagram, you can see that the direction angle for vector $\overrightarrow B$ is not $\alpha+\beta$ but rather $\alpha+\beta-180°$. This changes the sign of your second term in the formulas, giving

$$x=a\cos(\alpha)-b\cos(\alpha+\beta)$$ $$y=a\sin(\alpha)-b\sin(\alpha+\beta)$$

enter image description here

  • In my second diagram, $c$ is the distance from the origin to the desired position. We than have a triangle with sides $a,b,c$, though the notation does not match the standard one. By the law of cosines we have

$$c^2=a^2+b^2-2ab\cos\beta$$

so

$$\beta=\cos^{-1}\left(\frac{a^2+b^2-c^2}{2ab}\right)$$

  • We see that $\alpha=\gamma+\delta$, so we want to find $\gamma$ and $\delta$.

  • We can find $\gamma$ with

$$\gamma=\operatorname{atan2}(x,y)$$

where atan2 is the arctangent function with two arguments. If you don't like atan2, you can use

$$\gamma=\tan^{-1}\left(\frac yx\right)$$

though that does not quite work correctly for $x\le 0$. The linked article for atan2 explains how to calculate atan2 if it is not in your toolkit.

  • We can find $\delta$ from another use of the law of cosines,

$$\delta=\cos^{-1}\left(\frac{a^2+c^2-b^2}{2ac}\right)$$

  • You can tell if there is no solution if you get a "domain error" when finding the arccosines: i.e. you attempt to find the arccosine of a value outside the interval $[-1,1]$. This will happen when $c$ is outside the interval $[|a-b|,a+b]$.

  • You can tell is there is one solution if $\beta=0°$ or $\beta=180°$.

  • These calculations only give you one of the solutions, if there are two solutions. I'll leave it to you to figure how to correct the orientations to get the other solution.

  • There is a singularity in my calculations when $a=b$ and the object is at the origin. In particular, both atan2 and atan fail at $x=y=0$. You would need to take that into account in a real solution.

  • You do not state the range of possible values for $\alpha$ or $\beta$, though given your diagram you probably want $0°\le\beta<360°$. The range for $\alpha$ could be $[0°,360°)$ or $(-180°,180°]$. In your final solution you will probably need to adjust your answers to stay in the desired ranges.

0
On

The arms $a$ and $b$ are two sides of a triangle. The third side of the triangle is the segment from the origin to the far end of arm $b$ (the yellow dot in your figure).

Let the length of the third side be $r$. Then $$r^2 = x^2 + y^2, \tag 1$$ where $(x,y)$ is the point at the far end of arm $b$.

Working backwards given $x$ and $y$, you can use Equation $(1)$ to find $r$. You then know all three sides of the triangle. Given all three sides of a triangle, the three angles are completely determined. One way to find an angle of the triangle is to use the Law of Cosines, for example,

$$r^2 = a^2 + b^2 - 2ab \cos \beta.$$

Since we know $a$, $b$, and $r$, we can solve for $\beta$.

In your figure, the angle $\alpha$ is the sum of two angles: $\theta$, the angle between side $r$ and the $x$-axis, and $\gamma$, the angle between sides $a$ and $r$. Another possible configuration of the arms makes $\alpha = \theta - \gamma$. The angle $\theta$ is found by solving

$$ y = x \tan \theta.$$

The angle $\gamma$ can be found either by applying the Law of Cosines again, or, since you now all three sides and an angle now, the Law of Sines.