How to find Theta 1 and theta 2 inverse of the two line connecting

451 Views Asked by At

I'm doing the two axis arm robotics on the canvas which shown in the picture as red to blue circle is theta 1 and than blue to yellow is theta 2 here i need to find joint pair of them which is inverse as green and cyan circle is movable so i set according to inverse theta but seems not able to find inverse theta of them correctly here angle are theta1 = 80 theta2 = 50

and my math is bad so can't figure out how can i find their inverse i found the angle using the axis of lines but it seems to be wrong i guess these angle calculated using this function

function angle(cx, cy, ex, ey) {
    var dy = ey - cy;
    var dx = ex - cx;
    var theta = Math.atan2(dy, dx); // range (-PI, PI]
    theta *= 180 / Math.PI; // rads to degs, range (-180, 180]
    //if (theta < 0) theta = 360 + theta; // range [0, 360)
    return -theta;
  }

A1 : 80 & A2 : 50
A1' : 47.45904399010462 & A2' : 82.29636680333454

IMG

i.e. I made cyan circle move a bit on purpose to make yellow visible

red is base
blue,green is shoulder
yellow,cyan is tooltip
1

There are 1 best solutions below

0
On BEST ANSWER

Let's consider the following simple robot, with all four arms the same length $L$, angle $\theta$ between $x$ axis and blue arm $O A$, angle $\phi$ between the blue arm $O A$ and the red arm $O B$, with $O$ at origin, and the robot tip at $C = (x, y)$: Simple robot

Note the right triangles end-to-end. The angle at points $O$ and $C$ is $\phi/2$, and both hypotenuses are $L$. Therefore, $$\left\lVert O C \right\rVert = \sqrt{x^2 + y^2} = 2 L \cos\left(\frac{\phi}{2}\right)$$ Solving for $\phi$ yields $$\phi = 2 \operatorname{acos}\left(\frac{\sqrt{x^2 + y^2}}{2 L}\right) \tag{1}\label{1}$$
We can also see that the angle between the $x$ axis and $O C$ is $\theta + \phi/2$: $$\operatorname{atan2}(y, x) = \theta + \frac{\phi}{2}$$ solving for $\theta$ yields $$\theta = \operatorname{atan2}(y, x) - \frac{\phi}{2} \tag{2}\label{2}$$


In Python, you could use

from math import acos, atan2, sqrt, pi

two_pi = pi+pi

def robot_angles(x, y, L):
    half_phi = acos(sqrt(x*x + y*y) / (L + L))  # 0 <= half_phi <= 0.5pi
    theta = atan2(y, x) - half_phi              # -1.5pi < theta <= pi
    if theta <= -pi:
        theta += two_pi
    return (theta, half_phi+half_phi)           # -pi < theta <= pi

which returns the tuple $(\theta, \phi)$ in radians.

The inverse is e.g.

from math import sin, cos

def robot_tip(theta, phi, L):
    return ( L*cos(theta) + L*cos(theta + phi),
             L*sin(theta) + L*sin(theta + phi) )

which returns the tuple $(x, y)$.