Week 2- 2R Robotic Arm Challenge
%robotic arm in animated view
%inputs
l1 = 0.25;
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('robotic_arm.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)
explaination of the code
1.first we have to take l1 and l2 valves for robotic arm length
2.theta1 and theta2 valves are taken for angles between 0 and 90 so that i have used "linspace" command for interval of 10 valves
3.i have taken for loop for generating automatic valves instead of manual valves THETA1 and THETA2 are two variables
4.i have taken co-ordinates of x0 and y0 as zero initial valves and x1=l1*cosd(THETA1) and y1 = l1*sind(THETA1)
5. x2 and y2 valves as x1+l2*cosd(THETA2) and y1+l2*sind(THETA2)
6.ct refers to count frames from one to another so i have used ct command
7.Then i have done plotting command to plot the coordinates and M(ct) for creation of movie
8.movie(M) command used to give the video title in AVI format and uncompressed avi and open command for starting the videofile and writevideo command to write the video and close command to close the video
ERRORS:
1.firstly i came across many syntax errors instead of x1 i writes y1 and later sort it using command window
2.in for loop command i made a mistake that i have written the values down the for command it shows me error in command window


youtube video link:
https://youtu.be/4Wjkf_1rwfo