a new title
INTRODUCTION :
To write a Python program to simulate the forward kinematics of a 2R robotic arm.
In this program, we need parameters like ;
-----(l1,l2) = lengths of the links,
-----(theta_start, theta_end) = starting and ending theta values,
-----(n_theta) = divisions of theta[angle],
-----tmp = temparary space to store changing theta values,
-----ct = counter variable,
-----(x1,x2,y1,y2) = co-ordinates of positioning of the links.
Python program to simulate the forward kinematics of 2R robotic arm :
import mathimport matplotlib.pyplot as plt# Inputsl1 = 1l2 = 0.5n_theta = 10theta_start = 0theta_end =math.pi/2theta1 = []theta2 = []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 = 0y0 = 0ct=1for t1 in theta1: for t2 in theta2: # Link 1, Link 2 connector x1 = l1*math.cos(t1) y1 = l1*math.sin(t1) # Coordinates of the manipulater 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)PROCEDURE :
1. To create a simulation of forward kinematics of a 2R robotic arm , I have followed the instructions as shown in the video.
2. The formula used :
x1 = l1*math.cos(t1)
y1 = l1*math.sin(t1)
x2 = x1 + l2*math.cos(t2)
y2 = y1 + l2*math.sin(t2)
3. Then added a counter feature to give each single output plot a different name, so 'str' (string) funtion is used and '.png' is mentioned so that the program knows to which format the images must be converted to.
4. Then the plot limits are mentioned so that all the outputs don't differ and be consistent.
ANIMATION :