Week 3.2 - 2R Robotic Arm Challenge
clear all
close all
clc
%Inputs
l1=1;
l2=0.5;
theta1 = linspace(0,90,15);
theta2 = linspace(0,90,15);
ct=1;
for i=1:length(theta1)
THETA1 = theta1(i);
for j=1:length(theta2)
THETA2 = theta2(j);
x0=0;
y0=0;
x1=0+l1*cosd(THETA1);
y1=0+l1*sind(THETA1);
x2=x1+l2*cosd(THETA2);
y2=y1+l2*sind(THETA2);
%Plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',4)
axis([-0.5 1.5 0 1.5])
pause(0.03)
M(ct)=getframe(gcf);
ct=ct+1;
end
end
movie (M)
videofile= VideoWriter('forward_kinematics.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Aim:
To write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm.
Equations:
There are some simple formulaes , which can easily describe the link functions of X1, X2,Y1,Y2
X1=0+l1*cosd(THETA1)
Y1=0+l1*sind(THETA1)
X2=0+l2*cosd(THETA2)
Y2=0+l2*sind(THETA2)
Here,
X1 and Y1 are the link from the starting point.
X2 and Y2 are the link from the X1 and Y1.
Objectives:
The main objective of this function is to simulate a Robotic Arm in a MATLAB using Forward Kinematics.
Explanation:
MATLAB is the language used here to do this function
The function starts with the basic instructions as:
Clear all
Close all
Clc
Header is given as Inputs
The 6th and 7th line describes the length of the Links as 1m and 0.5m
The 9th and 10th line describes the value of the theta1 and theta2 values with the linspace command from 0 to 90 with 10 intervals.
The 12th line shows the count as 1
The 14th line shows the for loop with the 'i' value as 1*length of theta1,where the THETA values as theta1(i)
Meanwhile, The 16th line shows the j value with again a for loop.
The 18 and 19 line shows the values of X0 and Y0.
The 21 and 22 line shows the values of X1 as 0+l1*cosd(THETA1) ,
Y1 as 0+l1*sind(THETA1).
The 24 and 25 line shows the values of X2 as X1+l2*cosd(THETA2) , Y2
as Y1+l2*sind(THETA2).
Again the header is given as Plotting
The 29th line shows the plot with the points with the linewidth of 4
The 30th line shows the X and Y axis starting and ending points.
The 31st line gives the pause command with the value of 0.03sec
The 32nd line gives the M(ct) command which is used for getting th frame as output
The 33rd line gives the command of Counter value as Counter+1
The 34th line shows the end command of the second opened for loop , Meanwhile 35 line is for giving the end command of first opened for loop
And, for showing the output as video the movie command is used in 37th line
Videofile is opened as Videowriter in forward kinematics.avi, uncompressed AVI
For displaying the output the open and write command is used on 39th and 40th line
Close command is given for closing the output in 41st line.