I want to implement in python the inverse kinematic algorithm describied in the…
- User
I want to implement in python the inverse kinematic algorithm describied in the following latex paragraph. The python script need as input the robot end-effector pose and rotational matrix and return as output the possibile joint values. Furthermore If I specifify the previous joint values and the joint limits as optional parameters, it return the most close single joint configuration. The end-effector's position and orientation is given by the homogeneous transformation matrix: [\mat{T_e^0(\vet q)}= \begin{bmatrix} \vet n_e^0(\vet q) & \vet s_e^0(\vet q) & \vet a_e^0(\vet q)& \vet p_e^0(\vet q)\ 0 & 0 & 0 & 1 \end{bmatrix}] to simplify the notation, the end-effector position is rewritten as (\vet p_e^0(\vet q)=\vet p_e=(p_x, p_y, p_z)).
Since the robot considered is a 6-dof robot we can split the inverse kinematic problem in two subproblem.
\paragraph{Wrist Position} The wrist position can be found as in \autoref{eq:WristPosition} \begin{equation} \label{eq:WristPosition} \begin{aligned} \vet p_W^0 (q_1,q_2,q_3) &=(p_{W_x},p_{W_y},p_{W_z})= \vet p_e - d_6 \vet a_e \ &= \begin{bmatrix} \cos(q_1) (a_1 + a_2 \sin(q_2) + a_3 \sin(q_2 + q_3) + d_4 \cos(q_2 + q_3))\ \sin(q_1) (a_1 + a_2 \sin(q_2) + a_3 \sin(q_2 + q_3) + d_4 \cos(q_2 + q_3))\ a_2 \cos(q_2) + a_3 \cos(q_2 + q_3) + d_1 - d_4 \sin(q_2 + q_3) \end{bmatrix} \end{aligned} \end{equation}.
\paragraph{First Joint Angle (( q_1))} The solution for the first joint is only a matter of solving a simple trigonometrical problem. %To ensure that all possible solutions are found we need to take into account that arctangent is only defined for angles between [-90\textdegree, 90\textdegree]. To counteract this issue, two different equations (shown in \autoref{eq:IK_first_joint}) are presented for joint-angle one which differs by one period (180\textdegree). The first joint angle (q_1) is determined by: \begin{equation} \label{eq:IK_first_joint} q_1^{(1)} = \text{atan2}(p_{W_y}, p_{W_x}) \end{equation} Since (q_1) has two possible solutions, the other solution is: [ q_1^{(2)} = q_1 + \pi ]
\paragraph{Second Joint Angle ((q_2))}
For each (q_1), the second joint angle (q_2) is computed using geometric analysis of the robot's arm. The parameters (L_2) and (L_3) are defined as: [ L_2 = a_2, \quad L_3 = \sqrt{d_4^2 + a_3^2} ] The vector (\vet p_W^1) (the wrist position expressed in the reference frame 1) is given by: [ \vet p_W^1 =(\mat A_1^0)^{-1}\mat T_3^0 = (\mat A_1^0)^{-1} \begin{bmatrix} \vet p_W \ 1 \end{bmatrix}
\begin{bmatrix} -a_1+p_{W_x} \cos (q_1)+p_{W_y} \sin (q_1)\ d_1-p_{W_z}\p_{W_y} \cos (q_1)-p_{W_x} \sin (q_1)\ 1 \end{bmatrix} ] And (r) is the distance: [ r = \sqrt{(p_{W_x}^1)^2 +(p_{W_y}^1)^2} ] Then, we calculate (\beta) and (\gamma) as: [ \beta = \text{atan2}(-p_{W_y}^1, p_{W_x}^1) ] [ \gamma = \cos^{-1} \left( \frac{L_2^2 + r^2 - L_3^2}{2 L_2 r} \right) ] The two possible solutions for (q_2) are: [ q_2^{(1)} = \frac{\pi}{2} - \beta - \gamma \quad \text{(elbow up)} ] [ q_2^{(2)} = \frac{\pi}{2} - \beta + \gamma \quad \text{(elbow down)} ]
- Assistant