Week 1 - 2R Robotic Arm Simulator on Python
AIM : To write a program to simulate the forward kinematics of a 2R Robotic Arm in Python .
OBJECTIVE :
- To solve and simulate the forward kinematics of a 2R Robotic Arm.
- To create the animation of working of a 2R Robotic Arm.
INTRODUCTION : A robotic arm is a robot manipulator, usually programmable, with similar functions to a human arm. The links of such a manipulator are connected by joints allowing either rotational motion (such as in an articulated robot) or translational (linear) displacement. The links of the manipulator can be considered to form a kinematic chain. The use of industrial robots is increasing in areas such as food, consumer goods, wood, plastics and electronics, but is still mostly concentrated in the automotive industry.
(i)
In the image shown above, the robotic arm consists of 4 components,
- The Base, which is clamped to the surface and all other links are joined through hinge joint.
- Link 1 (l1) making `theta 1` with horizontal.
- Link 2 (l2) making `theta 2` with horizontal.
- The device attached to the manipulator which interacts with its environment to perform tasks is called the end-effector.
SOLUTION STEPS :
- For our program we have assumed the length of link 1 and link 2 to 1 m and 0.5 m.
- In order to simulate the robotic arm it is necessary to vary `theta 1 and theta 2` to obtain a desired animation and it cannot be possible if we manually enter the respective data everytime. So we have created an array from `0°-90°` with 10 evenly spaced points and stored `theta 1 and theta 2` as `theta_(Start) and theta_(end)` between them and a loop counter is initiated from 1.
- The coordinates of base, i.e., is assumed to be at origin `( 0,0)` and the initial value of `theta 1 and theta 2` array is null. Then a for loop is executed with a range of 0 to 10 and each value of the loop is temporarily stored in a separate variable.
- Another for loop is executed which stores each values obtained from previous one and dumps into the trigonometric relation for simulating different values of angles and the loop counter increases by one for each iterations.
- For plotting graph 'plt.plot' command is used with 'plt.figure' and 'plt.lim' to set the axis and connector in a desired way.
- The coordinates of end points of link 1 (l1) can be found by using trignometry as,
`x_1 = l1*cos(theta1)` and `y_1 = l1*sin(theta1)`
Similarly, the coordinates of end point of link 2 (L2) can also be found from trignometry as,
`x_2 = x_1 + l2*cos(theta2)` and `y_2 = y_1 + l2*sin(theta2)`
BODY OF THE CONTENT :
Python Code -
# A program to create simulation of 2R robotic arm manipulator
import math
import matplotlib.pyplot as plt
# Inputs
l1 = 1
l2 = 0.5
x0 = 0
y0 = 0
n_theta = 10
theta_start = 0
theta_end = math.pi/2
counter = 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 = str(counter) + '.png'
counter = counter + 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)
RESULTS :
- 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 . The following plot is obtained as one of the output:
- The following is the animation of the simulation of 2R robotic arm :
Link : https://youtu.be/u4Ye_CEOWoo
REFERENCES :
- Image (i) is obtained from google image of Skill Lync page.