2R robotic arm using python
This code is to track the kinematic motion of a 2R Robotic arm.
it starts with considering its initial position coordinates as input.
the link lengths of the arm are considered as follows:
l1 = 1 metre
l2 = 0.5 metre
considering origin as the initial postion of the first link, the coordiates can be cosidered as
x0 = 0, y0 = 0, x1 = l1*cos(theta1), y1 = l1*sin(theta1), x2 = x1+l2*cos(theta2), y2 = y1+l2*sin(theta2)
the arm is give a range of 90 degrees for rotation in an interval of 10 degrees
each value of theta is stored and corresponding position of the link is caclculated and the iteration continues for all values of theta1 and theta2.
a graph is plotted for each position and saved in a folder which is converted into animation for visual understanding.
import math
import matplotlib.pyplot as plt
#defining range of theta
n_theta = 10
theta_start = 0
theta_end = math.pi/2
#inputs
l1 = 1
l2 = 0.5
theta1 = []
theta2 = []
#creating and storing different valules
for i in range(0,n_theta):
tmp = theta_start + i*(theta_end - theta_start)/(n_theta-1)
theta1.append(tmp)
theta2.append(tmp)
#loop for calculating and plotting values
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 = str(ct) + \'.png\'
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)