Project

Forward Kinematics of 2R Robotic Arm Manipulator

AIM-

To simulate the forward kinematics of 2r robotic arm manipulator in Matlab.

OBJECTIVE-

To write code in Matlab for simulating forward kinematics of 2r robotic arm then collecting all those positions of the arm frame by frame then creating an animation by those frames

THEORY-

  • A 2r robotic arm manipulator consists of two links which refer as 2 arms which are free to move in space these arms are programmed so that we can have the control on them the main aim is to track the areas it can reach and show it in a video.
  • One end of link 1 is connected to a horizontal surface and another end is connected to link 2 using a joint so that it is movable thus the rotary motion is obtained.
  • In forward kinematics, we use kinematic equations of the robot to calculate the position of the end effector.

DIAGRAM

FORMULA TO CALCULATE THE POSITION OF MANIPULATOR

  • step1- calculate the position of link1, link1 has two end points so co-ordinate of starting point is (0,0) and co-ordinate of ending point is (`l1costheta1 ,l1sintheta1)`
  • step2- calculate the co-ordiantes of link2, co-ordinate of the starting point of link2 is same as ending point of link1 i.e, (`l1costheta1,l1sintheta1`) and co-ordinate of the ending point of link2 is (`l1costheta1+l2costheta2, l1sintheta1+l2sintheta2`).

CODE-

%forward kinamatics of a 2R robotic arm manipulator
clear all
close all
clc
%Inputs
%length of arms in meters
l1 = 1.2;%length of link1
l2 = 0.6;%length of link2
%angles made by links w.r.t x-axis in degrees
[theta1,theta2] = deal(linspace(0,90,20), linspace(0,90,20));
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 2 0 2])
     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)

STEP BY STEP CODE EXPLANATION

  1. firstly, define inputs i.e, length of arms l1 and l2 and angles made by arms with horizontal surface is to assigned here we used linspace command to generate the 20 samples from 0 to 90 degrees.
  2. there are 20 different positions for link2 for every position of link1 therefore there are 400 different positions this logic is implemented by using nested forloop where inner forloop run for j =1 to 20 and outer forloop run for i = 1 to 20 total 20*20 = 400 times the code inside loop is executed.
  3. inside the loop the 3 co-ordinates are defined then the plot command is used to join the lines between the co-ordinates thus link1 and link2 are formed.
  4. getframe command is used to get each of those figure i.e, for every possible combination of `theta1`and`theta2` the figures(frames) are captured
  5. then movie command is used to create the movie in that a video file is created then file is opened and the frames are written in video by writeVideo command, thus a animation video is created.

ERRORS FACED WHILE EXECUTION OF PROGRAM

  • firstly, the major error i faced is, i want to give inputs of two angles `theta1 ,theta2` in one line since both angles are similar so i written this below code and executed
    %forward kinamatics of a 2R robotic arm manipulator
    clear all
    close all
    clc
    %Inputs
    %length of arms in meters
    l1 = 1.2;%length of link1
    l2 = 0.6;%length of link2
    %angles made by links w.r.t x-axis in degrees
    (theta1,theta2) = (linspace(0,90,20), linspace(0,90,20));
    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 2 0 2])
         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)
    ​
    thus i got error message i got in command window is

to rectify this error i used deal command do define the two angles in single line

  • there are some minor errors i faced such as i used WriteVideo instead of writeVideo then i got this message in command window

then i used the first letter of the command lower case to rectify this error

VIDEO LINK- https://youtu.be/Z8vyFfNLwL8

CONCLUSION-

The forward kinematics of 2r robotic arm manipulator is simulated using matlab and thus an animation video is created we can see in video the every position that it can reach.

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.