Challenge

Week 3.2 - 2R Robotic Arm Challenge

Aim:

To simulate forward kinematics of 2R robotic arm using matlab code.

Introduction:

A 2R Robotic Arm is a mechatronic system which uses linkages and end factor to achieve an assigned task. It consists of a base, two rotational joints, two links and end factor (robotic arm) as shown in below figure. It has multi-applications over a variety of industries such as welding industry, painting industry etc. It brings in precision and saves time for the production process. The arm uses code language for its operation which can be visualized using MATLAB coding through graphical representation.

Objective:

To write a program for simulation of forward kinematics of 2R Robotic Arm

To create a movie animation of obtained plots.

Inputs:

Link 1 = l1

Link 2 = l2

L1 making an angle with respect to x axis = Ɵ1

L2 making an angle with respect to x axis = Ɵ2

X0, Y0 = co-ordinates of the base (Origin).

Approach:

In this project a 2R robotic arm is used where,

  • its first link is hinged at the base having coordinates X0,Y0 and end coordinates (also the starting coordinates of link 2) X1,Y1.
  • Similarly, the second link has coordinates X1,Y1 and X2,Y2.
  • Both the links l1 and l2 are making an angle of Ɵ1 and Ɵ2 with the x-axis respectively.
  • To run an animation of forward kinematics of the given arm, a set of angles to both the links is provided in the form of arrays using “linspace” command.
  • Both the links move from 0-degree angle to 90-degrees angle.
  • Using geometry, the values of the coordinates X1,Y1 and X2,Y2 are calculated, i.e. X1 = l1cos Ɵ1, Y1 = l1sin Ɵ1, X2 = l1cos Ɵ2, Y2 = l1sin Ɵ2.
  • By using ‘for’ loop, iterating the values of Ɵ1 and Ɵ2 in a loop for given number of times and storing them in assigned variables.
  • By using ‘plot’ ,‘axis’ and ‘pause’ commands, plotting graphs for l1 and l2 in the provided axes with a defined pause.
  • Providing title and legend names to the graph.
  • All figures are stored in a variable ‘M’.
  • To create a movie, using ‘movie’ command.
  • Saving the video file using ‘videofile’ command and providing the name for it.

Matab Code:

% Forward Kinematics of a 2R Robotic Arm

clear

close all

clc
 

%inputs

l1 = 1; 

l2 = 0.5;

 

% Providing an array of angles for each link

theta1 = linspace(0,90,20);

theta2 = linspace(0,90,20);

 
 

%Using nested for loop
 

ct = 1;  % counter
 
for i = 1:length(theta1)

    A = theta1(i);

   

  for j = 1:length(theta2)

    B = theta2(j);

 

 

% Co-ordinates

X0 = 0;

Y0 = 0;                 % Base co-ordinates of link1

X1 = l1*cosd(A);

Y1 = l1*sind(A);        % Final co-ordinates of link1

X2 = X1 + l2*cosd(B);

Y2 = Y1 + l2*sind(B);   % Final co-ordinates of link2

 


% Plotting

plot([X0 X1],[Y0 Y1],[X1 X2], [Y1 Y2], 'linewidth', 3);

axis([-1,2,0,2]);

title ('2R Robotic Arm')

legend('Link 1','Link 2')

pause(0.01);

M(ct) = getframe(gcf);   % Assigning all images to one variable 

ct = ct+1;
 
  end

end

 

% Creating movie file

movie(M)

videofile = VideoWriter('2R_Robotic_Arm.avi','Uncompressed AVI');

open(videofile)          % To open the video file.

writeVideo(videofile,M)  % Writing the video file with frames from M array

close(videofile)         % To close the video file

Conclusion:

The code runs smoothly and depicts the movement of the robotic arm as shown in the video.

No erros were found during the exection of code.

Video Link:

https://drive.google.com/file/d/1OiRRe_9Evn0-ZSeu0e6AFLXwS_7rbFCQ/view?usp=sharing

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.