Project

FORWARD KINEMATICS OF 2R ROBOTIC ARM USING PYTHON

AIM

To write a program to simulate the forward kinematics of the 2R robotic arm and create an animation file on the plot

2R ROBOTIC ARM

It consists of two links. The first link is connected to the base in an angle of theta1. And the second link is connected with the first link. The starting point of the second link is the ending point of the first link. The second link is at an angle of theta2 to the normal. The endpoint of the second link is used for the machining processes like welding or any process.

PROGRAM TO SIMULATE THE ROBOTIC ARM

import math
import matplotlib.pyplot as plt 

#inputs
l1 = 1
l2 = 0.5

#thetas
n_theta = 10
theta_start = 0
theta_end = math.pi/2
theta_1 = []
theta_2 = []

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

#initial coordinates
x0 = 0
y0 = 0

#loop for creating 100 values 
ct = 1
for t1 in theta_1:
	for t2 in theta_2:
		x1 = l1*math.cos(t1)
		y1 = l1*math.sin(t1)
		x2 = x1+l2*math.cos(t2)
		y2 = y1+l2*math.sin(t2)
		filename = 'test%05d.png'%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

  • The lengths of the link1 and link2 are given as 1 m and 0.5 m respectively
  • Then no of theta values for which the simulation to be done is given as 10
  • The limits for the theta should be given (ie) the starting and ending value of theta. Between the starting and ending value of theta, there will be ten no. of values.
  • The starting value of theta is 0 and the ending value of theta is 90
  • For calculating the ten values between the starting and ending, 'for loop' is used
  • For both the thetas separate empty array is created and using 'append' command the values are stored in the respective arrays
  • The coordinates of the starting point of the first link are (0,0)
  • The coordinates of the ending point of the first link are calculated by means of angle theta. As there are different values of theta another 'for loop' is created to calculate the coordinates
  • Then using plot command the coordinates are plotted and there should be 100 plots
  • To obtain those 100 plots, the counter variable is used
  • Then using magick command all the 100 plots are stitched and an animation file is created

ANIMATION LINK

https://youtu.be/P5nyKoEfJG8

RESULT

Thus the program was coded to simulate the 2R Robotic arm and an animation file was created on it.

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.