Project

Simulation of 2R Robotic Arm using MATLAB

AIM: To create the simulation of forwarding kinematics of a 2R Robotic Arm

GOVERNING EQUATIONS: Basic trigonometry and math skills.

OBJECTIVES OF THE PROJECT: The main objective of this project is to create the simulation of the forwarding kinematics of a 2R Robotic Arm using simple math functions like plot and with the help of for loop.

%I have created this in MATLAB ONLINE

% Program to simulate the forward kinematics of a 2R Robotic Arm

%input parameters
% Initilise the lengths of the input links l1 & l2
l1=3;
l2=1.5;
%create a row vectors of theta1 & theta2
%Linearly spaced vector
% LINSPACE(X1, X2, N) generates N elements between X1 and X2
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);

ct=1;

%FOR    Repeat statements a specific number of times
%use the for loop to assign different values to THETA1 & THETA2 
for i=1:length(theta1)
    THETA1=theta1(i);
    for j=1:length(theta2)
        THETA2=theta2(j);

%co-ordinates
x0=0;
y0=0;

x1=l1*cosd(THETA1);
y1=l2*sind(THETA1);

x2=x1+l2*cosd(THETA2);
y2=y1+l2*sind(THETA2);

%  Linear plot
%   PLOT(X, Y) plots vector Y versus vector X.

plot([x0  x1],[y0  y1],[x1 x2],[y1 y2],'linewidth',3)
%add the title that apt for figure
title('Simulation of a 2R Robotic Arm')
%set the limits of axes for easy analysis
axis([-0.1 4.5 0 4]);
legend('link1','link2');
    pause(0.001)
    M(ct)=getframe(gcf);
    ct=ct+1;
   
    end
end
%function movie  Plays recorded movie frames
movie(M)
%Use a VideoWriter object to create a video file
v = VideoWriter('forward_robotic_arm.avi',' uncompressed AVI');
%Open file for writing video data
open(v)
%Write video data to file
writeVideo(v,M)
%Close file after writing video data
close(v)

https://youtu.be/x846Pk71OUk

%EXPLANATION

  • To start with this program initially we should have an idea about basic trigonometry and also about coordinates of specific points in the cartesian plane
  • the position of the links are sorted out by knowing the coordinates of end and start point of the links
  • so after keeping this in mind, assign specific lengths to the links as desired.
  • create variables theta1 & theat2, assign values to these variables using linspace function
  • use for loop to iterate length(theta1 or theta2) times
  • set the coordinates by recalling basic math skills
  • make use of plot command to draw the graph
  • add title and set the axes length of your comfort
  • use pause or create a movie file to make an animation out of plots

% OUTPUTS

  • The animation is the result of playing captured frames continuously
  • pause: stops the animation for some seconds to get a clear view
  • The animation shows the workspace of the robotic arm

CONCLUSION

  • Better to use the installed version of Matlab than online version because I faced a problem in creating the animation file.
  • I also got errors which are most common for beginners but debugging helped me a lot.
  • In this project, we build the links based on the relative positions of the starting and ending points of the links
  • So we found that length of link1 gets reduced when compared to its initial length.
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.