2R Robotic Arm Simulator Using Python
Description
The Program consists of two links L1 and L2. For Varying the angles for loop is used and the theta start and theta end are mentioned. Then using for loop position of the links are varied. Then by savefig comment the plots are saved. The Plots are stiched into gif file by the Image Magick.
import math
import matplotlib.pyplot as plt
#Inputs
l1 = 1
l2 = 0.5
n_theta = 10
theta_start = 0
theta_end = math.pi/2
theta1 = []
theta2 = []
for i in range(0,n_theta):
temp = theta_start + i*(theta_end - theta_start)/(n_theta-1)
theta1.append(temp)
theta2.append(temp)
x0 = 0
y0 = 0
ct = 1
for t1 in theta1:
for t2 in theta2:
x1 = l1*math.cos(t1)
y1 = l1*math.sin(t1)
x2 = x1 + l2*math.cos(t2)
y2 = y1 + l2*math.sin(t2)
filename = \'test%05d.png\' % ct
ct = ct + 1
plt.figure()
plt.plot([x0,x1],[y0,y1])
plt.plot([x1,x2],[y1,y2])
plt.xlim([0,2])
plt.ylim([0,2])
plt.savefig(filename)
Result
I have attached the animation file in the below link.
https://drive.google.com/file/d/1KD3EbwcpXMy8KJ5EEiawv2bubuPQB5l7/view