Project

SIMULATING FORWARD KINEMATICS OF A 2R ROBOTIC ARM USING MATLAB PROGRAMMING

Aim :

To simulate the Forward Kinematics of a 2R Robotic Arm using MATLAB Program and tracing the Workspace of the End Effector using an Animation.

Description :

A Robotic Arm is a programmable Mechanical Arm which may be the sum total of Mechanism or a part of complex shape. The links are connected by joints which allow either Rotational or Translational Movement. 2R Robotic Arm is a Robotic Arm with 2 Rotational joints. The links of the Robotic Arm form a kinematic chain and the terminus of this kinematic chain is called End Effector. The End Effector interacts with the Environment. Both the links of the Robotic Arm are restricted to a 90 degree rotation with respect to the axis.

Degree of Freedom (DOF) of each link = 1

Kinematics of the Robotic Arm :

Kinematics is the analysis of motion without considering the forces.Forward kinematics (for a robot arm) takes as input joint angles, and calculates the Cartesian position and orientation of the end effector. Inverse kinematics takes as input the Cartesian end effector position and orientation, and calculates joint angles. Inverse kinematics is used for trajectory planning.

Figure :

l1 is the length of 1st link and l2 is the length of 2nd link. Considering that link 1 is attached to the horizontal plane and making an angle θ1 with the horizontal. The link 2 is connected to link 1 and makes angle θ2 with horizontal. The co ordinates of (x0,y0) (x1,y1) and (x2,y2) are shown in figure.

MATLAB CODE :

%program for forward kinematics of a 2 arm robotic manipulator
clear all
close all
clc
%Inputs for link 1 and link 2
l1=1;
l2=0.5;
%Taking set of angles for θ1 and θ2 with same interval using linspace command 
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
%Initializing the counter variable
ct=1;
%for loop programming 
for i=1:length(theta1)
    THETA1=theta1(i);
    for j=1:length(theta2)
        THETA2=theta2(j);
        %co ordinates calculation
        x0=0;
        y0=0;
        x1=l1*cosd(THETA1);
        y1=l1*sind(THETA1);
        x2=x1+(l2*cosd(THETA2));
        y2=y1+(l2*sind(THETA2));
        %plotting the values
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
        %setting the X axis and Y axis limits
        axis([-0.1 1.5 0 1.5])
        %pausing the code in sec
        pause(0.2)
       %Getting all the frames in a single matrix
        M(ct)=getframe(gcf);
        %Incrementing the counter variable 
        ct=ct+1;
        
    end
end
%creating an animation and extracting the video file
movie(M)
videofile=VideoWriter('forward_kinematics.avi','uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)

Explanation for the code:

At first the input values for the lengths of the links are taken and now the set of values of θ1 and θ2 are taken such for different locations of the links the workspace will be traced.For one θ1 value of link 1 ten θ2 values of link is obtained.This can be acheived by the for loop and nested for loop operations. All the co ordinate value calculations and plotting commands should be included in the nested for loop.So 100 positions of links will be traced by these loops. Pause command pauses the code for a particular time period before executing the next incremental step in a for loop so it creates an illusion like animation.

getframe : It collects the frame and stores the frame in it

movie : It generates an animation using the frames collected

videofile=videoWriter() : It assigns file name and file format

open(videofile) : It opens the video file

writeVideo(videofile,M) : It writes the video with plot frames in array M

close(videofile) : It closes the video file

Output plots :

Using basic plot command plotting all the link positions in a single frame with out any animation

All the 100 link positions will be displaced in a seperate frames if figure(ct) is placed above the plotting command.It displays each link position independently.

Animation video youtube link : https://youtu.be/mfQ9D7Um558

Conclusion :

Hence an animation video is created to enhance the positions of the End Effector.Its very important to know the work space locations in most of the Robotic applications like Welding a complex frame structure,Drilling applications,palletization in industries and some laser cutting operations.

Error :

Error rectification:

'videowriter' and 'writevideo' are undefined functions as they are case-sensitive. 'VideoWriter' and 'WriteVideo' are the actual commands to rectify the error

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.