Project

2R robotic arm simulator using MATLAB

Aim:

To analyse and simulate the 2R robotic arm using MATLAB. The movement of the robotic arm is to represented in a video.

Procedure:

  • Initially, the length of the two links are assinged as input in the program.
  • Then, a counter variable 'a' is assigned.
  • The theta value of the two links, which indicated the position of the links are assigned.
  • The various theta values are assigned in an array using 'linspace' command.
  • The two angles of the two links are assigned in theta1 and theta2.
  • Using for loop, till the end value of theta1 the values are stored in a new variable called angle1.
  • Using nested for loop, the theta2 values are stored in a new variable called angle2.
  • The intial position of the link1 is assigned as zero. (x0=0,y0=0)
  • The final position of the link1 is obtained by solving the horizontal and vertical components of the link1 based on the angle values.
  • The final position of link1 is given as x1=l1*cosd(angle1) and y1=l1*sind(angle1).
  • For the link2 the values obtained from calculating x1 and y1 is taken as its initial position.
  • The fnal position of the link 2 is also obtained by solving the horizontal and vertical components.
  • The final position of the link2 is given by x2=x1+l2*cosd(angle2) and y2=y1+l2*sind(angle2).
  • Thus, the position of the link1 and link2 is obtained.
  • The 'Plot' command is used to plot the links of the robotic arm.
  • Using the counter variable 'a', all the frames of the plot are stored.
  • All the frames are stored in the 'M' variable for creating video.
  • The movie is formed using 'Movie' command.
  • Then, using videofile command the name and the format of the video is assigned.
  • Then, open that video file, write the content on it and it is closed.

Errors faced during program:

I had faced some problems while typing commands in the MATLAB. The uppercase and lowercase representation of various commands are bit hard to initialize. I have attached one among the errors faced during programming.

Errors solving:

The errors are solved using correct uppercase and lowercase representation.

Source code:

clear all
close all
clc

%Input
%Length of the link
l1=1;
l2=0.5;
%Counter variable
a=1;
%Theta value
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);

%function
for i=1:length(theta1)
    angle1=theta1(i);
    for j=1:length(theta2)
        angle2=theta2(j);
        x0=0;
        y0=0;
        
        x1=l1*cosd(angle1);
        y1=l1*sind(angle1);
        
        x2=x1+l2*cosd(angle2);
        y2=y1+l2*sind(angle2);
        
        %Ploting
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],"linewidth",3)
        axis([0 1.5 0 1.5])
        pause(0.1)
        M(a)=getframe(gcf)
        a=a+1;
    end
end
%Video making.
movie(M)
videofile=VideoWriter('2R_robotic_arm_Forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

Output:

The output video was uploaded on the youtube and its link is attached below.

https://youtu.be/FAVSDUTHtZ4

The various output images of the different position of links are attached below.

Conclusion:

Finally, The 2R robotic arm simulator is made using MATLAB.

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.