Project

Simulation of the forward kinematics of a 2R Robotic Arm.

Objective: To write a program in MATLAB to simulate the forward kinematics of a 2R Robotic Arm.

Description:

Let us say the length of links of 2R robotic arm be l1 & l2 respectively.

Angle1 and Angle2 are the angles made by the links w.r.t horizontal.

let us say the hinged position of robotic arm is origin. Therefore, x0 y0 are starting coordinates of link1. x1 y1 are the end coordinates of link1 & also starting coordinates of link2. x2 y2 are the ending coordinates of link2.

MATLAB code with explanation:

%2R robotic arm
clear all
close all
clc

%defining the length of links of 2R robotic arm
l1 = 4;
l2 = 2;

%Defining the angle to be made by links w.r.t horizantal
angle1 = [0:15:90];
angle2 = [0:10:90];

%let us say the hinged position of robotic arm is origin.
%x0 y0 are starting coordinates of link1
%x1 y1 are the end coordinates of link1 & also starting coordinates of link2
%x2 y2 are the ending coordinates of link2
x0 = 0;
y0 = 0;

%To store each frame lets start a frame counter
frame = 1;

for k=1:3                       
for i = 1: length(angle1)     %For motion of link1
for j = 1:length(angle2)       %For motion of link2
x1 = l1*cosd(angle1(i));
y1 = l1*sind(angle1(i));
x2 = x1+l2*cosd(angle2(j));
y2 = y1+l2*sind(angle2(j));

figure(k)
plot([x0 x1],[y0 y1],'-*',[x1 x2],[y1 y2],'-*','linewidth',2)
axis([0 6.5 0 6.5])
if k<=2
hold on
end
if k==1
title('Complete motion path trace of Robatic arm')
elseif k==2
title('Complete motion path trace of link2 at certain angle of link1')
else k==3
title('Motion of Robotic arm at different angles of link1 & link2')
end
M(frame)=getframe(gcf);      %To store each frame in a variable M
frame=frame+1;
end
if k==2
hold off
end
end
end

%To create a movie with the frames in variable M in mp4 format with 10FPS
movie(M)                   
v = VideoWriter('2R_Robotic_Arm','MPEG-4')
v.Quality = 100
v.FrameRate = 10
open(v)
writeVideo(v,M)
close(v)

Output:

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.