Project

Forward Kinematics of a 2R Robotic Arm using Python

Aim: To simulate the Forward Kinematics of a 2R Robotic arm using Python.

Introduction: A robotic arm is a kind of a mechanical arm that is generally programmable. The arm might be a sum total of all the mechanisms or maybe a part of a more complex robot. The robotic arm is commonly a system comprising of various connections, called links. On the off chance when the orientation of the mechanical arm is determined, at that point it is conceivable to figure out the workspace of the arm. The workspace usually refers to all the potential areas that the robot can reach.

In this project, we are using Python as a scripting language to simulate the Robotic Arm.

Robot kinematics can be partitioned into forward kinematics and inverse kinematics. Forward kinematics is the utilization of the kinematic equations of a robot to compute the position of the end effector from specified values for the joint parameters. The kinematic equations for the robot series chain are obtained by means of a rigid transformation to describe the relative movements permitted for each joint and separate rigid transformation in order to define the dimensions of each link.

The general layout of a 2R Robotic arm is as follows:

Here,

Let ϴ₁ - Angle made by link 1 with the base of the robot

ϴ₂ - Angle made by link 2 with respect to X-axis

Inputs are – l1, l2, ϴ₁ and ϴ₂

Output- Movement of Manipulator

The code for the simulation of the 2R Robotic arm is as follows:

#Simulation of a 2R Robotic Arm 
#Importing the basic libraries/ modules
import math
import matplotlib.pyplot as plt

#Inputs
l1 = 1 #length of link 1
l2 = 0.5 #length of link 2

n_theta = 10

theta_start = 0
theta_end = math.pi/2

theta1 = []
theta2 = []

for i in range (0,n_theta):
	tmp = theta_start+i*(theta_end-theta_start)/(n_theta-1)
	theta1.append(tmp)
	theta2.append(tmp)

#Base of the Robot 
x0 = 0
y0 = 0

#Counter Variable
ct = 1
for t1 in theta1 :
	for t2 in theta2 :

		#Link 1, Link 2 connectors
		x1 = l1*math.cos(t1)
		y1 = l1*math.sin(t1)

		#Coordinates of the Manipulator
		x2 = x1+l2*math.cos(t2)
		y2 = y1+l2*math.sin(t2)

		filename=str(ct)+ '.png'
		ct= ct+1

		plt.figure() #Creating an empty figure for every iteration of a for loop
		plt.plot([x0,x1],[y0,y1])
		plt.plot([x1,x2],[y1,y2])
		plt.xlim([0,2]) #Providing axis limits
		plt.ylim([0,2]) #Providing axis limits
		plt.savefig(filename) #Saving the figure window with assigned name 

Concise Description of the Code:

In order to successfully execute the program, we import two main libraries; namely math library and mathplot library.

The program is provided with inputs; l1 and l2, which represent the lengths under consideration in metric units 1m and 0.5m respectively. Then, we assign n_theta=10, in this program, I have chosen 10 values for both theta1 and theta2. For each value of theta1; we get 10 values of theta2. So, we get 100 combinations. The starting angle is denoted as theta_start= 0 and the ending angle as theta_end as 90°. Later, two empty arrays are created as theta1 and theta2.

For generating different values of theta, a for loop is used, and every time it is executed; the values for theta gets stored.

Now, we create a temporary element as tmp, which is a function for creating temporary files and directories. Here, we use it to create theta values, followed by appending theta1 and theta2 values. Now, we create the counter variable 'ct', which is further used to store the figure after every iteration of for loop. Then, inside the for loop for t1 and t2, we assign the formulae of coordinates. Later, we store the filename as a string of (ct)+'.png', which will eventually store all the plot images.

Finally, we define the coordinates of both the start and end points of the link, using inputs and math modules. By importing the plot library, we also assign the xlimit and ylimit to provide the constraints.

Later, we plot the graphs using the plot module. Now, the program is run and all the images get updated. We generate 100 images, which are stitched together to obtain the desired animation. The animation depicts the forward kinematics of a 2R Robotic Arm.

The visual representation of the animation created is attached below:

Result:

Following is the result of the executed code for a 2R Robotic Arm Manipulator.

Conclusion:

Located the points along the forward motion of 2 links of a robotic arm of varying lengths, over a range of 0° to 90°, and generated the corresponding animation of the results achieved.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.