2R Robotic Arm Simulation
Objective:
To simulate the forward kinematics of a 2R Robotic arm using Python & ImageMagick
Problem Statement:
Tracing the path of the robotic arm ensuring that it moves in the desired trajectory
Solution Procedure:
A python program has been made defining the values of the lengths of both the links of the robotic arms and the minimum and maximum values of the angles the links make with the horizontal.
Then, we append the values of each angle the links make with the horizontal. And then, we calculate the co-ordinates of the start and end points of both the links of the robotic arm using the nested loop concept.
Afterthat, using the commands from matplotlib module, I have plotted the positions of the arm on line graphs and saved them as image files.
Now, the final step is to convert the images into a video file to analyse the trajectory and for that, I have used the Imagemagick software. Using the magick -delay 5 *.png forward_kinematics.mp4 command on CMD, the final video has been created. The detailed code is given below.
import math
import matplotlib.pyplot as plt
#length of Link 1 of Robotic Arm
l1=1
#length of Link 2 of Robotic Arm
l2=0.5
#The minimum value of the angle a link makes with the horizontal
theta_start=0
#The maximum value of the angle a link makes with the horizontal
theta_end=math.pi/2
#define an empty list in which we can later store the values of angles the link 1 makes with the horizontal
theta1=[]
#x co-ordinate of the start of Link 1
x0=0
#y co-ordinate of the start of Link 1
y0=0
#a counter variable required for filename saving later on
ct=1
#no of values of theta1 and theta2 required
n=11
#a for loop to save the values of angles for both theta1 and theta2
for i in range(0,n):
temp=theta_start + i*(theta_end-theta_start)/(n-1)
theta1.append(temp)
#list in which the values of angles the link 2 makes with the horizontal is stored
theta2=theta1
#nested loop used for incrementing the position of link 2 for a certain position of link 1
for t1 in theta1:
for t2 in theta2:
#x co-ordinate of the end of Link 1/start of link 2
x1=l1*math.cos(t1)
#y co-ordinate of the end of Link 1/start of link 2
y1=l1*math.sin(t1)
#x co-ordinate of the end of Link 2
x2=x1+l2*math.cos(t2)
#y co-ordinate of the end of link 2
y2=y1+l2*math.sin(t2)
#defining the filename format for saving
ct=ct+1
filename= 'output%05d.png'%ct
"""
saving the entire 11*11=122 images for every incremental position of the robotic arm
while constraining the range of the graph to 2 units both in x and y direction
"""
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)
Results and Discussion:
As per the video simulation of the forward kinematics of the 2R Robotic arm, it has been found that the arm moved as per the desired trajectory
Here is the video for this simulation: