Challenge

Week 2- 2R Robotic Arm Challenge

https://youtu.be/z8hmmh6ynDs

clear all
close all
clc
% program to simulate forward kinematics of 2R robotic arm

% Assuming the values of length of the links of robot in metre 
l1=1;
l2=0.5;

% assigning possible angle of inclination of link 1 with horizontal surface 
theta1=0:20:180;

% assigning possible angle of inclination of link 2 with horizontal surface 
theta2=0:15:90;

% assigning theta3 to obtain angle of rotation in opposite direction when
% link 1 rotates at an angle greater than 90 degree
theta3=90:15:180;

% Using for loop to acessing each values of theta and assigning them to
% matrices THETA1 and THETA2

ct=1;

for i=1:length(theta1)
    THETA1=theta1(i);

    if THETA1<=90

        for j=1:length(theta2)
               THETA2=theta2(j);

             % the initial starting point of link 1 is assigned as x0 and
             % y0 corresponding to coordinates (0,0)
                 x0=0;
                 y0=0;

             % the end points of the link 1 is assigned as (x1,y1) which also
             % corresponds to starting point of link 2
                 x1=l1*cosd(THETA1);
                 y1=l1*sind(THETA1);

             % the end points of the link 2 is assigned as (x2,y2) 
                 x2=x1+(l2*cosd(THETA2));
                 y2=y1+(l2*sind(THETA2));

             % plotting the graph of link 1 and link 2 simultaneously at different
             % possible angle inclinations

             % the coordinate (x4,y4) and (x5,y5) are taken to illustrate
             % a base table or a base pivot

                 x4=-0.1;
                 y4=0;

                 x5=0.1;
                 y5=0;


             plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],[x4 x5],[y4 y5],'LineWidth',3)
             legend('LInk1','Link2','Base','Location','south')
             axis([-2.5 2.5 -2.5 2.5])
             pause(0.8)

    % Saving the frames obtained to array M to create movie         
    M(ct)=getframe(gcf)
    ct=ct+1;

        end

        % if angle of rotation of link 1 rotates beyond 90 degree, link 2
        % rotates through 90 to 180

    else

        for k=1:length(theta3)
            THETA3=theta3(k);

              % the coordinate (x6,y6) corresponds to coordinates(0,0)
         
              x6=0;
              y6=0;

              % the coordinate (x7,y7) corresponds to end point of link 1
              % and the starting point of link2

              x7=l1*cosd(THETA1);
              y7=l1*sind(THETA1);

              % the coordinate (x8,y8) corresponds to end point of link 2

              x8=x7+(l2*cosd(THETA3));
              y8=y7+(l2*sind(THETA3));

              %plotting the graph of link 1 and link 2 simultaneously at different
              % possible angle inclinations

              % the coordinate (x9,y9) and (x10,y10) are taken to illustrate
              % a base table or a base pivot

              x9=-0.1;
              y9=0;

              x10=0.1;
              y10=0;

              plot([x6 x7],[y6 y7],[x7 x8],[y7 y8],[x9 x10],[y9 y10],'LineWidth',3)
        
              legend('LInk1','Link2','Base','Location','south')
              axis([-2.5 2.5 -2.5 2.5])
              pause(0.8)

    % Saving the frames obtained to array M to create movie          
    M(ct)=getframe(gcf);
    ct=ct+1;

        end

    end
    
end

movie(M);
Videofile=VideoWriter('kinematics.AVI','Uncompressed AVI');
Videofile.FrameRate=10;
open(Videofile)
writeVideo(Videofile,M)
close(Videofile)

%errors encountered
% 1. output video format was too fast, so introduced framerate to obtain a
% smoother video. 
% 2. The get frame had to be used inside both for loops, under if and else
% conditions, to obtain the plot. Encountered error where it said M value
% changes every time, when it was added only inside the first for loop.



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.