Week 2- 2R Robotic Arm Challenge
AIM: To simulate the Forward Kinematics of a 2R Robotic Arm using MATLAB program.
Theory:
1.A robotic arm is a type of a mechanical arm, usually programmable,with similar functions to a human arm. The arm may be the sum total of the mechanism (or) may be the part of a more complex robot. The links of such a manipulator are connected by joints allowing either rotational motion (or) translational displacement.
2.The links of the manipulator can be considered to form a kinematic chain. The terminus of the kinematic chain of the manipulator is called the end effector and it is analogous to the human hand.
3.Forward kinematics refers to the use of kinematics equations of a robot to compute the position of the end-efffector from specified values for the joint parameters.
4.Robotic arms are used in variouus industrial applications such as drilling,welding,metal cutting,painting etc...

5.The link-1 is attached to the base and end of the link one is connected to link-2. End of link-2 is connected to the end effector which performs the desired operation.
6.In this challenge we will restrict the movement of the links in 2-D palne.
PROGRAM:
clear all
close all
clc
% Taking Inputs
% Length of link-1(L1) and link-2(L2) in meter
L1 = 1;
L2 = 0.5;
% Angle traced by Link-1 in degrees (theta1)
theta1 = linspace(0,90,10);
% Angle traced by Link-2 in degrees (theta2)
theta2 = linspace(0,90,20);
% Initialising base coordinates of Link-1
x_0 = 0;
y_0 = 0;
ct = 1;
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
% calculating the coordinates of end point of link-1
x_1 = x_0+L1*cosd(THETA1);
y_1 = y_0+L1*sind(THETA1);
% calculating the coordinates of the end point of link-2
x_2 = x_1+L2*cosd(THETA2);
y_2 = y_1+L2*sind(THETA2);
% Ploting
plot([x_0 x_1], [y_0 y_1], [x_1 x_2], [y_1 y_2], 'linewidth',3);
axis([-0.1 1.5 0.1 1.5]);
pause(0.03);
% Capturing the current plot to combine later
M(ct) = getframe(gcf);
ct = ct+1;
end
end
% Making movie from collected frames
movie(M)
% creating a video file of '.avi' format to save the animation
videofile = VideoWriter('Forward_kinematics_of_2R_Robotic_arm.avi','Uncompressed AVI');
open(videofile);
%writing the movie in the videofile created
writeVideo(videofile, M);
close(videofile);
EXPLANATION OF THE PROGRAM:
1.Length of both the links are taken as input. Length of link-1(L1) is taken as 1m and length of link-2(L2) is taken as 0.5m.
2.Angles traced by both the links, for link-1 and link-2 is taken as input. The angles are traced are varied over a range to simulate the movement of the robotic arm.
3.Base position of link-1(x0,y0) is considered as origin (0,0).
4.Then two for loops are used to iterate over the range of angles traced by the both links.
5.For each particular angle of link-1 and link-2 is moved over its entire range, to obtain different positions of end effector at that angel of link-1.
6.For a particular value of `theta1` and `theta2`, the end position of link-1 is calculated by these equations:
x1 = x0+L1*cosd(`theta1`)
y1 = y0+L1*sind(`theta1`)
7. The end position of link-1 is also the start position of link two. The end position for link-2 is calculated by these equations:
x2 = x1+L2*cosd(`theta2`)
y2 = y1+L2*sind(`theta2`)
8.Then for each particular position of link-1 and link-2,a plot is made which is then captured frame by frame to make a movie.
9.The movie is then written into the videofile and the final animation is created.
Mistakes Made & Rectified:

In this step i made a typo error and i rectifie it by seeing the error shown in command window.

In this step instead of smallcase x i used uppercase x. Error shown is command window by seen this i rectifie my mistake.

In this step i forget to declare theta2. Error rectified using command window.
OUTPUT:
The output is obtained in form of an animated video clip. This animation can be viewed by visiting the link mentioned below.
CONCLUSION:
A simulation of the forward kinematics of a 2R Robotic Arm in 2D workspace was created using MATLAB program.