Project

SIMULATE THE FORWARD KINEMATICS OF AN 2R ROBOTIC ARM BY USING MATLAB

A PROGRAM IN MATLAB TO SIMULATE THE FORWARD KINEMATICS OF AN 2R ROBOTIC ARM.

AIM: To write a program to simulate the Forward Kinematics of an 2R Robotic Arm.

GUI Used: MATLAB R2020a

OBJECTIVES:

  • Basic theories of a Robotic Arm and its workspace and mechanism will be discussed.
  • Few steps will be followed to create a program in MATLAB by using its mechanism and the code will be explained.
  • If we face any errors, we will discuss on that and will try to figure it out.
  • A program will be created when the various angle of the Robotic arm is fixed and the output diagram will be shown.
  • A program will be created to show the output diagram when different angle is used to make a Robotic Arm and an Animation will be made on that.

BASIC THEORIES:

A Robotic Arm is a type of mechanical arm that is similar to a human arm. It has various segments which is closely resembles the shoulder, an elbow and a wrist. A robotic arm is programmable and can be directed to perform a variety of function just like human arm.

A 2R Robotic Arm which has two joints. Each and every links have independent angle to rotate. It is used in a wide range where automation is needed for welding, painting, drilling, material handling etc. Let’s take example to explain a 2R Robotic Arm,

Here, Length of two links of the Robotic Arm l1 and l2. They are rotating with their individual angle θ1 and θ2. We have three coordinates from the drawing;

(x0, y0) is the starting point of link 1.

(x1, y1) is the mating point of link 1 and link 2.

(x2, y2) is the end point of the manipulator.

Here in mathematical expression, we get,

x0 = 0;

y0 =0;

x1 =l1cosθ1;

y1= l1sinθ1;

x2=x1+ l2cosθ2;

y2=y1+ l2sinθ2;

later, we will to try to simulate the MATLAB program with the help of above information.

PROCDURES:

Steps to be followed to create a program to calculate the Drag Force;

  • Step1: Open MATLAB.
  • Step2: Click on New Script to open the Editor Window.
  • Step3: Input code need to be written here and then click on Save option to save the program as a M-file.
  • Step4: Run the programming to get an output as a plot.

PROGRAMMING FOR FIXED VALUE OF THETA (θ):

% Program for Forward Kinematics of a 2R Robotic Arm manupulator

clear

close all

clc

 
% Inputs for the Robotic Arm

% length of link 1

l1=1.2;

% length of link 2

l2=0.5;

% angle of link 1

THETA_1=45;

% angle for link 2

THETA_2=30;

 
% coordinates

x0=0;

y0=0;

x1=l1*cosd(THETA_1);

y1=l1*sind(THETA_1);

x2=x1+l2*cosd(THETA_2);

y2=y1+l2*sind(THETA_2);

 
% For plotting the diagram for the Robotic Arm manupulator

plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',4)

xlabel('X axis')

ylabel('Y axis')

EXPLNATION:

To calculate Drag Force in MATLAB, we have created the above Program where,

clear all: It removes items from workspace, freeing up system memory.

close all: It deletes all figures whose handles are not hidden.

clc: It clears Command Window.

All the input values being taken for plotting the diagram as input in the program from theory explained.

‘plot’ command is use to plot the diagram by the coordinates as defined.

OUTPUT:

ERROR OCCURRED:

Error occurred in the run time:

SOLUTION:

It had been mistaken by using ‘single quotation sign (‘ ’)’ inside the plot function before and after 4. After removing the single quotation sign (‘ ’), the program ran properly.

PROGRAMMING FOR MULTIPLE VALUE OF THETA (θ):

% A Program for forward Kinematics 2R Robotic Manupulator

 
clear

close all

clc

 
% Inputs for Robotic Arm

% Length of both links in (m)

L1=1;

L2=0.5;

 
% Angles of the links along with their respective horizontal in (deg)

THETA1=linspace(0,90,10);

THETA2=linspace(0,120,20);

 
ct=1;

for i=1:length(THETA1)

    theta1=THETA1(i);

    for j=1:length(THETA2)

     theta2=THETA2(j);

    
     % coordinates

       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',4);

       xlabel('X axis')

       ylabel('Y axis')

       pause(0.3)

       grid on

       axis([-0.1 1.7 0 1.7])

       title('FORWARD KINEMATICS OF 2R ROBOTIC ARM')

       M(ct)=getframe(gcf);

       ct=ct+1;

    end

end

movie(M)

videofile=VideoWriter('robotic_arm_for_random_angle.avi','uncompressed avi');

open (videofile)

writeVideo(videofile,M)

close(videofile)

 

EXPLNATION:

To calculate Drag Force in MATLAB, we have created the above Program where,

clear all: It removes items from workspace, freeing up system memory.

close all: It deletes all figures whose handles are not hidden.

clc: It clears Command Window.

  • All the input values lengths and angles being taken for plotting the diagram as input in the program from theory explained. Here linspace() command is used to take multiple values or we can say a range of values for θ1 and θ2
  • A ‘for’ loop has been created to generate frames and the variable called ‘counter(ct)’ to starts with.
  • First loop i and second loop j are ranging from 1 to maximum value of θ1(THETA1) and θ2 (THETA2) respectively.
  • The graph has been plotted by using plot
  • The counter will increment by 1 until the loop is finished.
  • M, an array is created to store all the frames which are created by using getframe()
  • An animation of all frames is created by using few commands such as,

The function movie is used to play the recorded movie frames , VideoWriter is used to create a videofile from an array and specifies the file type. ‘open()’, ‘writeVideo()’ and ‘close()’ are used to open the file to write, write data to the file and to close the file respectively.

OUTPUT:

Program ran successfully;

*the above image is a screenshot that is why we cannot see the animation.

Animation:

ERROR OCCURRED:

Error occurred in the run time:

ERROR 1:

SOLUTION 1:

There was an invalid entry of ‘Theta_2’. There was no input called ‘Theta_2’. It should be ‘theta_2’ instead of ‘Theta_2’. Error resolved.

ERROR 1:

SOLUTION 2:

There is no such function called ‘videowriter’. That is why the error had been occurred. The expression was wrong. ‘VideoWriter’ was used to omit the error.

CONCLUSION:

So, the program for the Forward kinematics of a 2R Robotic arm has been made and the workspace of the Manupulator or the Robotic Arm is plotted in the animation.

References:

1.https://en.wikipedia.org/wiki/Robotic_arm

2.https://3dinsider.com/what-are-robotic-arms/

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.