2R Robotic Arm simulation using MATLAB
AIM
To simulate the position of end-effector of 2R Robotic Arm in 2D using MATLAB.
EQUATIONS
`"End-Effector Position "( X , Y )" Equation "`
`X = L_1*cos(\theta_1)+ L_2*cos(\theta_2)`
`Y = L_1*sin(\theta_1)+ L_2*sin(\theta_2)`
`where;`
`L_1" = Length of Arm 1"`
`\theta_1" = Angle of Arm 1"`
`L2" = Length of Arm 2"`
`\theta_2" = Angle of Arm 2"`
OBJECTIVES
Forward Kinematics:
The mathematical process to calculate the position of end-effector by using the angles of the robotic rotational joint arm.
Inverse Kinematics:
The mathematical process to calculate the angles of the robotic rotational joint arm by using the position of end-effector.
MATLAB PROGRAM
% program to plot 2d forward kinematic
close all
clear all
clc
% Inputs
% Length of Arm 1 in m
Arm_1_Length = 1;
% Length of Arm 2 in m
Arm_2_Length = 0.5;
% Angle of Arm 1 in degrees
Arm_1_Angle = 0:10:90;
% Angle of Arm 2 in degrees
Arm_2_Angle = 0:5:90;
% Figure Count
FigureCount = 1;
for i = 1:length(Arm_1_Angle)
theta1 = Arm_1_Angle(i);
for j = 1:length(Arm_2_Angle)
theta2 = Arm_2_Angle(j);
% Center (orgin) of robot
x0 = 0;
y0 = 0;
% Position of Arm 1 end
x1 = Arm_1_Length * cosd(theta1);
y1 = Arm_1_Length * sind(theta1);
% Position of Arm 2 end [--end-effector--]
x2 = x1 + Arm_2_Length * cosd(theta2);
y2 = y1 + Arm_2_Length * sind(theta2);
angle1Label=strcat('Angle= ', num2str(theta1), ' deg');
angle2Label=strcat('Angle= ', num2str(theta2), ' deg');
endEffectorPosition = strcat('X= ', num2str(x2), ' , ', 'Y= ', num2str(y2));
% Ploting
%figure(FigureCount);
%hold on;
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3,'marker','o','markerfacecolor','black');
text((x0+x1)/2,(y0+y1)/2,'Arm 1');
text((x1+x2)/2,(y1+y2)/2,'Arm 2');
text(x0,y0,angle1Label,'VerticalAlignment','bottom','HorizontalAlignment','left');
text(x1,y1,angle2Label,'VerticalAlignment','top','HorizontalAlignment','left');
text(x2,y2,endEffectorPosition,'VerticalAlignment','top','HorizontalAlignment','left');
axis([-0.5 2 0 2])
title('2R Robotic Arm Forward Kinematic');
xlabel('x-axis in m')
ylabel('y-axis in m')
grid on
pause(0.1)
M(FigureCount) = getframe(gcf);
FigureCount = FigureCount + 1;
end
end
movie(M);
videofile = VideoWriter('2D_Forward_Kinematics','Uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile);
close all
clear all
clc
EXPLANATION
Step 1: Length and angle of 2R robotic arm are given as input in MATLAB code directly.
Step 2: Starting position of the first rotational joint was fixed as origin `( X_0, Y_0 )`.
Step 3: Position of the first rotational joint was calculated using the formula below.
`(X_1, Y_1) = ( L_1 * cos(\theta_1),L_1 * sin(\theta_1))`
Step 4: Position of the second rotational joint was calculated using the formula below.
`(X_2 , Y_2) = ( X_1 + L_2 * cos(\theta_2), Y_1 + L_2 * sin(\theta_2))`
Step 5: In order to simulate the position of end-effector of 2R Robotic Arm as an animation, the angles of arms are varied form `0 \degree` to `90 \degree`
Step 6: Using "getframe()" captures the current axes (plot) as it appears on the screen as a movie frame into an array.
Step 7: Using "writeVideo()" writes data from an array to the video file.
RESULTS
CONCLUSION
A program for 2R Robotic Arm forward kinematic simulation was coded and simulated the position of end-effector in MATLAB plot as a video.