Week 2- 2R Robotic Arm Challenge
MATLAB PROGRAM:
% A Matlab program to simulate the forward kinematics of a 2R robotic arm and to visualize the arm motion.
clear all
close all
clc
% Inputs for the Program:
%length of Link 1 in meters (L1):
L1 = 1;
%length of Link 2 in meters (L2):
L2 = 0.25;
% Angle made by Link 1 with vertical axis in degree is Theta_1
Theta_1 = linspace (0,90,15);
% Angle made by Link 2 in degree is Theta_2
Theta_2 = linspace (0,90,25);
ct = 1;
% Tracing the movement of link 1 and link 2 by iterating the value of Theta_1 and Theta_2, respectively.
for i = 1: length (Theta_1)
THETA_1 = Theta_1 (i);
for j = 1: length (Theta_2)
THETA_2 = Theta_2(j);
% Suppose the initial points for link 1 is (x0,y0).
x0 = 0;
y0 = 0;
% Calculating end points of link 1.
x1 = x0+L1*cosd(THETA_1);
y1 = y0+L1*sind(THETA_1);
% Calculating end points of link 2.
% End points for link 1 is starting point for link 2.
x2 = x1+L2*cosd(THETA_2);
y2 = y1+L2*sind(THETA_2);
% Ploting Robotic arm movement.
plot ([x0 x1],[y0 y1],[x1 x2],[y1 y2], 'LineWidth',3,'Color','b')
axis ([-0.1 1.5 0 1.5])
% Giving pause to the plot preview when shifting from one plot to another plot
pause (0.03)
% Storing Plot.
M(ct) = getframe (gcf);
% Increment in ct will help to create plot with multiple angles of link 1 and link 2 which will store in M.
ct = ct+1;
end
end
% Making movie combining simulated results.
movie(M)
% Making a video file of movie created in .avi format.
videofile = VideoWriter ('forward_kinematics_robotic_arm.avi','Uncompressed AVI');
open(videofile)
% Adding video to the video file created above.
writeVideo(videofile, M)
close (videofile)
ERROR FACED:
- Undefined Function. (as shown in figure 1.)

Figure 1: Error in Function Assigned.
The solution to Error:
- Basically, it was typing error where I have typed Theta instead of Theta_1 and was rectified by using the proper function.
Video file link:
https://drive.google.com/file/d/1siprDEkPX24iOZPeyq9Xt2EDI0xE4YTw/view?usp=sharing