Program in Matlab to simulate the forward kinematics of a 2R Robotic Arm.
AIM: Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm.
Theory
Kinematics is the analytical study of the geometry of motion of a mechanism:
- With respect to a fixed reference co-ordinate system,
- Without regard to the forces or moments that cause the motion.
Robot Kinematics is the relationship between the dimensions and connectivity of kinematic chains and the position, velocity and acceleration of each of the links in the robotic system, in order to plan and control movement.
There are two types of robot kinematics Forward Kinematic and Inverse Kinematics
In forward kinematics, joint angles and the lengths known with the help of given data can compute the position and the orientation of the end effector with respect to the base. Which can use DH notation simply to compute the forward kinematic solution for a given serial manipulator.
In inverse kinematics if the end effector position is known. Using the end effector position, can calculate the joint angles and the lengths. Inverse kinematics is more important for controlling a robot.
2R Robotic arm contain 2 link and 2 revolute pair, these types of arm usually used to robot which are used in manufacturing, assembly line such as drilling, cutting, pick and drop, milling etc.
Code synopsis
One of the link i.e. link 1 whose length is l1, which is connected with the base making and angle θ1 and link2 whose length l2 is connected with link 1 at angle of θ2 .

Θ1 and θ2 varies from 0oto 90o taking the interval of 20 using linspace command.
Consider, X0, Y0 are the initial position of link 1 which is fixed with the base. X1, Y1 are the other end position of link1. Since link1 and link 2 are connected by revolute pair, so the end position of link 1 and starting position of link 2 are same i.e. X1,Y1 .End position of the link2 is assume to be X2, Y2.
Coordinates of Link1 and link 2 as follow:
X0 = 0 Fixed position of link 1
Y0 = 0
X1 = l1*cosθ1 End position of link 1
Y1 = l1 * sinθ1
X2 = X1 + l2* cosθ2 End position of link 2
Y2 = Y1 + l2 *sin θ2
% Forward kinematics of robotic arms
clear all
close all
clc
%inputs
l1= 1;
l2= 0.5;
theta1=linspace(0,90,20);
theta2 =linspace(0,90,20);
ct=1;
for i= 1:length(theta1)
THETA1 = theta1(i);
for j= 1:length(theta2)
THETA2 = theta2(j);
%cordinates of Link1
x0= 0;
y0=0;
x1= l1*cosd(THETA1);
y1= l1*sind(THETA1);
%cordinates of Link2
x2 = x1+l2*cosd(THETA2);
y2 = y1+l2*sind(THETA2);
%ploating
plot([x0,x1],[y0,y1],[x1,x2],[y1,y2],'linewidth',3)
axis([-0.1 1.5 0 1.5 ])
pause(0.02)
M(ct)= getframe(gcf);
ct=ct+1;
end
end
movie(M)
videofile= VideoWriter('forward.avi','uncompressed avi');
open(videofile)
writeVideo(videofile,M)
close(videofile)
RESULT:
Following video shows the forward kinematics of 2R Robotic arm at different angle and workspace of the robotic arm which are depend on length of the both links and angle between the link and base, angle between two links.
https://www.youtube.com/watch?v=K_Qw6Gt4SVI&feature=youtu.be