Week 2- 2R Robotic Arm Challenge
youtube link of avi: https://youtu.be/qFA8VeoreJQ
drive link: https://drive.google.com/file/d/1nixh6_PewpxkL9eSgBSH6FaoVc3xmhqg/view?usp=sharing
full program
%animatiom by for loop movie a robotic arm
clear all
close all
clc
%input
k1=0.5;
k2=1;
theta1=linspace (0,90,5);
theta2=linspace (0,90,12);
ct=1;
for i=1:length(theta1)
THETA1=theta1(i);
for j=1:length(theta2)
THETA2=theta2(j);
x0=0;
y0=0;
x1=k1*cosd(THETA1);
y1=k1*sind(THETA1);
x2=x1+k2*cosd(THETA2);
y2=y1+k2*sind(THETA2);
%ploting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',7)
axis([-0.1 1.5 0 2])
pause(0.2)
M(ct)=getframe(gcf);
ct=ct+1;
end
end
movie(M)
videofile=VideoWriter('roboticarm.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

length 1 and 2 is k1 and k2
0-90degree 5 and 12 values in between them

counter command we use it for loop
for loops 1)as i for the length k1 2) as j for the length k2
x,y strts from 0 degree as initial value with the formula resp.

After the formula we have plot the graph as we need all the line in the same graph we use plot command insted of line command,
demanding axis of x to bev -0.1 to 1.5 and y to be 0 to 2 and pause of 0.2 frame
saving/getting the frame that we executed to an array M
counter +1 for the for loops to continue till 90degree as given for this program
end command to stop the for loop commands
Till now we made the frame as required for the solution and called it in an array now Movie time...

command movie matlab genetrate a movie of array M for this program,give the destination as avi format in uncompressed form
then open that file and write / save the array in avi format a video/movie and close the file
Errors while executing the programs:
couter after for loop so the j file was not running so had to put the counter before the end of the loop
as the first file was not saved

axis command was invalid until the [ x x y y] was in () as the funtion calls it so was made porper after some iterations.
Finally the program of robotic arm was successfuly executed.