Week 2- 2R Robotic Arm Challenge
%a program to simulate the forward kinematics of a 2R Robotic Arm
%input
l1=1;
l2=0.5;
theta1=45;
theta2=55;
%coordinates
x0=0;
y0=0;
x1=l1*cosd(theta1);
y1=l1*sind(theta1);
x2=x1+l2*cosd(theta2);
y2=y1+l2*sind(theta2);
%plotting
line([x0 x1],[y0 y1],'linewidth',2,'color','r')
line([x1 x2],[y1 y2],'linewidth',2,'color','b')

- step1:- our first step is to calculate the position of link1
- step2:- is to calculate the position of link2
in the programming point of view we will see how to calculate
- step1:-in this step we have to give the values of L1,L2,`theta1`,theta2
- step2:- in this step we can give the coordinates as x0,x1,x2 and y0,y1,y2
- step3:- let x0=0,y0=0
- step4:-let x1=L1*cosd(theta1),and y1=L1*sind(theta1)
- step5:- letx2=x1+L2*cosd(theta2),and y2=y1+L2*sind(theta2)
- step6:- using plotting command
- step7:- using line command "line([x0 x1],[y0 y1],with a linewidth of 2 and in red color)"
- step8:- simillarly using the line command for "line([x1 x2],[y1 y2],with a linewidth of 2 and in blue color)"

error:- in the above screen shot i got an error in line number 21 and 22 because i used close parantheses after y1and y2
%a program to simulate the forward kinematics of a 2r robotic arm with an animation plot
%input
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.03)
M(ct)=getframe(gcf);
ct = ct+1;
end
end
movie(M)
videofile=VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

error:-
here in the above screenshot i got an error in line 36 there i have used open parentheses
error:-
here in the above screen shot i got an error in line number 29 instead of gcf i have used gfc
here in the above screen shot i got an error in line number 35 and 37 instead of capital V,capital W and capital U ,i have used small alphabets

to make animation plot and to make a video
we can use this command
movie(M)
videofile=VideoWriter('forward_kinematics.avi,'Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
The below link contains the video which is uploded in the drive
https://drive.google.com/file/d/1XcqvdkGckXUtldlb_jemTH04QHsZqcIi/view?usp=sharing