% forward Kinematic with animation
%input
clear all
close all
clc
% Inputs
l1 = 1.0; % link of 1st arm
l2 = 0.5; % Link of 2nd arm
ct = 1; % counter
theta1 = linspace(0,90,4); % Different angle of theta1 and angle limited 4 to reduce file size
theta2 = linspace(0,90,4); % Different angle of theta2
for i = 1:length(theta1) % for loop for 1st arm
THETA1 =theta1(i); % For every angle of lower theta1 is stored in cap THETA1
for j = 1:length(theta2) % for Loop for 2nd Arm
THETA2 =theta2(j);% For every angle of lower theta2 is stored in cap THETA2
x = 0; % Initial x coordinate
y = 0; % Initial y coordinate
x1 = cosd(THETA1)*l1; % x1 is derived by basic trignometry formula
y1 = sind(THETA1)*l1; % y1 is derived by basic trignometry formula
x2 = x1+cosd(THETA2)*l2; % x2 is calucated based on x1+l2
y2 = y1+sind(THETA2)*l2; % y2 is calucated based on y1+l2
%plotting
plot([x x1],[y,y1],[x1 x2],[y1 y2],LineWidth=3)
grid on
axis([-0.1 1.6 0.1 1.6]); % axis set
pause(0.3);
M(ct)=getframe(gcf); % getframe save the figure generated by plot and stored in M
ct =ct +1 % counter is increased by one
end
end
% Creating Movie
movie(M)
videofile = VideoWriter('FK_Animation','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)