Simulating Forward Kinematics of a 2R Robotic Arm using PYTHON.
AIM:
To simulating Forward Kinematics of a 2R Robotic Arm using PYTHON.
GOVERNING EQUATION:
For link 1(arm1)
Start Point
x=0
y=0
End point:
x1=l1×cos(θ1)
y1=l1×sin(θ1)
For link 2 (arm2)
Start Point
x1=l1×cos(θ1)
y1=l1×sin(θ1)
End point
x2=x1+(l2×cos(θ2))
y2=y1+(l2×sin(θ2))
OBJECTIVES:
- Write a program to simulate the forward kinematics of a 2R Robotic Arm.
- Creating an animation from the plots obtained in the program.
THEORY:
Forward kinematics refers to the use of the kinematic equations of a robot to compute the position of the end-effector from specified values for the joint parameters.
A robotic arm is a type of mechanical arm, usually programmable, with similar functions to a human arm; the arm may be the sum total of the mechanism or may be part of a more complex robot. The links of such a manipulator are connected by joints allowing either rotational motion or translational displacement. The links of the manipulator can be considered to form a kinematic chain. The terminus of the kinematic chain of the manipulator is called the end effector and it is analogous to the human hand.
The link-1 is attached to the base and end of link one is connected to link-2. And end of link-2 is connected to the end effector which performs the desired operation.
EXPLANATION OF THE PROGRAM:
1) Lengths of both the links are taken as input. Length of link-1 (L1) is taken as 2m and length of link-2 (L2) is taken as 1m.
2) Angles traced by both the links, for link-1 and for link-2 is taken as input. The angles traced are varied over a range to simulate the movement of the robotic arm.
3) Base position of link-1 (x0,y0) is considered as origin (0,0).
4) Then two for loops are used to iterate over the range of angles traced by both the links. For each particular angle of link-1, link-2 is moved over its entire range, to obtain different positions of end effector at that angle of link-1
5) For a particular value of θ1 and θ2, the end position of link-1 is calculated by these equations.
x1=L1⋅cos(θ1)
y1=L1⋅sin(θ1)
The end position of link-1 is also the start position of link two. The end position for link-2 is calculated by these equations.
x2=x1+L2⋅cos(θ2)
y2=y1+L2⋅sin(θ2)
6) Then for each particular position of link-1 and link-2, a plot is made.
PROGRAM CODE:
# Program to create simulation of 2R robotic arm manipulator
import math
import matplotlib.pyplot as plt
# Inputs
l1 = 2
l2 = 1
x0 = 0
y0 = 0
n_theta = 10
theta_start = 0
theta_end = math.pi/2
ct = 1
theta_1 = []
theta_2 = []
for i in range(0,n_theta):
tmp = theta_start + i*(theta_end - theta_start)/(n_theta - 1)
theta_1.append(tmp)
theta_2.append(tmp)
for T1 in theta_1:
for T2 in theta_2:
# Link 1 & Link 2 connector
x1 = l1*math.cos(T1)
y1 = l1*math.sin(T1)
# Coordinates of manipulator
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,3])
plt.ylim([0,3])
plt.savefig(filename)
OUTPUT:
Upon executing the given code, it will generate 100 plots as the program was inputted to have 10 values between `0°-90°` and due to iterating it for two times for two different angles.
Animation can be viewed by visiting the link mentioned below.
https://drive.google.com/file/d/1G6ForQnJIBDKXnO6GiyFsse2GIvOct6c/view?usp=sharing
CONCLUSION:
A simulation of the forward kinematics of a 2R Robotic Arm in 2D workspace was created using PYTHON program.