Animation of a 2R - robotic arm using Python
1.AIM: To simulate the forward kinematics of a 2R Robotic Arm
2.ASSUMPTIONS:
- Assumption of the lengths of the two links, l1 and l2.
- The initial co-ordinates of the base of the robotic arm (0,0) i.e the base of the robot arm is assumed to be at the origin.
3.OBJECTIVES:
- To determine the various motions of the robotic arm and the manipulator in its workspace.
- Create an animation file of the plot.
4.FLOW :
- Assign values to the input variables.
- Get the values of co-ordinates of the various link motion.
- Plot the graphical representation of the robotic links and stitch the various plots and create an animation.
5.PYTHON CODE :
import math
import matplotlib.pyplot as plt
#input lengths
l1=2
l2=1
n_theta=12 #no of values required in the range of 0 to 90 degree
theta_start=0 #start from
theta_end=math.pi/2 # end to
theta1=[] #array to store all values for theta1
theta2=[] #array to store all values for theta2
for i in range(0,n_theta):
tmp=theta_start + i*(theta_end - theta_start)/(n_theta - 1) # to evaluate the minimum interval
theta1.append(tmp) # append all the values in theta 1
theta2.append(tmp) # append all the values in theta 2
# start point of link 1
x0=0
y0=0
count=1 # count for the no. of images generated
for t1 in theta1:
for t2 in theta2:
#link 1 & link 2 common point
x1= l1*math.cos(t1)
y1= l1*math.sin(t1)
#end point of link 2
x2=x1+l2*math.cos(t2)
y2=y1+l2*math.sin(t2)
#increment the no. of images generated
filename= str(count) + '.png'
count=count+1
#plotting data
plt.figure()
plt.plot([x0,x1],[y0,y1])
plt.plot([x1,x2],[y1,y2])
plt.xlim([0,3]) #setting the plot limits for x axis
plt.ylim([0,3]) #setting the plot limits for y axis
plt.savefig(filename) #saving all the plots
6. OBSERVATION:
- The multiple plots are extracted one by one and stitched together to form an animation.
7.CONCLUSION:
- The animation depicts the various possible motions and the co-ordinates of the arm as well as the manipulator.
- The final animation of the various plots of the two links is obtained by the image stitching process, and thus the animation is generated in MATLAB.
- The Youtube animation which is uploaded on my channel is provided below: