Project

Simulation of forward kinematics of 2R robotic arm

Aim:

To simulate the forward kinematics of a 2R robotic arm using python.

Objective:

To animate and simulate the motion of the 2R robotic arm in the given workspace.

Theory:

Forward kinematics means the use of kinematic equations of a robot to compute the position of the arm of the robot from specified values for the joint parameters.

A robotic arm is a usually a programmable robot manipulator having similar functions as a human arm. In our robotic arm there are 2 links forming a kinematic chain which allows for both rotational and translational motion. These types of robots are vastly used in industries such as automobile, electronics, welding etc.

Input Parameters:

L1=length of link 1

L2=length of link 2

Theta1=angle made by link 1 w.r.t x-axis

Theta2=angle made by link 2 w.r.t x-axis

(X0, Y0) = starting point of link 1

(X1, Y1) = ending point of link 1 and starting point of link 2

(X2, Y2) = ending point of link 2

Explanation of code:

  • Length of first link is assumed to be 1 m
  • Length of second link is assumed to be 0.5 m
  • Theta1 and Theta2 varies from 0 to 90 degree in 4 partitions
  • The value of counter is set to 1 which increases by 1 for every iteration of loop
  • Double for loops are used for iteration of the robotic arm position
  • First for loop is for link 1 and second for loop is for link 2
  • The positions of link 1 and link 2 is itearted and plotted in a graph
  • saveas and sprintf command were used to save each iteration.
  • ImageMagick was used to create the animation in gif file.

Code:

Programming language used=Python

# Simulation of forward kinematics of a robotic arm
# By : Anubrat Padhee

# Importing math library
import math

# Importing matplotlib library
import matplotlib.pyplot as plt

# Length of link 1 unit-m
l1=1

# Length of link 2 unit-m
l2=0.8

# Taking equal intervals od theta1 and theta2
n_theta=10
theta_start=0
theta_end=math.pi/2

# Theta 1 
theta1=[]

# Theta 2
theta2=[]

for i in range(0,n_theta):
	temp=theta_start+i*(theta_end-theta_start)/(n_theta-1)
	theta1.append(temp)
	theta2.append(temp)

# Base of robotic arm
x0=0
y0=0

#counter variable 
ct=1

for t1 in theta1:
	for t2 in theta2:
		# End of link 1 and start of link 2
		x1=l1*math.cos(t1)
		y1=l1*math.sin(t1)

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

		filename=str(ct)+".png"
		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)
		ct=ct+1

Output:

https://drive.google.com/open?id=13ockKI_CwCYUvUWsdZOhpiqMkxGUCCMv

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.