%Program in Matlab to stimulate forward kinematics of 2R robotic arm
% To make an animation of 2R robotic arm
%Inputs
L1 = 2; % Length of Link1
L2 = 1; % Length of Link2
theta1 = linspace(0,90,10); %In degrees
theta2 = linspace(0,90,10); %In degrees
ct = 1;
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
%Coordinates
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 3.5 0 3.5])
pause(0.1)
M(ct) = getframe(gcf); % Gathering all the frames.
ct = ct+1;
end
end
movie(M) % Creating a movie.
videofile = VideoWriter('forward_kinematics_two.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
REPORT:-
AIM :- To make an animation of Forward Kinematics of 2R Robotic Arm in MATLAB.
WORKING :- 1. Mentioning the lenghts of 2 links and making an array of theta1 and
theta2, the angles of those links.
2. Running the 'for loop' for the array of two angles naming as THETA1 and
THETA2 while mentioning all the coordinates of 2 links.
3. While plotting we are acknowleging many plot frames one after another. To
make it in one frame we are using 'getframe' command while incrementing
the frames by using ct = ct+1.
4. Finally, we are creating a movie by using 'movie' command while creating a
video file.
5. https://youtu.be/bfoX-N4x8Bs. Here is the link of my video file that I
posted in youtube.
OUTPUT :- In the output video we are getting Link1 is travelling from 0deg to 90deg and
Link2 is travelling from 0deg to 90deg at each angle of Link1. For example, At
10deg of Link1, Link2 is rotating from 0 to 90deg then only Link1 is moving to
20deg..