Project

Forward Kinematics of a Two-link and Three-link Robotic Arm

Aim:

Robots have become an integral part of most manufacturing industries and in the Healthcare discipline. Some of operations that Robots can perform include drilling, welding, scanning, lifting, assembly, etc. In Healthcare, some surgeries are performed with robotic assistance. Artificial Intelligence has become very essential in our daily living.

This project is about simulating a 2 link Robotic arm in its moving envelope using a Matlab code. As an extension to the current challenge, a 3R robotic arm is also simulated with some alterations to the Matlab code.

Governing Equations:

The following equations are used to calculate the coordinates of the linkages. Please refer to the schematic provided in the objectives section to identify the variables used in the governing equations.

`x_1=x_0+L_1 cosθ_1 [m]`

`y_1=y_0+L_1 sinθ_1 [m]`

`x_2=x_1+L_2 cosθ_2 [m]`

`y_2=y_1+L_2 sinθ_2 [m]`

where, `L_1` and are `L_2` the lengths of the two linkages. The angles subtended by the first and second linkage with the horizontal are denoted by `theta_1` and `theta_2` respectively. When extending the same problem to include a third linkage, the following equations have to be included in the code.

`x_3=x_2+L_3 cosθ_3 [m]`

`y_3=y_2+L_3 sinθ_3 [m]`

where,`L_3` is the length of link-3. The angle subtended by the third linkage with the horizontal is denoted by `theta_3` .

Objectives:

The main objective of this project is to understand the working of a robotic arm using a simplified 2-link system. A schematic of the linkage system is shown below. Please note that the term linkage/link/arm mean the same and are used interchangeably.

In real life applications, it is essential to understand the motion of a robot in order to ascertain its working envelope. This project simulates one such robotic system with two links using a Matlab code. A picture of a robot used in a Hospital is shown below.

Ref: Medical Device Network

Main Content:

The following Matlab code simulates the movement of a 2 link Robotic Arm (linkage) by changing the angle with respect to the horizontal. Comments are provided at each step of the code to explain the command. This code creates a movie, simulating the movement of the manipulator. The algorithm for the Matlab code is given below followed by the code.

Program Algorithm:

Line No.

Explanation

1,2,3

Code title and description

4,5,6

Clear all previous data/screen and close windows of previous code execution

8,9

Initialize length of the robotic linkages 1,2

10

Initialize the counter value for the Figure output (to be displayed)

11

Initialize the angular orientation of link-1; this is an array of values for multiple locations of link-1

12

Initialize the angular orientation of link-2; this is an array of values for multiple locations of the link-2

13,14

For loop description

15,16

A for loop is used to repeat a set commands for a certain range of counter “i” values; During every iteration, THETA1 is assigned to a new value from the array of possible values for link-1 angular orientation

17,18

A second for loop (or nested loop) is used to repeat a set commands for a certain range of counter “j” values within the first for loop assigned for link-1; During every iteration, THETA2 is assigned to a new value from the array of possible values for link-2 angular orientation

20,21

Set the first rotational point (origin) for link-1

22,23

Calculate the second rotational point for link-1 (or the first rotational point for link-2) based on the length and angular orientation of link-1

24,25

Calculate the second rotational point for link-2 based on the respective length and angular orientation of link-2

30

Using the plot command to display the links in a figure window

32,33

Providing labels for the X and Y axis

35

Turning the grid lines ON in the plot

41

Setting the axis limits

44

The pause command is used to display multiple plots on the same window in a sequence but with a set pause time

47

Create an Animation of the robotic arm by stitching individual frames from the current figure window

48

Set counter to increment figure number

49,50

End the nested for loop

52

Create a Movie from the individual frames

54

Creating a ".avi" format of the movie to play it in Media player

57

Open the video file

58

Copy the individual frames into the video file

59

Close the video file

%-----------------Start of Program-----------------------
%Forward kinematics of robotic arm
%Clear and close all previous calculations, figures, etc.
clear all
close all
clc
%Defining the lengths of the Robotic arms
L1=1;%length of link 1 in 'm'
L2=0.5;%length of link 2 in 'm'
ct=1;%figure counter for incrementing the figure number
theta1=linspace(0,90,10);%angle of link 1 with horizontal in 'deg.'
theta2=linspace(0,90,10);%angle of link 2 with horizontal in deg.'
%for loop for calculating the link 1 and link 2 coordinates
%in the robotic workspace
for i = 1:length(theta1)%loop for theta1
    THETA1 = theta1(i);%assigning value for THETA1
    for j = 1:length(theta2)%loop for theta2
        THETA2 = theta2(j);%assigning value for THETA2
        %Calculating the arm location in space
        x0 = 0;%x coordinate at the start of link 1
        y0 = 0;%y coordinate at the start of link 1
        x1 = L1*cosd(THETA1);%x coordinate at the end of link 1
        y1 = L1*sind(THETA1);%y coordinate at the end of link 1
        x2 = x1+L2*cosd(THETA2);%x coordinate at the end of link 2
        y2 = y1+L2*sind(THETA2);%y coordinate at the end of link 2
%Plotting the link locations in the workspace
%figure(ct)%Use this if incrementing Figure number
%hold on % for keeping the previous plots on the screen
%Plotting the robotic links location in the workspace
plot([x0 x1],[y0 y1],'b',[x1 x2],[y1 y2],'r','linewidth',4);
%providing labels for the x and y axis
xlabel('x-position [m]')
ylabel('y-position [m]')
%enabling the grid display
grid on
%Use the line command to draw a line between two cooedinates
%Using the plot command is a better option 
%line([x0 x1],[y0 y1],'linewidth',3,'color','b');
%line([x1 x2],[y1 y2],'linewidth',3,'color','r');
%setting the axis limits
axis([-0.05 1.5 0 1.5])
%Use the pause command to quickly check the results
%pausing the code is not very efficient
pause(0.1)
%Creating Animation of the robotic arm
%get individual frames from the current figure window
M(ct) = getframe(gcf);
ct = ct+1;%counter to increment figure
    end
end
%Creating Movie from the individual frames
movie(M)
%Creating a ".avi" format of the movie to play it in Media player
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
%Open the video file, copy the individual frames into it,
% and close the file
open(videofile)
writeVideo(videofile,M)
close(videofile)

% -----------------------End of program------------------------------

The movie can be viewed by clicking on the following link:

https://drive.google.com/file/d/1_jfpO2Zc252a02SRtMKvfbt66otB36DM/view?usp=sharing

As we can see from the animation, by altering just the angular orientation of the linkages, we are able to achieve the moving envelope of the 2R robotic system. The moving envelope is between 0 and 90 degrees of link-1 and link-2. To increase the flexibility of motion, the angular motion can also be extended till -90 degrees.

Extension of the 2R Challenge:

As an extension to the 2R robotic arm simulation, one can also simulate the movement of a robot with 3 or more linkages by keeping track of the angular positions. The above matlab code has been modified to include the third link in the simulation and is presented below.

%-----------------Start of Program-----------------------
%Forward kinematics of robotic arm
%Clear and close all previous calculations, figures, etc.
clear all
close all
clc
%Defining the lengths of the Robotic arms
L1=1;%length of link 1 in 'm'
L2=0.5;%length of link 2 in 'm'
L3=0.3;%length of link 3 in 'm'
ct=1;%figure counter for incrementing the figure number
theta1=linspace(0,90,10);%angle of link 1 with horizontal in 'deg.'
theta2=linspace(0,90,10);%angle of link 2 with horizontal in deg.'
theta3=linspace(0,90,10);%angle of link 3 with horizontal in deg.'
%for loop for calculating the link 1 and link 2 coordinates
%in the robotic workspace
for i = 1:length(theta1)%loop for theta1
    THETA1 = theta1(i);%assigning value for THETA1
    for j = 1:length(theta2)%loop for theta2
        THETA2 = theta2(j);%assigning value for THETA2
            for k = 1:length(theta3)%loop for theta3
                THETA3 = theta3(k);%assigning value for THETA3
        %Calculating the arm location in space
        x0 = 0;%x coordinate at the start of link 1
        y0 = 0;%y coordinate at the start of link 1
        x1 = L1*cosd(THETA1);%x coordinate at the end of link 1
        y1 = L1*sind(THETA1);%y coordinate at the end of link 1
        x2 = x1+L2*cosd(THETA2);%x coordinate at the end of link 2
        y2 = y1+L2*sind(THETA2);%y coordinate at the end of link 2
        x3 = x2+L3*cosd(THETA3);%x coordinate at the end of link 3
        y3 = y2+L3*sind(THETA3);%y coordinate at the end of link 3
%Plotting the link locations in the workspace
%figure(ct)%Use this if incrementing Figure number
%hold on % for keeping the previous plots on the screen
%Plotting the robotic links location in the workspace
plot([x0 x1],[y0 y1],'b',[x1 x2],[y1 y2],'r',[x2 x3],[y2 y3],'g','linewidth',4);
%providing labels for the x and y axis
xlabel('x-position [m]')
ylabel('y-position [m]')
%enabling the grid display
grid on
%Use the line command to draw a line between two cooedinates
%Using the plot command is a better option 
%line([x0 x1],[y0 y1],'linewidth',3,'color','b');
%line([x1 x2],[y1 y2],'linewidth',3,'color','r');
%setting the axis limits
axis([-0.05 1.9 0 1.9])
%Use the pause command to quickly check the results
%pausing the code is not very efficient
pause(0.1)
%Creating Animation of the robotic arm
%get individual frames from the current figure window
M(ct) = getframe(gcf);
ct = ct+1;%counter to increment figure
            end
    end
end

%Creating Movie from the individual frames
movie(M)
% %Creating a ".avi" format of the movie to play it in Media player
videofile = VideoWriter('forward_kinematics_3R_Srikrishna.avi','Uncompressed AVI');
% %Open the video file, copy the individual frames into it,
% % and close the file
open(videofile)
writeVideo(videofile,M)
close(videofile)

% -----------------------End of program------------------------------

An animation of the complete moving envelope for the 3R robotic arm can be viewed by clicking on the following link.

https://drive.google.com/file/d/1j2-Bi-pGBD3NhKzUeOTiSMrpVC-vSxUy/view?usp=sharing

As observed from the animation, it is clear that with increasing number of robotic arms (linkages), the flexibility of the robot can be increased. This is particularly helpful when high precision movement is necessary, for example in machining an automobile component.

Conclusions:

Thus, the robotic arm challenge enables us to understand the concept of the linkage motion in a simplified manner. Extending the 2D motion of the arm to 3D space would be interesting as most robots operate in 3D space. In addition, a small manipulator can also be modeled to mimic the hand of a robot.

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.