Project

Forward kinematics of 2R Robotic Arm using MATLAB

Aim : Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm.

Introduction:

The 2R robotic arm consist of 2 arm linkages,of which one end of linkage is fixed at ground.

Linkage 1 = L1 = 1m

Linkage 2 = L2 = 0.5m

The coding is done in such a way to simulate the possible movement of the arms in x-y axis at a range of 0 to 90 degrees.

At first,we fix the arm position by assigning it coordinates and also giving the range through which we want the arm to move.

Then we plot the arm by assigning all the points in plot command. The axis will be fixed.

Since we want an animation file of the code,we generate a movie by reoccuring the plot at different arm positions by "for loop" command.

"linspace" command generates various angular positions between a predetermined range.

We assign this all to a command "VideoWriter" which in return generates a video file.

The code is as follows:

clc
close all
clear all

%forward_kinematics_of_robotic_arm

%inputs

l1 = 1;
l2 = 0.5;

theta1 = linspace(0,90,5);
theta2 = linspace(0,90,10);


ct = 1;
for i = 1 : length(theta1);
    THETA1 = theta1(i);
    
    
   for j = 1 : length(theta2);
    THETA2 = theta2(j);
    
    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([-0.1 1.5 0 1.5]);
    pause(0.03);
    M(ct) = getframe(gcf);
    ct = ct+1;
    end
end

movie(M)
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

The Animation video file is uploaded on YouTube,the links is given below:

https://youtu.be/Ag2APk0rVD0

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.