Week 2- 2R Robotic Arm Challenge
Robotic arm challenge
To create path of robitic arm first we need to define its coordinates and input according to link So,
Link 1 Length = 2 metres, Link 2 length = 1 metres (hyprotheoretically), theta1(angle with link 1)= 0-180 degree, theta2( angle with link2 )=0-180degree as we multiple uniform angular data we use linspce command which allow us to get different data set of angle with uniforn spacing eg theta 1 = linspace(0,180,10)( here first digit'0' shows base value and second digit,'180' shows last value and last digit '10' shows no. of uniform intervals from 0 to 180 degree)
First step entering data in loop
Our Main aim here is to create data for different angle for link 1&2 simultaneously . Which means for single position of link 1( eg 45 degree) we require 10 different angle positions data for link 2 according to code below.
We achieve this by using 'for' loop for theta 1 and then inside 'for' loop we create another 'for' loop for differnt set of angluar data for link 2. Which gives link 2 10 different angular movement for link 2 at single angle of link 1.
Next is we assign coordinate data for x0,x1,x2,y2,y1&y0. mentioned in codes
for Link 1 x0 & y0= 0 , x1= Link1 length * cos(theta1) & y1=Link1 * sin(theta1) for link 2 = x1 & y1 are base coordinates but it already has assigned values( not zero) so x2 = x1 + Link 2 length*cos(theta2) & similar way for y2.
Next we plot and create video
Using plot command for all coordinates accordingly as shown in attached code. But here we need video output so we enter 'ct'= 1 as input ( ct= every frame of data) and at end we use ct= ct+1 so every frame is stored as data. to complile it to video we use 'M' command and call everyframe by M(ct) command after that at end of data we use movie(M) command so we compile those framework into video then we assign video name and write the video and save the data as shown in attached code.
Output
Error faced & solution

As shown in picture plot was not running the command because in line 29 i entered y2= y1+ L2*sind(theta2) but as in code data should be given by "y2= y1+ L2*sind(Theta2)". after correcting the error the code ran smoothely.
close all
clear all
clc
% Robotic Arm challenge 2-D
% Input(eg. lenghth of link 1 &2 and coordinates & angles theta)
L1= 2
L2= 1
theta1=linspace(0,180,10);
theta2=linspace(0,180,10);
% using for loop for different set of data
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',2)
axis([-3 3 0 3])
grid on
pause(0.1)
M(ct)= getframe(gcf);
ct=ct+1;
end
end
movie(M)
videofile = VideoWriter('Robotic_challenge2d.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)