Project

MATLAB Program: Simulating 2R Robotic Arm

Aim: Write a MATLAB program to simulate forward kinematics of a 2R robotic arm.

Objective:

  • Simulate the movement of 2R robotic arm
  • Create animation of robotic arm's workspace

Theory:

A robotic arm is a type of mechanical arm, usually programmable, with similar functions to a human arm. The arm may be the sum total of the mechanism or may be part of a more complex robot. The links of such a manipulator are connected by joints allowing either rotational or translation motion. 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.

A 2R robotic arm consists of two links (L1 & L2) and two rotational joints and is pivoted to the base as shown in the following figure. Let `theta 1` and `theta 2` be the angle made by the links L1 and L2 respectively with the horizontal axis. Let (X0,Y0), (X1,Y1), (X2,Y2) be the coordinates of the points as shown above.

Program:

%2R robotic arm challenge
clear all
close all
clc

%Inputs
%Assuming length of link 1 as 3m and length of link 2 as 1.5m.
l1 = 3;
l2 = 1.5;

%t1 and t2 are the angle of traverse of 1st arm and 2nd arm respectively
t1 = linspace(0,90,10); 
t2 = linspace(0,90,10);
ct = 1;

for i = 1:length(t1)
    T1 = t1(i);
    for j = 1:length(t2)
        T2 = t2(j);
        x0 = 0;
        y0 = 0;

        x1 = l1*cosd(T1);
        y1 = l1*sind(T1);

        x2 = x1 + l2*cosd(T2);
        y2 = y1 + l2*sind(T2);
        
        %Plotting
        plot([x0 x1],[y0 y1],'linewidth',3,[x1 x2],[y1 y2],'linewidth',3)
        hold on
        
        %plot used to visualise presence of a joint (feels a littel realistic)
        plot(x0,y0,'marker','o','markerSize',10,'markerFacecolor','k')
        plot(x1,y1,'marker','o','markerSize',10,'markerFacecolor','k')
        
        %plot used to visualise end effector
        plot(x2,y2,'marker','*','markerSize',25)
        
        hold off
        axis([-0.3 5 0 5])
        title('2R Robotic Arm Workspace')
        
        %M(ct) = getframe(gcf);   %WORKS IN MATLAB
        
        Text = sprintf("Robotic_Arm-%d.jpg",ct);    %FOR OCTAVE
        saveas(1,Text);
        
        ct=ct+1;
    end
end

%wORKS IN MATLAB
%Animation of Workspace of Arm
%movie(M)
%videofile = VideoWriter('Robotic_Arm.avi','Uncompressed AVI')
%open(videofile)
%writeVideo(videofile,M)
%close(videofile)

Working of Code:

The values of link L1 and L2 are assumed to be 3 metres and 5 metres respectively. The angle of traverse of both the links are set at 90 with respect to the surface. A nested for loop was used to locate the coordinates of the arm and thus, playing a sequence of the obtaines points. The coordinates were located by the concept of projection. The result was then plotted and using loop counter the successive images were captured. Stitching the images gave us the animation of the robotic arm.

Output:

References:

Material: Resources can be accessed here

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.