Week 2- 2R Robotic Arm Challenge
close all
clear all
clc
% inputs
l1=1.5;
l2=0.75;
t1=linspace (0,90,10);
t2=linspace (0,90,10);
ct=1;
for i=1:length(t1)
T1=t1(i);
for j=1:length(t2)
T2=t2(j);
x0=0;
y0=0;
x1=l1 *cosd(T1);
y1=l1 *sind(T1);
x2=x1+l2*cosd(T2);
y2=y1+l2*sind(T2);
%plotting
plot([x0,x1],[y0,y1],[x1,x2],[y1,y2],LineWidth=4)
axis([-0.1 2.5 0 2.5])
pause(0.02)
M(ct)=getframe(gcf);
ct=ct+1;
end
end
movie(M)
vd=VideoWriter('f_k.avi','Uncompressed AVI');
open(vd)
writeVideo(vd,M)
close (vd)
Code explanation
Line (1-3) the commands are used for closing and clearing the previous data which might be stored in the software due to previous functions performed on it.
clc- will clear the screen and gives you empty window to write codes.
Line(5-9) these lines are used for assigning the varieables realated to Questions
l1- Length of the link 1
l2- Length of the link 2
t1- thetha for the link 1, here we took the linspace command for taking no. of different values of thetha.it will give 10 different values b/w 0-90.
t2- thetha for the link 2
line (12 & 14) here we are taking FOR loop for calling a function no. of times.
i=1:Length(t1)- it means the value of i is changing from 1 t0 t1.
similarly we have taken one more FOR LOOP as j=1:length(t2)
i & j are called loop counters they represent how many times the FOR LOOP is executing.
line (13 & 15) here we are assigning the values of i & j to a new variable T1 & T2 and these new values are used for calculation in position of links
line(16-21) these are the formulas for the links to provide them desired rotation.
line (25) here we are starting to plot the desired output from the above program
we have taken a single plot statement for plotting. the respective values are provided in the statement along with line width of 4,
line (26) we are taking a viewing gallery for watching here we are giving the x and y limits in the plot.
Line (28) we are giving the pause in running the program so that we can get clear view.
line (11 & 30) in line 11 we are giving the frame coount as 1
in line 30 we are increasing the frame by +1 for each time it executes in for loop.
line(29) is for creating the movie of ct {M =ct} for creating a movie we are taking the figure window which is generated after plot statement ie {getframe(gcf)} gcf represents figure window.
line (32 & 33) here we are closing the FOR LOOPs
line 34-38 we are calling our movie(M) giving name to it and speciffying type of file to it, write video will create an anime. then we are closing the movie
END RESULTS
as per the plot statement the program is creating the plot
then it is creating a movie.
vidoe link -https://youtu.be/94qaKIToWXA