Project

Simulation of the forward kinematics of a 2R Robotic Arm

Simulation of the forward kinematics of a 2R Robotic Arm in an animation

Description :

Forward kinematics is the study of analysing and detecting the workspace of a robotic arm with the help of kinematic equations so that one can understand the possible working areas of a robotic arm. In this project, a 2R robotic arm is mentioned which means that two links are only used for working in this scenario which can rotate or work in a two-dimensional plane with each links having only single degree of freedom. In this scenario, both the links are restricted to a 90 degree rotation with respect to the axes. In this code, various number of plot figures are obtained according to the inputs and they are finally merged into a single gif file to clearly understand and visualize the working of a 2R Robotic arm.

Code for the project :

#Program to simulate the forward kinematics of a 2R Robotic Arm
# and to create a animation using all the plots

import math
import matplotlib.pyplot as plt 

n_theta = 15     #creating no. of angles needed

#initialising the values for the starting and ending values of theta
theta_start = 0
theta_end = math.pi/2

l1=1
l2=0.5

#declaring empty arrays to be appended
theta1=[]
theta2=[]

#intialing the points as origin
x0 = 0
y0 = 0

count = 1   #a counter variable

#getting values for theta1 and theta2
for a in range(0,n_theta):
	temp = theta_start + a*(theta_end-theta_start)/(n_theta-1)
	theta1.append(temp)
	theta2.append(temp)

for a1 in theta1:
	for a2 in theta2:
		#calculating end point of Link1
		x1 = l1*math.cos(a1)
		y1 = l1*math.sin(a1)

		#calculating coordinates of end point of Link2
		x2 = x1 + l2*math.cos(a2)
		y2 = y1 + l2*math.sin(a2)

		filename = str(count) + '.png'
		#incrementing the variable for the next iteration
		count = count + 1

		plt.figure()                   #to obtain different plot windows
		plt.plot([x0,x1],[y0,y1])      #to plot in x-axis
		plt.plot([x1,x2],[y1,y2])      #to plot in y-axis
		plt.xlim([0,2])                #to set limits
		plt.ylim([0,2])
		plt.savefig(filename)   #saving the file with a new name each iteration

Output :

( Various images are merged into a single gif file for an animation )

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.