2R Robotic Arm Forward Kinematics
AIM: To simulate the forward kinematics of 2R Robotic Arm using MATLAB
OBJECTIVE: Write a program to solve forward kinematics of 2R Robotic Arm
THEORY:
A robotic arm is a type of mechanical arm, usually programmable. The arm may be whole of the mechanism or may be a part of a more complex robot. The links of such a manipulator are connected by joints allowing either rotational motion or translational displacement. The links of the manipulator can be considered to form a kinematic chain. The terminus of the kinematic chain of the manipulator is called the end effector. An end effector is the device at the end of a robotic arm, designed to interact with the environment.
Robot kinematics refers the analytical study of motion of a robot manipulator. Formulating the suitable kinematics models for a robot mechanism is very crucial for analyzing the behavior of industrial manipulators.
A manipulator is composed of series of links which are affixed to each other revolute or prismatic joints from the base frame through the end effector. Calculating the position and orientation of the end effector in terms of the joint variables is called forward kinematics. In order to have forward kinematics for a robot mechanism in a systematic manner, one should use a suitable kinematic model. Forward kinematics problem is straightforward and there is no complexity deriving the equations. Hence, there is always a forward kinematics solution of a manipulator.
PROCEDURE:
- Start programming in MATLAB with these three commands, as all the previous calculations are erased.
- clear: This command clears all the data stored in the workspace previously.
- close all: This command closes all the previous figures and plots.
- clc: This command clears the command window.
- Now give inputs for length of link 1 (l1) as 1 meter and link 2 (l2) as 0.5 meter, theta 1 (theta1) and theta 2 (theta2) as a range from 0 to 90 degrees, ‘linspace’ command is used for providing equal gap points within the range.
- Now ‘for’ loop is used for calculating the x and y coordinates of link 1 and link 2. As ‘theta1’ and ‘theta2’ are arrays and contains multiple values of angle with x-axis therefore, we need another variable which stores only one valve at a time so that we can get a set of x and y coordinates that are different that is why two variables are defined for theta 1 and theta 2 that are ‘THETA1’ and ‘THETA2’.
- Now coordinates for starting point of link 1 is defined.
- Then the coordinates of end points of link 1 or the coordinates of starting point of link 2 is defined. Here ‘cosd’ and ‘sind’ is used so that the values are stored in degrees.
- Now the coordinates of end point of link 2 is defined in which there is a use of coordinates of end points of link 1.
- Now plotting of all the points is done using the ‘plot’ command having a linewidth of 3 units. The command used for differentiating the two links is ‘legend’ which helps us to determine the links with color. The labeling of x-axis and y-axis is done with the use of ‘xlabel’ command and ‘ylabel’ command. A pause command is used for pausing the program for a certain time before processing a new set of values.
- Now for creating a movie or an animation of the results a counter variable is defined before the first ‘for’ loop command as ‘ct’ and then a variable ‘M’ for capturing the current frame every time the ‘for’ command runs. Then for the increment of the frame ‘1’ is added to the variable ‘ct’. After all this both the ‘for’ loop are ended. Now for creating a complete movie a command named ‘movie’ is used and then fro assigning the file name and file format ‘VideoWriter’ command is used, the format used here is ‘.avi’. Then for opening the video file ‘open’ command is used and then ‘writeVideo’ command is used which writes the video with plot frames. After this with the use of ‘close’ command the video file is closed.
- Save the program in the desired folder and then run the program by using a shortcut key i.e. ‘F5’ key or it can also be done with the option present in the top bar. After the successful running of the program an animation can also be seen running and this animation is saved in the format that you have assigned in the folder in which the program file is saved.
CODE:
% Forward Kinematics of a Robotic arm
clear
close all
clc
%Inputs
l1 = 1; %length of link 1
l2 = 0.5; %length of link 2
theta1 = linspace(0,90,20); %angle between x-axis and link 1
theta2 = linspace(0,90,20); %angle between x-axis and link 2
ct = 1;
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
%coordinates for starting point of link 1
x0 = 0;
y0 = 0;
%coordinates for end point of link 1 and also the starting point of
%link 2
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
%coordinates for ending point of link 2
x2 = x1 + l2*cosd(THETA2);
y2 = y1 + l2*sind(THETA2);
%Plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],"LineWidth",3)
axis([-0.1 1.8 0 1.8])
legend('Link1','Link2')
xlabel('x-axis')
ylabel('y-axis')
pause(0.01)
%for creating the animation
M(ct)= getframe(gcf);
ct = ct+1; %increment of frame
end
end
movie(M) %creates a movie
videofile = VideoWriter("robotic_arm_kinematics.avi",'Uncompressed AVI'); %assigns the file name and file format
open(videofile) %opens the videofile
writeVideo(videofile,M) %writes the video with plot frames
close(videofile) %closes the videofile
ANIMATION: 2R Robotic Arm Forward Kinematics
CONCLUSION:
Thus to simulate and animate the forward kinematics of 2R robotic arm using MATLAB has been done and with this we can see the workspace of the manipulator.