Project

2R Robotic Arm Simulaation Using Python

1 OBJECTIVE: To write a python program wherein to simulate the motion of 2R robotic arm.

2 INTRODUCTION

Robotic arm animation can be used to know the workspace of the robotic system and also to trace the path of the end effector. For the present study, 2R robotic arm is considered. The one end of the first link is fixed and rotation about the axis is possible. The other end, link 2 is attached which is free to rotate about the axis. At the end of link 2 end effector is fixed. This is show in fig. 1 below.

Fig. 1: Simple sketch of 2R robotic arm. Picture credits- www.google.com

In the above fig. 1, `theta1` and `theta 2` are the angle subtended by the link 1 (l1) and link 2 (l2) respectively. for the present study we limt the both angles to 90 degrees. The values of the co-dinates for the links can be caluclated by using simple trignometric relations.

At the fixed end say x0 and y0 are co-ordinates, then x0= 0 and y0= 0.

At the end of link 1, x1 and y1 are co-ordinates, then x1= l1 cos(`theta1`) and y1= l1 sin(`theta1`).

At the end of link 2, x2 and y2 are co-ordinates, then x2= x1+( l2 cos(`theta2`) ) and y1= y1+ (l2 sin(`theta2`)).

Animation is created by a making an array of `theta` values. The python program is written below with the help of this idea.

3 PYTHON PROGRAM

""" Program for 2R robot forward animation """
import math
import matplotlib.pyplot as plt 

# inputs 
l1=1 #  length of the link 1
l2=0.5 # length of link 2
n_theta= 10 # no of theta values required
theta_start= 0
theta_end= math.pi/2 # math.pi assigns the value of pi=3.142...

# Base of the Robot
x0= 0
y0= 0

# creating a array of theta 1 and 2 with n_theta values in between
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)

ct=1 # assining the counter variable

# caluclations
for t1 in theta1:
	for  t2 in theta2:
		# Link 1 
		x1= l1*math.cos(t1)
		y1= l1*math.sin(t1)

		# Link 2
		x2= x1 + l2*math.cos(t2)
		y2= y1 + l2*math.sin(t2)

		# plotting and saving figure
		filename = str(ct) + '.png'
		ct=ct+1 # addding the counter by one for next iteration
		
		plt.figure()
		plt.plot([x0,x1],[y0,y1])
		plt.plot([x1,x2],[y1,y2])
		plt.xlim([-0.1,2])
		plt.ylim([-0.1,2])
		plt.savefig(filename)

4 ANIMATION VIDEO

5 CONCLUSION

Animation is obtained by using imageMagik. This helps to understand the forward kinematics of the robotic arm.

6 REFERENCES

  1. https://in.mathworks.com/help/fuzzy/examples/modeling-inverse-kinematics-in-a-robotic-arm.html
  2. https://projects.skill-lync.com/projects/2R-Robotic-arm-simulation-70336
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.