Robotic Arm
Objective: To Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm.
Code:
% Forward Kinematics
clear all
close all
clc
% Inputs
prompt = 'Enter the Length of Arm 1 : ';
l1 = input(prompt);
prompt = 'Enter the Length of Arm 2 : ';
l2 = input(prompt);
theta1 = linspace(0,90,20);% Angle between Pivot point & Link1
theta2 = linspace(0,90,20);% Angle between Link1 & Link2
ct=1;
for i = 1:length(theta1)
temp_t1 = theta1(i);
for j = 1:length(theta2)
temp_t2 = theta2(j);
% Coordinates
x0 = 0;%Position of Pivot Point & Link1 - Lower End
y0 = 0;%Position of Pivot Point & Link1 - Lower End
x1 = l1*cosd(temp_t1);%Position of Link1 - Upper End & Link2 - Lower End
y1 = l1*sind(temp_t1);%Position of Link1 - Upper End & Link2 - Lower End
x2 = x1 + l2*cosd(temp_t2);%position of Link2 - Upper End
y2 = y1 + l2*sind(temp_t2);%position of Link2 - Upper End
%Plot
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',5)
axis ([-1 15 0 15])
%pause(0.01)
M(ct) = getframe(gcf);
ct=ct+1;
end
end
movie(M)
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Animation File Link: Here