Project

To simulate forward kinematics of 2R Robotic arm using Python Programming.

Aim:To simulate the forward kinematics of 2R robotic arm using PYTHON Programming.

Introduction: A robotic arm (not robotic hand) is a type of mechanical arm, usually programmable, with similar functions to a human arm; the arm may be the sum total of the mechanism or may be part of a more complex robot. The links of such a manipulator are connected by joints allowing either rotational motion (such as in an articulated robot) or translational (linear) displacement. The links of the manipulator can be considered to form a kinematic chain. The terminus of the kinematic chain of the manipulator is called the end effector and it is analogous to the human hand.

Application:The Robotic arm are used in various fields such as:

1.Welding

2.Painting

3.Package Industry

4.Food,Beverage,Sanitation

Procedure: Here in this we are actually want to get the positions of the link1 and link2 with the change in angle of both the links with the x-axis. Basically what is done here is n_theta is set to 10 which means we are getting the coordinates at 10 different angles .So 10 different angles of first link amd 10 different angles of second link makes it hundred coordinates.After we have taken the figure of all the positions and then compile it to make an animation so that we can clearly see what is going on.

But before all this in Python first of all we have imported some modules like "import math" , "import matplolib.pyplot as plt" etc so that there is no error in use of mathematical functions like sine ,cosine,pi,etc.

Then some input values is given such as length of link l1=1m and length of link l2=.5m.

The coordinates of link1 is : x1=l1cos(theta1) and y1=l1sin(theta1)

The coordinates of link2 is:x2=x1+l2cos(theta2) and y2=y1+l2sin(theta2)

n_theta=10 i.e. the angles have 10 different values.

theta_start=0 and theta_end =90 i.e. the angle starts from angle 0 to 90 degree in between there are 10 values.

Initially the base coordinates x0=0 and y0=0.

After that with the help of for loop we have to assign and save the values to theta1 and theta2 that is done with the help of assumed variable tmp and then all the values are appended in the theta1 and theta2 .

So, at different angles coordinates are obtained and then we have taken the figures of all these coordinates and compile them to make an animation.

PYTHON Program:

#Program to Simulate the forward kinematics of 2R Robotic arm 
#By Rahul Rai

import math      #These ar imported so that there is no error in using the mathematical functions
import matplotlib.pyplot as plt

#inputs
l1=1    #length of link1
l2=.5   #length of link2

n_theta=10   #Here we want to get 10 different values

theta1=[]    # Variables assigned for saving the different values of angle
theta2=[]

theta_start=0   # angle start form 0
theta_end=math.pi/2 #angle ends at 90

for i in range (0,n_theta):    #Here we are appending different values of angle in theta1 nad theta2
	tmp=theta_start + i*(theta_end-theta_start)/(n_theta-1)
	theta1.append(tmp)
	theta2=theta1

#Coordinates of base
x0=0
y0=0

ct=1
for t1 in theta1:
	for t2 in theta2:
		#Link1,Link2 connector
		x1=l1*math.cos(t1)
		y1=l1*math.sin(t1)

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


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

		plt.figure()                  # Here we are saving all figures in the filename and after that they are used to make animation
		plt.plot([x0,x1],[y0,y1])
		plt.plot([x1,x2],[y1,y2])
		plt.xlim([0,2])
		plt.ylim([0,2])
		plt.savefig(filename)

Result:

At different values of angles different coordinates are obtained and also the figures of different coordinates.The animation of this is given:https://youtu.be/02heeQM1Dvc

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.