2R Robotic Arm Challenge
A program for simulate the forward kinwmatics of 2R robotics arm.
Program :-
% Forward Kinematics of a 2R robotic arm manipulator multiple animated.
% Inputs
% Length of links
l1 = 1;
l2 = 0.5;
% Angle of both links with horizontal axis
theta1 = linspace(0,90,20);
theta2 = linspace(0,90,20);
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',4);
axis([-0.1 1.5 0 1.5]);
grid on
title('Kinematics of 2R Robotics arm');
xlabel('Arm movement in x-axis');
ylabel('Arm movement in y-axis');
M(ct)=getframe(gcf);
ct = ct + 1;
end
end
movie(M)
videofile = VideoWriter('Forward_Kinematics.avi');
open(videofile)
writeVideo(videofile,M)
close(videofile)
In these first of all we will provide all the inputs which are required.
%Length of the links
l1=1;
l2=0.5;
% Angle
theta1=linspace(0,90,20);
theta2=linspace(0,90,20);
The linspace command is used to generate 20 values for theta in between 0 to 90 degrees.
To make it automatic we are using forloop function.
for i = 1 : lenght(theta1)
Value of 'i' will change from 1 to length(theta1), lenght(theta1) nothing but all the 20 theta values between 0 to 90 which is generated by using linspace command.
THETA1 = theta1(i);
THETA1 is a variable where theta1 is an array.'i' is loop counter which shows how many times forloop get execuated.for each value of theta1, theta2 will change 20 positions, so that's why second forloop is required.
for j = 1 : lenght(theta2)
THETA2 = theta2(j);
Then we have to provide points, so that the equation can be calculated.
x0 = 0;
y0 = 0;
x1 = l1*cosd(THETA1);
y1 = l1*sind(THEAT1);
x2 = x1 + l2*cosd(THEAT2);
y2 = y1 + l2*sind(THETA2);
After that we will use plot command to plot the following calculated values.
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',4);
The axis command is used for fixing the work area in the graph.
axis([-0.1 1.5 0 1.5]);
The title command is use to give the title to graph.
title('Kinematics of 2R Robotics arm');
The lable command is use for specify the name of x & y axis in the plot.
xlabel("Arm movement in x-axis');
ylabel("Arm movement in y-axis');
M(ct) = getframe(gcf);
By these command we will first save every frame in a variable called as 'M' & by using the getframe it can execuated.
ct = ct + 1;
Increment forloop execuation.
movie(M)
videofile = VideoWriter('Forward_kinematics.avi');
open(videofile)
Writevideo(videofile,M)
close(videofile)
This commands are used to create the movie for output of graph which is obtain by running these program and to save in the hard drive.
After generating animation file, the link is given below
https://drive.google.com/file/d/1wtbVyoArcIv_JaaCrih1I2pCci-wTtOH/view?usp=sharing