Week 2- 2R Robotic Arm Challenge
youtube link
google drive link
https://drive.google.com/file/d/1Cy_skaW-eSeUVsOmGu8DKSnu1hJSt5Mw/view?usp=sharing
close all
clear all
clc
l1=1;
l2=0.5;
theta1= linspace(0,90,10);
theta2= linspace(0,90,10);
ct=1;
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
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.1 1.5 0 1.5])
pause(0.1)
M(ct)= getframe(gcf);
ct=ct+1;
end
end
movie(M)
videofile= VideoWriter('forword_kinamatics_using_for_loop.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)
l1=1 is the lenght of link 1
l2= 0.5 lenght of link 2
theta1and theta2 are array of angle of link1 and link 2
i = 1:length(theta1) is an array. values of i starts from 1 to the length of theta1 i.e the output is 1 3 4 5 6 7 8 910
THETA1 = theta1(i); this line states that the value of THITA1 is the value of angle thita1 which changes from 0 to 90 degree
the output of the first for loop will be the change in angle of link 1 from 0 to 90 degree
for every change in angle of link1 the link2 have to change from 0 to 90 degree so that we put the the for loop of link2 inside the loop of link1
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
then we write the program for chnging the position of links with respect to change in the angle of THETA1 and THETA2
x0 = 0;
y0 = 0;
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
x2 = x1 + l2*cosd(THETA2);
y2 = y1 + l2*sind(THETA2);
plot the graph of link1 and link2 with the help of plot command
all the co_ordinates of link1 and link2 are put in single plot commad to avoid the overlapping of combination of link1 and link2 and also get the all combnations in single plot
then we write the limitis of x and y axis with the help of axis command. pause command is also use slow dowen the operation of every loop
axis([-0.1 1.5 0 1.5])
pause(0.1)
then westore the each frame in an array called M by using getframe(gcf)
M(ct)= getframe(gcf);
create a video file and save it in avi formate of each frame stored in an array M
movie(M)
there are 4 steps to creat a video file
1. give name to the file and formate of the video
videofile= VideoWriter('forword_kinamatics_using_for_loop.avi','Uncompressed AVI')
2. open the video file
open(videofile)
3. read/write the video file
writeVideo(videofile,M)
4. close the video file
close(videofile)