2R ROBOTIC ARM SIMULATOR
AIM : To simulate the forward kinematics of a 2R Robotic Arm using python programme
INTRODUCTION : Robotic Arms areone of the most common industrial tools to maintain quality and precision as, Robotic arms are very accurate. Designing these arms also constitute the process of simulation.
Why to Simulate?
Simulating a mechanism is an important part of design procedure these days, as it helps to preview the working position of the machine at all given inputs and to verify if the results are desirable or not.
Why Python for Simulation ?
As python is an easy to process language and can be easily used to intergrate several other tools to generate output, it makes it the best option to simulate mechanisms.
Code : The following code when run give 100 output image files, presenting Robotic arm's movement.
import math
import matplotlib.pyplot as plt
#Link Lengths : As there are two links for an arm
l1 = 1
l2 = 0.5
n_theta = 10
theta_start = 0
theta_end = math.pi/2
#Angle has been converted to radian as degrees will give non constant quadrant and will create problem in the video.
theta1=[]
theta2=[]
#creating a for loop to save theta values at the end of 2nd arm after the 1st arm theta values.
for i in range(0,n_theta):
tmp = theta_start + i*(theta_end-theta_start)/(n_theta-1)
theta1.append(tmp)
theta2.append(tmp)
x0 = 0
y0 = 0
#Defining a counter variable ct to save different output using for loop and save accordingly.
ct=1
for t1 in theta1:
for t2 in theta2:
#Link 1, Link2 connector
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= str(ct) + '.png'
ct=ct+1
plt.figure()
plt.plot([x0,x1],[y0,y1])
plt.plot([x1,x2],[y1,y2])
plt.xlim([0,2]) #To restrict the plot
plt.ylim([0,2]) #To restrict the plot
plt.savefig(filename)
OUTPUT : 2nd co-ordinate output out of 100 outputs.
*After the output generated, in the image format. Wondershare filmora was used to compile the images into a continous slideshow.
Result : Here is the complete simulation of the robotic arm video