2rp_jacobian

Jacobian and Singularity Analysis of a 2-Link Planar Manipulator using Python

With Sympy (Symbolic Python Module)

This post is a continuation of our previous posts where we had learned how to develop kinematics of a 2-Link Planar Manipulator with Python. We showed how to derive the same forward kinematic equations for the 2-Link Manipulator, first, using the DH method and, then, purely through the Sympy module.

Purpose

Our goal is to provide a straight forward scheme to derive relation between the joint and tip velocities (Jacobian matrix) of a serial robot (2-Link Manipulator) and analyze its singular configurations in a nice and interactive manner.

For this purpose, we will be using Jupyter Notebook\Lab which provides a flexible environment to develop the code and display plots. You may download and use this book as it is, or just grab the code and run it in any other Python development environment.

Prerequisites

Technical side: Know-how of robot kinematics is recommended, but not necessary.

Programing side: Beginner to intermediate level skills with Python and Jupyter Notebooks would be handy. The python library we will use in this post is:

  • Sympy (for symbolic computation)

Note: Assuming that you already know how to setup Python and Jupyter Notebook environment, it is skipped here.

Environment Setup

First, we import the SymPy library that will allow us to develop and manipulate symbolic expressions.

In [1]:
import sympy as sm

In SymPy, we initialize printing so that all of the mathematical equations are rendered in standard mathematical notation.

In [2]:
from sympy.physics.vector import init_vprinting
init_vprinting(use_latex='mathjax', pretty_print=False)

The Jupyter notebook can use IPython to display rich content. Here, We will use the Image function to import the geometric representation of 2-link manipulator example.

In [3]:
from IPython.display import Image
Image('fig/2rp_new.png', width=300)
Out[3]:

2RP Manipulator

2-link planar manipulator (sometimes called as 2RP manipulator, R stands for the revolute joints) is a basic manipulator example often described in robotics textbooks.

Now, we declare the symbols (link lengths, joint variables) which will be used for further formulation.

In [4]:
from sympy.physics.mechanics import dynamicsymbols
In [5]:
theta1, theta2, l1, l2 = dynamicsymbols('theta1 theta2 l1 l2')
theta1, theta2, l1, l2 
Out[5]:
$$\left ( \theta_{1}, \quad \theta_{2}, \quad l_{1}, \quad l_{2}\right )$$

Velocity mapping

From previous posts, we know the forward kinematic equations are;

In [6]:
px = l1*sm.cos(theta1) + l2*sm.cos(theta1 + theta2) # tip psition in x-direction
py = l1*sm.sin(theta1) + l2*sm.sin(theta1 + theta2) # tip position in y-direction

Now, the manipulator tip velocities ($\dot{px}, \dot{py}$) are mapped with the joint velocities ($\dot{\theta}_1, \dot{\theta}_2$) using the relation,

\begin{align}\left[ \begin{matrix} \dot{px} \\ \dot{py} \end{matrix}\right] = J(\theta_1,\theta_2) \left[ \begin{array}\\ \dot{\theta}_1 \\ \dot{\theta}_2 \end{array} \right], \end{align}

where $J(\theta_1,\theta_2)$ represents the Jacobian matrix which can be obtained by differentiating the above given forward kinematic equations.

In [7]:
a11 = sm.diff(px, theta1) # differentiate px with theta_1
a12 = sm.diff(px, theta2) # differentiate px with theta_2

a21 = sm.diff(py, theta1) # differentiate py with theta_1
a22 = sm.diff(py, theta2) # # differentiate py with theta_2

Jacobian Matrix

From above the above differentiation, the Jacobian elements can be used to construct the Matrix,

In [9]:
J = sm.Matrix([[a11, a12], [a21, a22]]) # assemble into matix form
Jsim = sm.simplify(J) # use sympy simplification method to obtain simplified results
Jsim
Out[9]:
$$\left[\begin{matrix}- l_{1} \operatorname{sin}\left(\theta_{1}\right) - l_{2} \operatorname{sin}\left(\theta_{1} + \theta_{2}\right) & - l_{2} \operatorname{sin}\left(\theta_{1} + \theta_{2}\right)\\l_{1} \operatorname{cos}\left(\theta_{1}\right) + l_{2} \operatorname{cos}\left(\theta_{1} + \theta_{2}\right) & l_{2} \operatorname{cos}\left(\theta_{1} + \theta_{2}\right)\end{matrix}\right]$$

Manipulator Singularities

Singularities are those manipulator configurations where it loses one or more degrees-of-freedom, i.e., it can not move further in specific direction(s). Physically, it means a manipulator would be in a singular configuration if its tip/end-effector cannot move in one or more directions. In other words, infinite joint velocities are required to move the end-effector in that particular direction(s).

Mathematically, singularities relate to the manipulator configuration(s) for which its Jacobian matrix becomes singular, i.e., $$\text{det}~J = 0.$$ In Sympy, this can be analytically calculated as,

In [10]:
Jdet = sm.det(Jsim) # determinant of Jacobian matrix 
detJ = sm.simplify(Jdet)
detJ
Out[10]:
$$l_{1} l_{2} \operatorname{sin}\left(\theta_{2}\right)$$

The above result gives information about all possible singular configurations of the 2-Link Manipulator. We solve the above equation against zero and get,

In [11]:
sm.solve(detJ, (theta2)) # slove detJ for theta_2
Out[11]:
$$\left [ 0, \quad \pi\right ]$$

This means the manipulator will be in singular configuration when the angle $\theta_2$ is either zero or it is $\pm \pi$,

$$\{(\theta_2)| \theta_2 = 0, \theta_2 = \pm \pi\}$$

Manipulator configuration when $\theta_2 = 0$

In [12]:
Image('fig/2rp_sing_config1.png', width=300)
Out[12]:

Manipulator configuration when $\theta_2 = \pm \pi$

In [13]:
Image('fig/2rp_sing_config2.png', width=300)
Out[13]:

Next...

That's all for this post! In the next article, we will see how to analyze the 2-Link manipulator's kinematic performance using various performance indices such as manipulability and isotropy.