2R robotics arm simulator using Python
- Aim :
The aim of the project is to simulate the forward kinematics of a 2R Robotic Arm.
- OBJECTIVE:
The robot consists of two arms(2R).The arm of the robot is in kinematic state which is about to move around an angle of 0degrees to 180degrees.
- Governing equations
- Position of link 1 is calculated by using 2 end Coordinates i.e. at base & end link 1
(x0,y0) = (0,0)
(x1,y1) = (l1*cos(θ1), l1*sin(θ1))
- Position of link 2 is calculated by using the arm manipulator end using
(x2,y2) = (x1 + l2*cos(θ2), y1 + l2*sin(θ2))
- Theory :
A robotic arm is a type of mechanical arm, usually programmable. 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 (linear) 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. An end effector is the device at the end of a robotic arm, designed to interact with the environment.
The kinematic analysis is the relationships between the positions, velocities, and accelerations of the links of a manipulator. The kinematics separate in two types, direct kinematics and inverse kinemtics.
In forward kinematics, the length of each link and the angle of each joint is
given and we have to calculate the position of any point in the work volume of the
robot.
PYTHON CODE
# program forforword kinematics of 2R robotic arm
import math
import matplotlib.pyplot as plt
#inputs
#defining the set of values for angles
n_theta=10
# starting and ending of theta
theta_start=0
theta_end=math.pi/2
# length of two robotic arm
l1=1
l2=0.5
# calculating both theta1 and theta2
theta1=[]
theta2=[]
for i in range(0,n_theta):
temp=theta_start + i*(theta_end-theta_start)/(n_theta-1)
theta1.append(temp)
theta2.append(temp)
# calculating coordinates for two robotic arms
x0=0
y0=0
ct=1
for t1 in theta1:
#end point of link 1
x1=l1*math.cos(t1)
y1=l1*math.sin(t1)
for t2 in theta2:
#end point of theta 2
x2=x1+l2*math.sin(t2)
y2=y1+l2*math.sin(t2)
# creating file for saving plots
filename=str(ct)+'.png'
ct=ct+1
# plotting the coordinates
plt.figure()
plt.plot([x0,x1],[y0,y1])
plt.plot([x1,x2],[y1,y2])
plt.legend(['arm','maupilator'])
plt.title('robotic arm')
plt.xlim([0,2])
plt.ylim([0,2])
# saving all plots
plt.savefig(filename)
code explanation:
The matplotlib, math, and numpy modules were importing required libraries were # is refered as comments. In this project, we create a two arm robotic simulator. This robot has two arm of different length (l1and l2). Then we choose the total number of theta1 and theta2 for simulation. In this program I choose 10 values for both theta1 and theta2.which is represented by n_theta. For each values of theta1 we get 10 values of theta2. So we get 100 combinations. Then calculating the three coordinates for 100 combinations by using the below formula, first_coordinate: x0=0 and y0=0 for all the 100 combinations, second_coordinate: x1=l1*math.cos(t1) and y1=l1*math.sin(t1), and third coordinate: x2=x1+l2*math.cos(t2) and y2=y1+l2*math.sin(t2). Here l1 and l2 be the length of arms and t1 and t2 be the theta values. ct stands for counter, which here in this program it refers to the 1st iteration of inputs ct=1, ct=ct+1 at the end supports the next set of iterations untill the last to simulate. The for loop has defined to support the iterations ie; for every value in the limits defined an temporary value is calculated and the same is made to store in the array using append comand.For 100 combinations we use for loop as shown in the program. Then plot all the coordinates for all 100 combinations in separate figure. So we get 100 plots plt.xlim & plt.ylim is used to define the limiting values on both axis of the graph to have a simulation well within the frame.Then save the frames with already defined filename
plot:
For the better understanding of the simulation please refer to the video link provided below
- CONCLUSION:
Thus simulation of the forward kinematics of a 2R Robotic Arm using python and animation are also done. We can observe the movement of link1 and link2 in the first quadrant.This can be usefull for understanding the workspace covered by two arm robotic systemWe can observe the movement of link1 and link2 in the first quadrant.This can be usefull for understanding the workspace covered by two arm robotic system