Challenge

Week 2- 2R Robotic Arm Challenge

% Writing code to show the forward kinematics of 2R robotics arm
close all
clear all
clc

% Inputs for the arm
L1 = 2;                     % length of link 1
L2 = 1;                     % length of link 2
theta1 = linspace(0,90,10); % Angle made by link 1 with horizontal
theta2 = linspace(0,90,10); % Angle made by link 2 with horizontal

% applied input in 'for loop' for successful compilation of code
ctr = 0;
for i = 1:length(theta1) 
    THETA1 = theta1(i);
    for j = 1:length(theta2)
        THETA2 = theta2(j);
        x0 = 0;
        y0 = 0;
        x1 = L1*cosd(THETA1);
        y1 = L1*sind(THETA1);
        x2 = x1 + L2*cosd(THETA2);
        y2 = y1 + L2*sind(THETA2);
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'LineWidth',3)
        axis([-0.1 3.1 -0.1 3.1]);
        ctr = ctr +1;
        pause(0.15);
        M(ctr) = getframe(gcf);   % Capturing all loop values as frames and Storing in M vector
    end
end

% creating animation video
movie(M)
robotic_arm = VideoWriter('Animation Video.avi','Uncompressed AVI');
open(robotic_arm)
writeVideo(robotic_arm, M)
close(robotic_arm)



Above code is programmed to understand how a forward kinematic robotic arm moves to pick or drop any object.

Here we have animated the robotic arm using MATLAB movie tool, for which, we kept on loop the angular displacement of link w.r.t x-axis anticlockwise.

To start with, we have to provide inputs of arms like Length of both links (L1 and L2) and a range of values of angle made by links w.r.t x-axis,(theta1 and theta2) which are developed equally spaced using linspace command.

Now comes the loop part of programming. We used 'for' loop for link 1 which is attached to base at one end, then inside that loop before the link 1's position get changed another 'for' loop is introduced so that, now, for link 2 ,whose one end is attached link 1 and other is free, all possible positions are covered. After that loop will end for link 2 then it will shift to next value in loop for link, it will again to the for loop for link and perform similar actions.

All these values are being captured in 'M' as a frame for animation using 'getframe(gcf)' command.

To develop an animation 'movie(..)' command is used then to perform the action related to naming the video file, format and opening, writing and closing video file using commands VideoWriter, writeVideo, open(...) and close(...).

Drive Link:

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

Youtube Link:

https://youtu.be/xUhr7uhbDlA

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.