Project

Forward Kinematic of a 2R Robotic Arm

The objective of this project is to simulate the forward kinematic of a 2R Robotic Arm by plotting the link using python.

The 2R Robotic arm is as seen below:

Forward kinematics refers to the use of the kinematic equations of a robot to compute the position of the end-effector from specified values for the joint parameters.

Our aim is to compute the end position of link 2- the manipulator for various angles of theta 1 and theta 2.

First, let the length of link 1 be l1 and length of link 2 will be l2

Let us assume that the origin point is x0, y0. And the position at which link 1 is present as x1, y1 and the position of the manipulator as x2, y2.

The angle link 1 makes with the horizontal is Θ 1 and the angle link 2 makes with the horizontal is Θ2.

For simplicity let us assume that x0, y0 is the origin i.e. 0, 0.

We can find out x1 and y1 from the following equation:

`x1=l1*cosθ1`

`y1=l1*sinθ1`

After finding out x1 and y1 we can proceed to find x2 and y2.

`x2=x1+l2cosθ2`

`y2=y1+l2sinθ2`

Now we can find the values of x1, x2, y1 and y2 for multiple values of Θ 1 and Θ2 and then by plotting them we can simulate the motion.

The code written for the simulation is as shown below:

#Code to simulate the forward kinematic of a 2D Arm
#Abhinandhan_Narayanan

#importing the libraries

import math
import matplotlib.pyplot as plt

#initialising the lengths of the two links
l1 = 1
l2 = 0.5

#number of angles 
n_theta = 10

theta_start = 0 #start value

theta_end = math.pi/2 #end value

#angles of link 1 and link 2
theta1 = []
theta2 = []
ct=1
#loop to append angles in the array
for i in range(0,n_theta):
	theta1.append(theta_start + i*(theta_end-theta_start)/(n_theta-1))
	theta2.append(theta_start + i*(theta_end-theta_start)/(n_theta-1))

x0=0
y0=0

for t1 in theta1:
	for t2 in theta2:

		x1 = l1*math.cos(t1)
		y1 = l1*math.sin(t1)

		x2 = x1+ l2*math.cos(t2)
		y2 = y1 + l2*math.sin(t2)
		filename = str(ct) + '.png'
		ct+=1

		plt.figure()
		plt.plot([x0,x1],[y0,y1])
		plt.plot([x1,x2],[y1,y2])
		plt.xlim([0,2])
		plt.ylim([0,2])
		plt.savefig(filename)

		
		

After importing the variables and initialising the values of the length of the links, the number of values for Θ1 and Θ2 has to be decided. In this case number of values for the angles are taken as 10.

Now the angles have to be appended in an array. The start value and end value between which the angles have to be in are initialised. The starting value is taken as 0 degree and ending value as 90 degree. After that 10 values within this interval are appended to both Θ1 and Θ2.

After the angles have been stored in an array we can proceed to calculate x1, y1 and x2,y2 using the formula mentioned above.

Now these points are plotted as and when they are calculated so that all the combinations of Θ1 and Θ2 are recorded. To plot each of the combination in a separate plot the figure() function is used.

A sample of the plot is as shown below:

After each of the plot has been saved as an image they are then compiled in the form of an animation.

The link to the animation is as seen below:

https://www.youtube.com/watch?v=SZWTbtL27BQ

The simulation of a 2R robotic arm was done using python and the animation of it was analysed

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.