Project

Simulation of forward kinematics of a 2R Robotic Arm.

TITLE: - Simulation on forward kinematics of a 2R Robotic Arm using Matlab.

OBJECTIVE: - The objective of this programming is to simulate the 2R Robotic Arm.

Fig. 2R Robotic arm

THEORY:-

A robotic arm can be described as a chain of links that are moved by joints which are actuated by motors. Two link are present in this robotic arm i.e. link (1) and link (2) An end effectors also called a robot hand, can be attached to the end of the link 2.

In this above fig link 1 is attached to the base and at the end of link 1, link 2 is attached and end effector is attached at end of link 2.

Programing:-

Program 1:- simple output by line graph

Explanation of program 1:-

Below program is the code of simple 2R robotic arm

In this link 1 and link 2 are the arms of robot with length of L1 and L2 resp. Link 1 is at theta1 angle with respect to horizontal and link 2 is at theta2 angle with horizontal.

So, here first we have to give inputs such as length of arms and the position of arm.

Then we have given the coordinates to the 3 points such as at the starting of link 1, at ending of link 1 or starting of link 2, and at ending of ink 2.

After giving the values to coordinates plotting of this points in the plots taken place.

Plotting of link 1 ([x0 x1],[y0 y1]) with line width of 3 and color is black (k).

Plotting of link 2 ([x1 x2],[y1 y2]) with line width of 3 and color is red (r).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Programing of Forward kinematics of a 2R Robotic Arm %%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc

% ------- Inputs ------- %

% Length of links %

l1 = 1;
l2 = 0.5;

% Position of the arm %

theta1 = 60;
theta2 = 70;

% ------- Coordinates (Points)------- %

x0 = 0;
y0 = 0;

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

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

% ------- Plots ------- %

line([x0 x1],[y0 y1], 'linewidth',3,'color','k')
line([x1 x2],[y1 y2], 'linewidth',3,'color','r')

As this program executed the following output I get.

As we change the theta of link 1 and link 2 as 60deg and 70deg with horizontal then I get the following output.

Programing 2:- Animation of forward kinematics of a 2R Robotic Arm.

Explanation of program 2:-

Now this below code gives us an animation of the robotic arm.

So before we need to change the position of links we have to change the value manually but in this by using for loop it change value one by one from [0 to 90]

So to get different value of theta we use linspace command i.e. linspace (0, 90, 15) this means that the first value is 0 and last value is 90 and is divided into 15 parts to display.

By using “for-loop”

(i) is the value which is going to change from 1 to length of θ

(j) is the value which is going to change from 1 to θ

Then after that in the ‘for loop’ itself we put the coordinates points.

And then gives command to plot the line 1 and line 2.

Pause command is use to decide the speed of the animation that we have to get as an output.

‘ct’ represent the individual frame.

“getframe” command is use to get the frame of current figure.

After the for loop,

We use movie command to get movie of our work.

Movie is in avi file so we have used .avi in it.

An Error i get that is

Error using VideoWriter (line 168)
The specified profile is not valid.

Error in finalarm (line 44)
videofile =VideoWriter('arm_simulation','compressed AVI');

So to remove the error type uncompressed AVI instead of compressed AVI.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Programing of Forward kinematics of a 2R Robotic Arm %%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc
 
% ------- Inputs ------- %

% Length of links %

l1 = 1;
l2 = 0.5;

% Position of the arm %

theta1 = linspace(0,90,15);
theta2 = linspace(0,90,15);
 
ct=1
for i = 1:length(theta1)
    THETA1 = theta1(i);
    for j = 1:length(theta2)
        THETA2 = theta2(j);
        % ------- Coordinates (Points)------- %
        x0 = 0;
        y0 = 0;
 
        x1 = l1*cosd(THETA1);
        y1 = l1*sind(THETA1);
 
        x2 = x1 + l2*cosd(THETA2);
        y2 = y1 + l2*sind(THETA2);
 
        % ------- Plots ------- %
        
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2], 'linewidth',3)
        axis([-0.1 1.5 0 1.5])
        pause (0.03)
        M(ct)= getframe(gcf);
        ct=ct+1;
    end
end
 
movie(M)
videofile =VideoWriter('arm_simulation','compressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

OUTPUT:-

Output is in the form of animation that I uploaded on youtube. This animation can be viewed by visiting this below link.

Link of my animation uploaded on YOUTUBE

https://youtu.be/haU_OiVQ1_c

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.