Project

2R Robotic Arm Simulation

In this project, a robotic arm with 2 links and 2 revolute joints are made and simulated in Matlab. The Matlab program will give an animation file of simulation of the 2R robotic arm as an output. Matlab code for same is attached below-

%This program is to simulate 2R robotic arm and gives video file as output
close all
clear all
clc

%inputs
l1 = 2;  %length of first link
l2 = 1.5;   %length of second link
theta1 = linspace(0,90,10); %array of angles for variation in first joint angle theta 1 
theta2 = linspace(0,90,10); %array of angles for variation in second joint angle theta 2

%coordinates of joint 1 where link 1 is connected with ground
x0 = 0; 
y0 = 0;

ct = 1;
for i = 1:length(theta1)
    THETA1 = theta1(i);
    for j = 1:length(theta2)
        THETA2 = theta2(j);
        
        %coordinates of joint 2 where link 2 is connected with link 1 
        x1 = l1*cosd(THETA1);
        y1 = l1*sind(THETA1);
        
        %coordinates of end effector or free end of link 2
        x2 = x1 + l2*cosd(THETA2);
        y2 = y1 + l2*sind(THETA2);
        
        %plotting
        plot([x0 x1], [y0 y1], [x1 x2], [y1 y2], 'linewidth', 3)
        axis([0 3.5 0 3.5]) 
        pause(0.03)
        M(ct) = getframe(gcf); %collecting plotted frames into an array
        ct=ct+1; %counter for frame array
    end
end

movie(M) %making movie or continues file form of M from frame array
videofile = VideoWriter('FWD_kinematics_2R_arm', 'Uncompressed AVI'); %defining videofile

%putting frames into videofile
open(videofile)
writeVideo(videofile,M)
close(videofile)

Working of code - The comments in the Matlab code will explain each and every variable we are using. In this program, 10 value is assigned to each of the joint angles which varies from 0 to 90 degrees. This program will take an angle of joint 1 and then it will take an angle of joint 2 and then it will calculate the position of joint 2 and the free end of the link 2 which is the end effector of the robotic arm. After that, it will plot the robotic arm. This is done for each pair of joint angles present in the array.

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.