Forward kinematics of a 2R robotic arm
AIM:
Matlab program to simulate the forward kinematics of 2R robotic arm.
OBJECTIVE:
To trace out the final position of the manipulator or end effectors of a 2R robotic arm by creating an animation.
PROJECT THEORY:
As kinematics refers to the analysis of motion without the consideration of forces. Forward kinematics means to find out the position of end efforts or manipulator of a robot with the help of kinematics equation of that particular robot, but for that geometry of the robot is required for mathematical calculations which in turn help to trace the position of manipulator.
PROJECT SETUP:
Figure: 2R robotic arm
Here, in this robotic arm there are 2 links, the one end of the link1 is attached to the base and other is to the one end of the link2, and the link2 is further connected to the manipulator.
Geometry:
The angle of lin1and link2 with the horizontal is θ1 and θ2 respectively.
Length of the link 1 = L1
Length of the link 2 = L2
The one end of the link1 (x0,y0) = (0,0)
Hence x1 = L1*cosd(θ1)
y1 = L1*sind(θ1)
so,
x2 = x1 + L2*cosd(θ2)
y2 = y1 + L2*sind(θ2)
so, by this way value of x2 and y2 can be calculated which tells the position of end efforts.
To creat the animation of the 2 links different value of angles is required during programming.
PROGRAMING LANGUAGE USED:
Matlab programming is used to make the video of robotic arm.
CODE USED TO PLOT THE ARMS:
close all
clear all
clc
%inputs
theta1 = 45; % link1 angle with horizontal
theta2 = 30; % link2 angle with horizontal
L1 = 1; % length of link1
L2 = 0.5; % length of link2
% starting point position of link one
x0 = 0;
y0 = 0;
% end point of link1
x1 = L1*cosd(theta1);
y1 = L1*sind(theta1);
% end point of link1 and starting point of link2 is same
% end point of link2
x2 = x1 + L2*cosd(theta2);
y2 = y1 + L2*sind(theta2);
line([x0 x1],[y0,y1],'color','b','linewidth',3)
line([x1 x2],[y1 y2],'color','r','linewidth',2)
OUTPUT:
so, by changing the value of theta different arm position can be plotted
CODE USED TO CREAT ANIMATION:
close all
clear all
clc
%inputs
theta1 = linspace(0,90,10); % link1 angle with horizontal
theta2 = linspace(0,90,10); % link2 angle with horizontal
L1 = 1; % length of link1
L2 = 0.5; % length of link2
% starting point position of link one
x0 = 0;
y0 = 0;
%frame
ct =1;
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
% end point of link1
x1 = L1*cosd(THETA1);
y1 = L1*sind(THETA1);
% end point of link1 and starting point of link2 is same
% end point of link2
x2 = x1 + L2*cosd(THETA2);
y2 = y1 + L2*sind(THETA2);
plot([x0 x1],[y0,y1],[x1 x2],[y1 y2],'linewidth',3)
axis([-0.1 1.7 0 1.7])
pause(0.07)
M(ct)= getframe(gcf);
ct = ct +1;
end
end
% creating video
movie(M)
videofile = VideoWriter('forwardkinematics.avi');
%for opening the video
open(videofile)
writeVideo(videofile,M)
close(videofile)
Explanation of the code:
- length of the both links is defiend firtst.
- Different values of the theta angle is taken by using linspace command.
- The value of c_t shows the frame number which is taken as 1 and increased by one on every iteration of the loop.
- By using the for loop all the value of angle theta is used to plot the figure and second for loop is used to give multiple value of theta 2 for given values of theta 1.
- Movie and getframe command help to creat the video file of the output.
ERRORS FACED:
While running the program two type of errors were faced.
- After using the foor loop I forgot to put the original theta in the equations which I defiend in starting (theta1,theta2) instead of new defiend variable (THETA1 and THETA2). so while running the program the following output has been genrated.but soon i figured it out.
- After removing the above error , another error was waiting in the qeue. it was about the videowriter command as the matlab is a case sensitive language it shows the following error when i wrote ' videowriter ' instead of ' VideoWriter'. but matlab is smart enough to notifiying me about this error.
OUTPUT:
This is the youtube video link of my output:-