Project

Forward kinematics of the 2R robotic arm manipulator by using the Python programming language.

Objective:

To show the forward kinematics of the 2R robotic arm manipulator by using the Python programming language.

Problem Statement:

For the 2R robotic arm manipulator considering the forward kinematics if the angles i.e., theta1 and theta2 are changes in that case what will be the final position of the manipulator?. This the required problem statement.

Solution Procedure:

  • Here we only need to do mathematics and figure out the position and orientation of any point on the robot.
  • As all the required geometry and all its joints point of the robot are given.
  • Here we are considering only with kinematics motion which means no external and internal forces are considered.

From the above diagram, we could say that it consists of

  • Base as link 1 is attached here; Link 1; Link 2; Robotic-arm/ Manipulator.
  • Link 1 and Base can have a motion with an angle of theta1 and Similarly
  • Link 2 and Link 1 can have a motion with an angle of theta2.
  • To see the motion we need to create a plot at various angular positions upto which these arms can move. And here comes the requirement to know the coordinates at the joints required for the motion.
  • At the base, the coordinate is (0,0) and at the end of the first link/ start of the second link the coordinate is (x1,y1) and at the manipulator, the coordinate is (x2,y2).
  • I hereby give my theta_start = 0 and theta_end = Pi/2.
  • By using mathematics we could relate the coordinates in terms of link 1 and link 2. Therefore

`x0=0;y0=0; x1=l1⋅cosθ1; y1=l1⋅sinθ1; x2=x1+l2cosθ2; y2=y1+l2sinθ2`

I hereby attached my output result link here below which shows the animation of my code output.

https://youtu.be/r8rbpW7SryE

The below-given steps are the procedure that I follow in my coding of this problem. I clearly give comments in every step that I do in the code.

""" Python code used to solve the Forward Kinematics 
    of the 2R robotic arm manipulator
""" 
# Importing the required modules
import math
import matplotlib.pyplot as plt

# Inputs are:.......

# length of link 1 (l1)
l1 = 1
# length of link 2 (l2)
l2 = 0.5
# No. of angles made by links.
n_theta = 10
# Initial angle and Final angle.
theta_start = 0
theta_end = math.pi/2

theta1 =[]
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)

# Coordinates of base of the robot	
x0 = 0
y0 = 0

ct = 1
for t1 in theta1:
	for t2 in theta2:
		# Coordinates of end of link 1 or start of the link 2
		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 = 'test%05d.png' % ct
		ct = ct + 1
		
		plt.figure()
		# Giving a title to my graph
		plt.title('Animation of Forward kinematics of the \n 2R robotic arm manipulator',color = 'maroon')
		# Plotting the points
		plt.plot([x0,x1],[y0,y1], label = 'link 1', marker = 'o', markerfacecolor = 'red')
		plt.plot([x1,x2],[y1,y2], label = 'link 2', marker = 'o', markerfacecolor = 'red')
		# Setting the x-axis and y-axis range
		plt.xlim([0,2])
		plt.ylim([0,2])
		# Naming the x-axis
		plt.xlabel('x - axis', color = 'green')
		# Naming the y-axis
		plt.ylabel('y - axis', color = 'green')
		# Show a legend on the plot
		plt.legend()
		# Function to save the fig
		plt.savefig(filename)
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.