Simulation of Forward Kinematics of a 2R Robotic Arm using MATLAB
Aim:
To simulate the forward kinematics of a 2R robotic arm using Matlab.
Description:
1.Forward Kinematics:
Forward kinematics is the use of kinematic equations to control the positions of the end-effector for the values of the joint parameters.
2.2R Robotic Arm:
The arms of the robots which have 2 rotational arms is known as the 2R Robotic Arm.
3.Coordinates of Robotic Arm:
The coordinates of robotic arm is the angles at which the arm of the robots work (i.e) in respond to the x,y and z axis.
θ1 - Angle of the arm 1
θ2 - Angle of the arm 2
Program:
%Forward Kinematics of a 2R Robotic Arm
% Inputs
l1 = 1;
l2 = 0.5;
theta1 = linspace(0,90,10);
theta2 = linspace(0,135,10);
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',5)
axis([-1.0 2.0 0 2.0])
pause(0.03)
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)
Output: https://youtu.be/GyvBD3BJgIg
Report of the Program:
The program starts by providing the inputs of the values that are necessary to run the forward kinematics of the 2R robotic arm. The length of the arm1 and arm2 are given as 1m and 0.5m. The angle at which the arms of the robot works are given as 'theta1' and 'theta2'. In this program the arm1 is given the command to work from 0°to 90° and the arm2 is given the command to work from 0° to 135°. To run the arm of the robot at various angles the 'for' loop command is used to program the arm. The counter is introduced as 'ct' which works in plotting the way the arm of the robot works. In the for loop a integer 'i' is used to give the angle at which the arm1 works and another integer 'j' is used to give the angle at which the arm2 works. In order to plot the working of the arm command 'plot([x0 x1], [y0 y1],[x1 x2], [y1 y2])' is used which indicates the position of the arm of the robot. The axis at which the arm works will have to be specified to get the complete working of the robotic arm. The command such as 'M(ct) = getframe(gcf)' is used to capture each frames of the robotic arm working in order to make a video of the robots operation. The movie of the operation of the robotic arm is made by using the defined statements which is carried after the end of the for loop. The Matlab being case sensitive even a small error in that program will make the failure of the video.