Project

2R ROBOTIC ARM SIMULATOR WITH PYTHON

Aim:

Creation of animation of the 2R Robotic Arm Using Python Program

Objective:

  • Write a program in python to simulate the forward kinematics of a 2R Robotic Arm, as shown in the video.
  • Create an animation file of the plot.

Theory:

Kinematic is a branch of mechanics that studies the motion of a body or a system of bodies, without consideration given to its mass or the force acting on it. A serial link manipulator comprises a chain of mechanical links and joints. Each joint can move its outward neighboring link with respect to its inward neighbor. One end is fixed to the ground (Link A) and Link B is connected to the end of Link A.

θ1 – Angle made by the fixed link to the base

θ2 – Angle made by Link B with respect to Link A

l1- length of Link A

l2- length of Link B

Python Program

"""
2R Roboitc Arm Simulator using python
Generated plots are stiched together by using ImageMagick for Animation
by SLOMO THOMAS
"""

#Modules Imported in the program
import math
import matplotlib.pyplot as plt 
import numpy as np 

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

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


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

ct = 1
for t1 in theta1:
	for t2 in theta2:
        # Link 1 to Link 2 connection
		x1 = x0+l1*math.cos(t1)  
		y1 = y0+l1*math.sin(t1)
		# End point of Link 2 & Co-ordinates of Manipulator
		x2 = x1 + l2*math.cos(t2)
		y2 = y1 + l2*math.sin(t2)

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

Explanation of the code

  • The inputs given to the program are the length of the Link A as l1 and l2 be the length of the link B. we assume the angular movement is 0 to 90 degrees, to get angles between 0 and 90, linspace command is used.
  • The different values of angle are connected by using for loop. Two for loops are used in the main program. If we didn’t use the for loop, we get each figure differently.
  • Coordinates of each link we determined are given by assigning name as mentioned at the determination of the position of each link
  • Plotting command is used for getting each position of the 2R robotic arm Plot(__)
  • ct=1 and ct=ct+1 is the command for getting next to the next value of the angle

using ImageMagick and command prompt (cmd) all generated plots are stitched together by using the following command in command prompt (cmd)

"magick *.png output.gif"

Results

  • Animated Video

Youtube Link

  • Plots in folder (Auto generate)

Conclusion:

  • Plots are obtained
  • The animation is created using ImageMagick
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.