close all
clear all
clc
% Program to design a 2R Robotic Arm to determine it's workspace
% Given Data:
x=0; % 'x' co-ordinate for initial position of arm
y=0; % 'y' co-ordinate for initial position of arm
L1=10; % Length 'L1' for robotic arm
L2=5; % Length 'L2' for manipulator arm
a1=linspace(0,90,10); % Angle 'a1' for position of 1st arm
a2=linspace(0,90,10); % Angle 'a2' for position of manipulator arm
ct=1;
% For every varying position of 'a1' there is 'a2' that varies until completion
% and thereafter only which 'a1' is incremented to the next value until it
% gets terminated. For this purpose, 2 'FOR' loops shall be implemented and
% the new values of 'a1','a2' will be 'A1' & 'A2'.
for i=1:length(a1)
A1=a1(i);
for j=1:length(a2)
A2=a2(j);
% Step 1 - Calculating the coordinates of x1,y1
x1 = L1*cosd(A1)
y1 = L1*sind(A1)
% Step 2 - Calculating the coordinates of x2,y2
x2 = x1 + L2*cosd(A2)
y2 = y1 + L2*sind(A2)
% Step - 3 - Plotting the figure
plot([x,x1], [y,y1], [x1,x2], [y1,y2],'linewidth', 3)
axis([-1 20 -1 20])
xlabel('X-Axis')
ylabel('Y-Axis')
title('2R Robotic Arm')
pause(0.05)
% Step - 4 - Now, collect individual frames of the plotted graph and
% store it into a movie vector 'M' so that the
% movie vector 'M' can be indexed later.
M(ct)=getframe(gcf);
ct=ct+1;
end
end
% Step - 5 - Saving the movie file and updating the data onto the file
% using the movie vector 'M'
robotvideo = VideoWriter('2R Robotic Arm');
open(robotvideo);
writeVideo(robotvideo,M);
close(robotvideo);
% SOLUTION FOR THE ERROR VIDEOS ATTACHED:
% Error Video-1 :
% How the error was made?
% In 'Step-3- Plotting the Figure' using the commands below :
% plot([x,x1], [y,y1], 'linewidth', 3)
% plot([x1,x2], [y1,y2], 'linewidth', 3)
% How was the error resolved?
% Using 'hold on' function which attaches the plots together and the
% resultant code would look like this -
% hold on
% plot([x,x1], [y,y1], 'linewidth', 3)
% plot([x1,x2], [y1,y2], 'linewidth', 3)
% Error Video-2 :
% How the error was made?
% In 'Step-3- Plotting the Figure' using the commands below :
% hold on
% plot([x,x1], [y,y1], 'linewidth', 3)
% plot([x1,x2], [y1,y2], 'linewidth', 3)
% How was the error resolved?
% By removing the 'hold on' fumction and just using a simgle 'plot'
% function to plot the values of [x,y], [x1,y1] & [x2,y2]
% plot([x,x1], [y,y1], [x1,x2], [y1,y2],'linewidth', 3)
% This final error-2 was resolved and the resultant output is shown
% in the video file named as '2R Robotic Arm'.