2R Robotic Arm Simulator in Python
AIM:
Write a python program to simulate the Forward Kinematics of 2R Robotic ARM. And create plots for animation in GIF format.
Python Code:
#Simulation of 2R Robotic Arm using Python
import math
import matplotlib.pyplot as plt
#inputs
L1 = 1
L2 = 0.7
#defining the angles
n_theta = 10
theta_start = 0
theta_end = math.pi/2
theta1 = []
theta2 = []
for i in range(0,n_theta):
tmp = theta_start+i*(theta_end-theta_start)/(n_theta)
theta1.append(tmp)
theta2.append(tmp)
x0 = 0
y0 = 0
ct = 1
for t1 in theta1:
for t2 in theta2:
#link 1 and link 2 connectors
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])
plt.ylim([0,2])
plt.savefig(filename)
Robot Arm in Animation:
REPORT:
1. In this project, The Robot Arm has two links of different lenghts, l1 and l2.
2. The angles for Robot arm are defined as theta1 and theta2 for the simulation.
3. For each theta1 and theta2 we get 10 values, comibed together for 100 combinations.
4. For calculating the the three coordinates of 100 combinations, the following formula is used, first coordinate x0 = 0 and y0 = 0, Second_coordinate: x1=l1*math.cos(t1) and y1=l1*math.sin(t1), Thrid_coordinate: x2=x1+l2*math.cos(t2) and y2=y1+l2*math.sin(t2).
5. l1 and l2 be the length of arms and t1 and t2 be the theta values.
6. for loop was used to create the 100 combinations.
7. The plots were stored in a seperates files in png format.
8. The png plots were saved using and online wedbsite. gifmaker.me