clear all
close all
clc
% codes for 2R Robotic arm aniamtion
% The arm consist of two links.One end of first link(l1) isconnected to base and other end is connceted to second link(l2)
% second link is connceted to manipulator or tool
% inputs
%length of first link l1 in m
l1=1;
%length of second link l2 in m
l2=0.5;
% first link makes an angle 'theta1' with respect to x-axis
% second link makes an angle 'theta2' with respect to x-axis
% coordinates
% x0=0;
% y0=0;
% x1=l1*cosd(THETA1);
% y1=l1*sind(THETA1);
% x2=x1+l2*cosd(THETA2);
% y2=y1+l2*sind(THETA2);
%
% for every value of theta1 ,the value of theta2 is also changes
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
% Animation
% for each positon of first link ,the second link takes multiple positions so the movement of first link and second link with respect to each other are creating using for loop
% counter 'ct'
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);
% ploting
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
% video creation ,writing and saving
% 'movie(M)' for creating movie in matlab
movie(M)
% video file creation and video writing
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
% Error faced during the challenge
% error in animation due to the placement of increament of ct=ct+1
% step taken to overcome the error
% changed the position of increament of ct=ct+1 such that it comes after getframe command
% youtube link https://youtu.be/XMFu91XX1-M