Challenge

Week 2- 2R Robotic Arm Challenge

Aim : Write a code in Matlab to simulate the Forward kinematics of a 2R Robotic Arm.

Objective : In this challenge we learn how to find diffferent angle or conditions robotic arm coordinate. i.e. we simulate degree of freedom of arm & also find their coordinates according to its angle & creat a animation file by using various Matlab commands.

Description :

Here we write a code for 2R robotic arm & create animation video.

inputs

select link length

link1 = L1= 0.8m

link2 = L2=0.6m

after selecting link length we define angle here is we simulate the forward kinematic of 2R robotic arm for different angle so we select 0 to 90 degree in matlab 'd' represent degree so after sin and cos we noted d (sind & cosd) otherwise result get in radiant θ symbol not insert in code so we insert as theta in the code we get different angle 0 to 90 , 10 values it is represent as shown

theta1 = linspace(0,90,10)

theta2 = linspace(0,90,10)

so we get two angle for two links we select same value for two links.

after that we select initial coordinates

x0 = 0

y0 = 0

done this input & type as per matlab coding language

After that we used 2 for loop for two angle selection theta1 & theta2 & put this value in formula for finding length of link.

by used i & j variable complete the for loop as shown in below

for i = 1:length(theta1)

THETA1 = theta1(i)

for j = 1:length(theta2)

THETA2 = theta2(j)

here we find x1 , x2 & y1 y2

Formula :

link 1 x & y coordinate

x1 = L1*cosd(THETA1)

y1 = L1*sind(THETA1)

Link2 x & y coordinates

x2 = x1 + L2*cosd(THETA2)

y2 = y1 + L2*sind(THETA2)

for link two we only change just add x1 & y1 values

After complete above all things we using plot command & creat a animation & also used videowriter command & save video.

plot([x0 x1],[y0 y1],[x1 x2],[y1 y2], 'linewidth' ,3)

axis([([-1 1 0 1.5])
pause(0.03);
M(ct) = getframe(gcf)
ct=ct+1;
end

end

by using two end we close both for loop . After that tyoe code for saving video file in '.avi' format.

movie(M)
videofile = VideoWriter('robotic_arm.avi','Uncompressed AVI')
open(videofile);
writeVideo(videofile,M)
close(videofile);

Code Details :

clear all
close all
clc

% Robotic arm two link

% inputs
% select link length
L1=0.8;
L2=0.6;
theta1 = linspace(0,90,10)
theta2 = linspace(0,90,10)

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

ct = 1;
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);
        
        
        %plotting
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
        axis([-1 1 0 1.5])
        pause(0.03);
         M(ct) = getframe(gcf)
         ct=ct+1;
    end
    
    end
    
movie(M)
videofile = VideoWriter('robotic_arm.avi','Uncompressed AVI')
open(videofile);
writeVideo(videofile,M)
close(videofile);


        
        

Video link :

https://drive.google.com/file/d/1F9FA7-FB-uhBvufbyid5YtndKobgK3-s/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.