Week 2- 2R Robotic Arm Challenge
1.OBJECTIVE : forward kinematic of a 2D robotic arm
code :
clear all
close all
clc
%inputs
L1=1;
L2=0.5;
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
ct=1;
%for loop
for i= 1:length(theta1)
THETA1=theta1(i);
for j=1:length(theta2)
THETA2=theta2(j);
%coordinates
x0 = 0;
y0 = 0;
x1 = L1*cosd(THETA1);
y1 = L1*sind(THETA1);
x2 = x1+L2*cosd(THETA2);
y2 = y1+L2*sind(THETA2);
%plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
axis([-0.5 2 0 2])
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)
RESULT :https://drive.google.com/file/d/1-yC61uqzXhPPoU08cMWQdmr4Ce3otZ9K/view?usp=sharing
EXPLANATION :
code :
1.clear all - it is used to remove all the variables from the current workspace,clearing from them from system memory.
2.close all - deletes all the figures whose handles are not hidden.
3.clc - it is used to clear the command window.
4.inputs- it includes the variables such as L1, L2 , theta 1 & theta 2.
5.Then ct is set to 1.
6. A nested for loop is used in which 'i' is iterated from from 1 to the length of theta 1 & 'j' is iterated from 1 to the length of theta 2.
7.then the coordinates are assigned to xo, x1, x2, y0, y1 & y2 .
8.plot - plotting is used to plot the graph for x0,x1,x2,y0,y1 & y2 with the linewidth of 3.
9. getframe commant is used to saved the figures in the array 'M'.
10.movie(M) is used to create a videofile with the help of VideoWriter commant in AVI format.
11. openvideo command is used to open the file, closevideo command is used to close the file.
output :
This plot shows the animation of 2D robotic arm.
the arm with some length are given with theta 1 & theta 2. With the help of nested for loop, i and j will be iterated with the given length & with the given angle of theta 1 & theta 2.
so by using pause(0.03) the given animation is presented exactly as the robotic arm.