Forward kinematics of a 2R Robotic Arm in MATLAB
Aim:
To simulate the forward kinematics of a 2R Robotic Arm in MATLAB.
Introduction:
Robot Kinematics
Robot kinematics applies geometry to the study of the movement of multi-degree of freedom kinematic chains that form the structure of robotic systems. The emphasis on geometry means that the links of the robot are modeled as rigid bodies and its joints are assumed to provide pure rotation or translation.
Robot kinematics studies the relationship between the dimensions and connectivity of kinematic chains and the position, velocity and acceleration of each of the links in the robotic system, in order to plan and control movement and to compute actuator forces and torques.
The robot kinematics can be divided into forward kinematics and inverse kinematics. Forward kinematics problem is straightforward and there is no complexity deriving the equations. Hence, there is always a forward kinematics solution of a manipulator. Inverse kinematics is a much more difficult problem than forward kinematics. The solution of the inverse kinematics problem is computationally expansive and generally takes a very long time in the real time control of manipulators. Singularities and nonlinearities that make the problem more difficult to solve.
Program:
%robotic arm challege
clear all
close all
clc
%input
l1 = 1.2; %length of the link 1
l2 = 0.8; % length of the link 2
% angles for the arm from o° to 90°
theta1 = linspace(0,90,20);
theta2 = linspace(0,90,20);
ct=1;
%for loop function
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
x0 = 0;% starting co-ordinates for x-axis
y0 = 0;% starting co-ordinates for y-axis
x1 = l1*cosd(THETA1);%link 1 co-ordinates for x-axis
y1 = l1*sind(THETA1);%link 1 co-ordinates for y-axis
x2 = x1+l2*cosd(THETA2);%link 2 co-ordinates for x-axis
y2 = y1+l2*sind(THETA2);%link 2 co-ordinates for y-axis
%plotting
plot([x0,x1],[y0,y1],[x1,x2],[y1,y2],'linewidth',3);
axis([-0.5 2.5 0 2.5])%plot values for x axis and y axis
pause(0.05) %pause time for each frame
xlabel('Along the X axis(m)'); ylabel('Along the Y axis(m)');
M(ct) = getframe(gcf);% frames for the animation video
ct=ct+1; % increment for frame
end
end
movie(M)
vidfile = VideoWriter('forward_kinematics.avi');
open(vidfile)
writeVideo(vidfile,M)
close(vidfile)
Explanation of the Program:
l1 = 1.2m [ Length of the link 1 ]
l2 = 0.8m [ Length of the link2 ]
theta1 = 0° to 90° [angle range for link 1 with 20 interval]
theta2 = 0° to 90° [angle range for link 2 with 20 interval]
linspace: This function generates linearly spaced vectors.
[X0 Y0], [X1,Y1],[X2 Y2] are the coordinates along the x-axis & y-axis for the link1 and link2.
for loop function : A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
M(ct) function is used to get the frame.
Vidfile: It defines the name & format of the video.
Animation file of the Plot generated from the program: