A MATLAB PROGRAM TO SIMULATE THE FORWARD KINEMATICS OF A 2R ROBOTIC ARM
AIM:
To create an animation of a 2R Robotic Arm.
DESCRIPTION:
A 2 R Robotic Arm is a device that performs a certain operation base on the manipulator attached at its end. The operation is performed by the program introduced.
To create a valid program, the programmer need to have basic knowledge about the kinematics of the links.
GOVERNING EQUATIONS:
`x_1= L_1 cos〖θ_1`
`y_1= L_1 sin〖θ_1 〗`
`x_2= x_1+ L_2 cos〖θ_2 〗`
`y_2= y_1+L_2 sin〖θ_2 〗`
where,
x0,y0 : initial coordinates, origin is taken
x1,y1 : end coordinates of link 1
x2,y2 : end coordinates of link 2
L1 : length of link 1
L2 : length of link 2
`Θ1 : angle made by link 1 with x-axis`
`Θ2 : angle made by link 2 with x-axis`

OBJECTIVE:
- To understand the kinematics of a 2R Robotic Arm.
- To write a program to crate an animation of Robotic Arm.
- To visualize the workspace of the manipulator.
- To visualize the workspace of the manipulator.
PROCEDURE:
- Declare all the variables and assign their respected values.
- Calculate the coordinates and plot the graph.
- Record each frame and merge them to form a movie.
- Store the animation in a videofile.
CODE EXPLANATION:
- Using linspace command the angles Θ1 and Θ2 are defined with 15 values ranging from 0 t0 90.
- Also the length of both arms and the base coordinates are taken as input
- The initial values of counter(ct) is taken as 1 and a for loop is created inside another for loop.
- Inside the loop for each values of angles the final coordinates of link 1 and link 2 are calculated.
- Now, 225 frames are created and each frame is stored in an array M(ct) which uses the getframe(gcf) command to store the current frames and ct is incremented in the inner loop foer each execution of the loop.
- The command movie is used to join each frame and a video file is create.
- The file is opened and closed using the open and close commands respectively.
- The writeVideo command is used to write the frames from M to videofile.
CREATING A MOVIE
Creating a movie type M(ct) = getframe(gcf) below the pause(0.03) and at extreme end command type movie (m).
Counters are useful programming tools, they are used to keep track of how many times a command has been executed.ct represent every frame.
getfram : this command represent to getting the current figure in the gcf window.
MATLAB CODE TO SIMULATE THE FORWARD KINEMATIVS OF A 2R ROBOTIC ARM:
close all
clc
clear all
ct = 1;
% theta1 = angle between the horizontal and first arm
% theta2 = angle between the horizontal and the second arm
theta1 = linspace(0,90,15);
theta2 = linspace(0,90,15);
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
% Initial coordinates
x0 = 0;
y0 = 0;
% length of robotic arms of first and second link
l1 = 1;
l2 = 0.7;
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',3)
hold off
axis([-0.1 2 -0 2])
pause(0.0003)
% storing each frame into array
M(ct) = getframe(gcf);
ct = ct+1;
end
end
% joining each frame and making a movie
movie(M);
%creating a video file
videofile = VideoWriter('forward_kinematics.avi','uncompressed AVI')
open(videofile)
% writing the data to a video file
writeVideo(videofile,M)
close(videofile)
CODE EXPLANATION:
- Using linspace command the angles Θ1 and Θ2 are defined with 15 values ranging from 0 t0 90.
- Also the length of both arms and the base coordinates are taken as input
- The initial values of counter(ct) is taken as 1 and a for loop is created inside another for loop.
- Inside the loop for each values of angles the final coordinates of link 1 and link 2 are calculated.
- Now, 225 frames are created and each frame is stored in an array M(ct) which uses the getframe(gcf) command to store the current frames and ct is incremented in the inner loop foer each execution of the loop.
- The command movie is used to join each frame and a video file is create.
- The file is opened and closed using the open and close commands respectively.
- The writeVideo command is used to write the frames from M to videofile.
CREATING A MOVIE
Creating a movie type M(ct) = getframe(gcf) below the pause(0.03) and at extreme end command type movie (m).
Counters are useful programming tools, they are used to keep track of how many times a command has been executed.ct represent every frame.
getfram : this command represent to getting the current figure in the gcf window.
ERROR FACED
While creating the vedio file for animation of forward kinematics of 2R robotic arm texted small letter 'w' instead of capital letter 'W' mistakely for the term "VedioWriter".
As we know Matlab is very sensitive . A mynute error from our side will be treated as error by Matlab .
corrected using the capital letter W for the term 'VedioWriter' .

GOOGLE DRIVE LINK FOR ANIMATION OF 2R ROBOTIC ARM:
https://drive.google.com/file/d/1ewXgkfoMMwqWHtYWAE4VQa5ZPmJdOdEs/view?usp=sharing
CONCLUSION:
We have created an animated plot and a movie for 2R robotic arm using this program.