Project

Matlab program to simulate forward kinematics of a 2R Robotic Arm

Introduction

A robotic arm is a mechanical arm (with 2 or more links) which can be programmed to do a particular function similiar to human hand. The function can be painting, welding,polishing,wrapping and a lot more. It's prominent application is seen in automotive field, mainly in body welding and painting.

Aim:

Visualize the motion of a 2R robotic arm using Matlab program.

Explanation

Theta1 represents the angle which the first link makes with the base and theta2 represents the angle which the second link makes with the horizontal. The range of angle is from 0 to 90 degrees with 18 degree steps. The initial length of the primary and secondary arms were set as 1m and 0.6m respectively. Values were assigned to the x and y coordinates using proper equations and a nested for loop with a plot command inside was used to plot b/w the coordinates.

Errors

Above shown error was encountered while running, where it displayed all the possible motions of the arms in one single frame which made it hard for visualization. The error was fixed using a hold off command.

Matlab Program

clear all
close all
clc
%Program for Forward Kinematics of 2R Robotic Arm
%Defining Length of arms
l1=1;
l2=0.6;
%Defining angles b/w the arms
theta1=0:5:90;
theta2=0:5:90;
flag=1;
%Using Nested for loop
for(i=1:length(theta1))
    
x1=l1*cosd(theta1(i));
y1=l1*sind(theta1(i));

  for(j=1:length(theta2))
        
x2=x1+l2*cosd(theta2(j));
y2=y1+l2*sind(theta2(j));

%Plotting the coordinates
plot([0,x1],[0,y1],'linewidth',2,'color','r')
hold on;
plot([x1,x2],[y1,y2],'linewidth',2,'color','b')
hold off;
%Redefining Axis
axis([-0.5 2 0 2])
pause(0.02)
Movie_Array(flag)=getframe(gcf);
flag=flag+1;
    end
end
%Creating Movie
movie(Movie_Array)
videofile=VideoWriter('forward_kin.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,Movie_Array)
close(videofile)
%End Of Program

Result:

All the possible motions of the mechanism was visualized. The possible reach of the mechanism was analysed using animation created from the series of plots.

Animation link: https://youtu.be/wbw_ZU3XatY

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.