2R Robotic Arm Simulator using Python
2R Robotic Arm Simulator using Python
Objective:
- create the animation of 2R Robotic arm for different θ values using python.
Description:
- A 2R robotic arm consists of 2 links and has a manipulator at the end of 2nd link.
- First link is fixed at one end and is making an angle θ1 with horizontal.
- Another link is making an angle θ2 with horizontal.
- The coordinates of two links are as follows:
where as
- X0,Y0 are coordinates at the fixed end
- X1,Y1 are coordinates at the end of first link
- X2,Y2 are coordinates at the end of second link
Programming in python:
The following is the code for decribing the motion of arms of 2R robot :
import math
import os
import matplotlib.pyplot as plt
n=10
t1=0
t2=math.radians(90)
l1=1
l2=0.5
x0,y0,f=0,0,0
for i in range(0,n):
for j in range(0,n):
theta1=math.radians(t1+i*9)
theta2=math.radians(t2+j*9)
x1,y1=l1*math.cos(theta1),l1*math.sin(theta1)
x2,y2=x1+l2*math.cos(theta2),y1+l2*math.sin(theta2)
plt.figure()
plt.xlim([0,2])
plt.ylim([0,2])
plt.plot([x0,x1],[y0,y1])
plt.plot([x1,x2],[y1,y2])
plt.legend(["link-1,link-2"])
f=f+1
plt.savefig("C:\\Users\\Admin\\Pictures\\gif\\forward"+str(f))
- Importing matplotlib module is necessary for plotting the coordinates of links
- t1,t2 are angles in this range the motion has been captured in this program
- l1,l2 are the lengths of links
- Logic has been written inside the nested loop for the flexble combinations of angles for θ1andθ2
- Using functions from module plotting has been programmed in the loop itself for collecting all the pictures of motion for animation.
Commands used in code:
Performing Animation:
- To perform animation here we used magick tool.
- Go to command prompt change directory to location where these pictures are saved
- Go to command prompt
>>> cd C:\Users\Admin\Pictures\gif2
>>> magick *.png output.gif
- Then you will get a gif file named output in the same loction.
Results:
The obtained gif is as follows:
Conclusion:
- Animation of 2R robotic arm has been created using python and magick animation tool.