Project

SIMULATION OF 2R ROBOTIC ARM USING MATLAB

Aim: Simulation of Forward kinematics of 2R Robotic Arm using MATLAB.

Objective:

  • Write a program in MATLAB for simulation of forward kinematics of a 2R Robotic Arm.
  • Plotting of results for single position and variation in position (movement).
  • Create an animation file of the plots.

Introduction & Terminology of 2R Robotic Arm:

  • A 2R Robotic Arm is a mechanical replica of human arm used to make robots to perform a specific task. The schematic diagram of a robotic arm shown in the figure below.
  • The arm is generally consists of Base, Shoulder, Elbow, Wrist, End-effector (Gripper) and links. The mechanism have two rotational joints at Shoulder and Elbow. These rotational joints tends motion and position of arm.

The operations of the arm are to be controlled by programming and in this project I am using MATLAB for programming.

Parameters:

For programming of the robotic arm the different parts are given different notations to calculate the position of links with respect to origin. The angles of the links are calculated with respect to the horizontal axis. These parameters are shown in the following figure.

  • Descriptions of the notations given in the figure:
  • L1 = Length of link 1
  • L2 = Length of link 2
  • θ1 = Angle of link 1 wrt Horizontal
  • θ2 = Angle of link 2 wrt Horizontal
  • (x0 , y0) = co-ordinates of origin/starting point of link 1
  • (x1 , y1) = co-ordinates of ending point of link 1/starting point of link 2
  • (x2 , y2) = co-ordinates ending point of link 2
  • The starting point is origin therefore, (x0 , y0) = (0 , 0).
  • The ending point of link 1, (x1 , y1) = (L1*cosθ1 , L1*sinθ1)
  • The ending point of link 2, (x2 , y2) = ([x1 + L2*cosθ2] , [y1 + L2*sinθ2])

Body of Content:

  • MATLAB is used to Program the operation of the robotic arm.

Progoram to Display Single position of Robotic arm:

clear all
close all
clc

%Program to simulate 2R Robotic Arm

%Inputs
%Length of Links (m)
disp('Length of first link')
L1 = 10
disp('Length of second link')
L2 = 5

%Agles of links with respect to horizontal axis
disp('Angle of first link')
theta1 = 60
disp('Angle of second link')
theta2 = 30

%Co-ordinates
x0 = 0
y0 = 0

x1 = L1*cosd(theta1)
y1 = L1*sind(theta1)

x2 = x1 + L2*cosd(theta2)
y2 = y1 + L2*sind(theta2)

%Plotting

line([x0 x1], [y0 y1], 'linewidth', 3, 'color', 'b')
line([x1 x2], [y1 y2], 'linewidth', 3, 'color', 'r')
  • This program is written to display a single position of the robotic arm for fixed input values of lengths of links and the angles of links with respect to horizontal axis.
  • First of all the input values are added in the program and the co-ordinates of the three positions are programmed based on that input values as per calculation in above context.
  • At the end the line command is used to plot the results on the graph.

Output:

Program to Display varying positions of the robotic arm:

clear all
close all
clc

%Program to simulate 2R Robotic Arm

%Inputs
%Length of Links (m)
disp('Length of first link')
L1 = 10
disp('Length of second link')
L2 = 5

%Agles of links with respect to horizontal axis
disp('Angles of first link')
theta1 = linspace(0,90,10)
disp('Angles of second link')
theta2 = linspace(0,90,30)

ct = 1;

for i = 1:length(theta1)
    THETA1 = theta1(i);
    for j = 1:length(theta2)
        THETA2 = theta2(j);
        %Co-ordinates
        x0 = 0;
        y0 = 0;

        x1 = L1*cosd(THETA1);
        y1 = L1*sind(THETA1);

        x2 = x1 + L2*cosd(THETA2);
        y2 = y1 + L2*sind(THETA2);

        %Plotting

        plot([x0 x1], [y0 y1], [x1 x2], [y1 y2], 'linewidth', 3)
        axis([-5 15 0 15])
        pause(0.05)
        M(ct) = getframe(gcf);
        ct = ct+1;
    end
end
movie(M)
videofile = VideoWriter('2R Robotic Arm Simulation.avi', 'Uncompressed AVI');
open(videofile)
writeVideo(videofile, M)
close(videofile)
  • This program is written to display variation of position of the robotic arm for fixed input values of lengths of links and the angles of links with respect to horizontal axis are to be vary between 0o to 90o to get different results.
  • As the input values are the set of different angles the program becomes complex to perform using the syntax as first program. To overcome it the “for loop” is used in the syntax.
  • First for loop used to calculate values of co-ordinates of output especially for first angle of first link. In which i variable used to compute values of input angles and THETA1 variable used to store output values to display different positions of arm.
  • Second for loop used to calculate values of co-ordinates of output especially for second angle of second link. In which j variable used to compute values of input angles and THETA2 variable used to store output values to display different positions of arm.
  • After that plot command used to plot the results on the graph. pause command used to make a gap between two different output. getframe command used to store each output position in a frame in order to make a simulation of output on graph.
  • In the last the movie command used to make an animation of the output of the robotic arm.

Output:

The output of this program is an animation file. The link for which is in conclusion.

Discussion about Errors:

  • While writing the program mainly the mistakes happened with me that are typing of wrong keyword, mistakes in the spellings including uppercase and lowercase because the MATLAB commands are very specific, frame storing and video functions.

Result:

As the result of this program I have made an animation file which can be watch using following link.

https://youtu.be/uT8GPLIGEIo

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.