Project

2R Robotic Arm Simulator using PYTHON

Forward Kinematics Simulator of a 2R Robotic Arm

Aim: To develop a PYTHON script to simulate the forward kinematics of a 2R robotic arm by simulating the profiles of the angles projected by the two linkages along with the x-axis. To utilize real time relative positions of the end points of the links as functions of the angle subjected by the links to the horizontal.

Figure 1: 2R Robotic Arm

Method:

  1. A python script was set-up in sublime and saved to a define folder
  2. The matplotlib, math, and numpy modules were imported to the script
  3. The length of the two links were defined.
  4. Using linspace command with numpy extension, the range of motion for the two angles ‘theta1’ and ‘theta2’ were defined from 0 to π/2 radians
  5. By using vector decomposition, the end-point of link 1 or the start point of link 2 (X1, Y1) was computed relative to the start point of link 1(X0,Y0), where the datum was placed.
  6. Vector sum for the components of the two links was used to determine the end-point of link 2. (X2, Y2)
  7. The projected angles of the two links were simulated to take on range of angles between 0° and 90°.
  8. A PYTHON script was developed to iterate the profiles of the two links for iterations of first quadrant angles.
  9. To the purpose of step 5, a nested for loop was utilized to iterate between range of angles for link 2 for every iteration of the projected angle of link 1.
  10. A plot command was used under the second loop to plot the profiles of the two links by plotting the start and end points of the links.
  11. A counter was set-up within the second loop and a filename was defined to take the value of the counter for every subsequent iteration.
  12. A new figure window was defined as “plt.figure()” and the figure was saved with the filename.
  13. The generated plots were then stitched using ImageMagick from the command prompt by indexing via occurrence and saved as “.flv” file.

CODE:

"""
           PYTHON for M.E.
Forward Kinematics of a 2R Roboitc Arm
    Authored by Amandeep Singh

Purpose:
To develop a matlab animation simulating the forward kinenmatics or
motion of a 2R robotic arm.

Apporoach
 Utilize real time relative positions of the end points of the links as
 functions of the angle subjected by the links to the horizontal.
 The animation was created by plotting the varying positions of the links
 in real time, accomplished via a nested for loop, and subsequently stitching 
 the series of plots using imageMagik.
 """

# Script
import math as m 
import matplotlib.pyplot as plt 
import numpy as np 

# Defining Inputs
l1 = 1 #length link 1 in m
l2 = 0.5 #length link 2 in  m

theta1 = np.linspace(0,m.pi/2,10)
theta2 = np.linspace(0,m.pi/2,10)


# start point of link 1 
x0 = 0 #x-coordinate of start point 
y0 = 0 

ct = 1
for t1 in theta1:
	for t2 in theta2:
		# Link 1-link 2 connect point
		x1 = x0+l1*m.cos(t1)
		y1 = y0+l1*m.sin(t1)
		# End point of link 2, co-ordinates of manipulator
		x2 = x1 + l2*m.cos(t2)
		y2 = y1 + l2*m.sin(t2)

		filename = str(ct) + '.png'
		ct = ct + 1
		#plots
		plt.figure()
		plt.plot([x0,x1], [y0,y1])
		plt.plot([x1,x2], [y1,y2])
		plt.xlim([0,1.6])
		plt.ylim([0,1.6])
		plt.savefig(filename)


	


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.