Project

2R Robotic Arm Simulator using Python

Aim: To write a program in python to simulate the forward kinematics of a 2R Robotic Arm

Theory:

Kinematics deals with the study of motion, without any reference to the forces that cause the motion.

Forward Kinematics is used to determine the required position and orientation from a given set of joint angles.

The robotic arm is used for multiple industrial applications, from welding, material handling and thermal spraying, to painting and drilling. The robotic technology also provides human like dexterity in a variety of environment.

The robotic arm is made up of a finite number of individual rigid segments. Each rigid segment is called as link and links are connected to each other by joints. Link move with respect to its joints.

In a 2-joint robotic arm, given the angles of the joints, the kinematic equations give the location of the tip of the arm.

L1 and L2 are length of the links

θ1 is the angle made by link 1 with X-axis

θ2 is the angle made by link 2 with X-axis

(X0, Y0) →Starting point of link 1

(X1, Y1) →End point of link 1 and Starting point of link 2

(X2, Y2) → End point of link 2

where,

X0=0 ; Y0=0

X1=L1 cos(θ1)

Y1= L1 sin(θ1)

X2=X1+L2 cos(θ2)

Y2=Y1+L2 sin(θ2)

Code:

# simulation of 2R robotic arm 
import math
import matplotlib.pyplot as plt

#Inputs
l1=1
l2=0.5

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

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()
    	plt.plot([x0,x1],[y0,y1])
    	plt.plot([x1,x2],[y1,y2])
    	plt.xlim([0,2])
    	plt.ylim([0,2])
    	plt.savefig(filename)

Explanation of code

1.First we import two libraries namely math library and matplotlib library.

2.Defining the length of both links l1 and l2.

3.Assigning n_theta=10 , starting angle which is denoted as theta_start =0 and the ending angle theta_end=90 degrees

4.Next two empty arrays called theta1 and theta2 are created.

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

6.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.

7.The counter variable 'ct' is used to store the figure after every iteration of for loop.

8.Then the coordinates of the links are calculated using the equations. Later, we store the filename as a string of (ct)+'.png',which eventually stores all the plot images.

9.Plots are obtained by plotting all the co-ordinate values and ‘'imageMagik” is used to stitch the plots together and create animation.

Errors in programming: No errors were obtained.

You tube link for an animation:

https://youtu.be/scNZJ7lId3g

Conclusion: Program to simulate the forward kinematics of a 2R Robotic Arm was written and the animation was created .

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.