2R ROBOTIC ARM SIMULATOR (PYTHON)
AIM: TO SIMULATE THE FORWARD KINEMATICS OF A 2R ROBOTIC ARM USING PYTHON
INTRODUCTION: A manipulator/end effector movement determines the workspace where the robotic arm can be applicable. Our motive is to animate the movement of the robotic arm with the subsequent relative motion between the two-comprising links.
OBJECTIVE:
- Write a program to simulate forward kinematics of a 2R Robotic Arm
- Animating and creating a movie from the plots/figures obtained from the program
INPUTS:
(x0, y0) = starting point of link1
(x1, y1) = endpoint of link1 / starting point of link 2
(x2, y2) = endpoint of link 2
l1 = length of the link attached to the base
l2 = length of the link between the first link and the end effector
theta1 = angle made by link 1 with x-axis
theta2 = angle made by link 2 with x-axis
PROGRAM:
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 = []
# Creating an array of values of theta and retaining them
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 counter variable
ct = 1
for 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 manipulator
x2 = x1 + l2*math.cos(t2)
y2 = y1 + l2*math.sin(t2)
# Naming the figures using the counter variable and saving them in '.png' format
filename = str(ct) + '.png'
ct = ct + 1
# Plotting figures and saving them with particular filename
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)
ANIMATION: The Link for the animation has been mentioned below –
CONCLUSION: A practical scenario regarding the functioning of the robotic arm and its workspace has been experienced by simulating the forward kinematics with a program in Python.