Week 3.2 - 2R Robotic Arm Challenge
Aim:-
To write a program to simulate the Forward kinematics of a 2R Robotic arm.
Objective:-
- To solve and understand the behavior of Translatory or rotary movement of a 2R Robotic arm
- To simulate the manipulator in Matlab
- To create a Movie/Animation video of a 2R Robotic arm manipulator
Theory:-
A robotic arm is a type of mechanical arm, usually programmable, with similar functions to a human arm. The links of such a manipulator are connected by joints allowing either rotational motion or translational (linear) displacement.
A 2R robotic arm represents a robotic arm with two rotations. i.e. it has two links that rotate or work over a two-dimensional plane with each of the links having a single degree of freedom

If we are able to find out how the robotic arms move, we could specify the application of a robot. That is we can find out it's workspace (The possible location the robot can reach).
For a 2R Robotic Arm, there are two links and two rotational joints. Link 1 makes an angle θ1">θ1 with the x-axis and link 2 makes θ2">θ2 with the x-axis. Let's assume the link length to be l1 andl2">l1 and l2 respectively. First, we need to specify the position of the manipulator if θ1 and θ2 are given/known.

Input Parameters:-
l1 = length of the link-1 (Hinged or pivoted at base)
l2 = length of the link-2 (Jointed with link-1)
(x0,y0) = Starting point of link-1
(x1,y1) = End point of link-1/Starting point of link-2
(x2,y2) = End point of link-2
theta1 = Angle made by the link-1 with x-axis (Horizontal)
theta2 = Angle made by the link-2 with x-axis (Horizontal)
Program Code:-
% A Program for Forward Kinematics of a 2R Robotic arm sitmulator
clear all
close all
clc
l1 = 2; % Assuming length of link-1
l2 = 1; % Assuming length of link-2
% Set of angles for the movement of robotic arms
theta1=linspace(0,90,20);
theta2=linspace(0,90,20);
ct=1; % counter with starting value as 1
for i = 1:length(theta1) % Iterating i from 0 to 10 as theta1 has 10 values
THETA1 = theta1(i); % Storing iterated values of i in THETA1
for j = 1:length(theta2) % Iterating j from 0 to 10 as theta1 has 10 value
THETA2 = theta2(j); % Storing iterated values of J in THETA2
% Co-ordinates of staring points of first arm
x0 = 0;
y0 = 0;
% Co-ordinates of end point of 1st arm / Starting point of 2nd arm
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
% Co-ordinates of end point of 2nd arm
x2 = x1+l2*cosd(THETA2);
y2 = y1+l2*sind(THETA2);
% ploting
% co-ordinates of arms assigned over a set of theta1 and theta2
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
% The limits of x-axis and y-axis
axis([-0.1 3 0 3])
% To cease the animation from jumping between subsequent figures
pause(0.09)
% collecting frames of figures to comprise a movie/animation
M(ct) = getframe(gcf);
ct=ct+1;
end
end
% To make a movie of the collected frame
movie(M)
% Saving the movie in '.avi' format
videofile = VideoWriter('forward_kinematics.avi','uncompressed AVI');
open(videofile)
% writing the movie in the videofile created
writeVideo(videofile,M)
close(videofile)


Errors Occurred During Execution:
- No Errors were found during the Execution
- Error Occurred only due to spelling mistakes or missing semicolons after completing the line
- Below Error Occurred due to small caps mistake in file naming

Results & Conclusion:-
Thus we have simulated the 2R Robotic arm by using Matlab programming and also created a Movie/Animation from the plots obtained from the program
- Below link is given for the Movie/Animation of a 2R Robotic arm Simulator
https://youtu.be/VePfCCvE2AA