Simulation of the forward kinematics of a 2R robot arm using Matlab
Intoduction:
Forward kinematics refers to the use of the kinematic equations of a robot to compute the position of the manipulator or end-effector(eg.electrodes for welding) from the values of the lenghts of the joints and angle made by them. A 2R robot arm is a mechanism which contains 2 turning pairs i.e 2 links connected by a binary joint forming a lower pair. This project is about simulating the positions of the manipulator of a 2R robot arm using Matlab.
2R robot arm:
It is system wich has a degree of freedom 2 which means that the configuration of the system can be completely defined with the help of 2 parameters viz. the angles made by link 1(θ1) and link 2(θ2) with respect to the horizontal. The links are connected by a pin joint and move in a single plane i.e the system is a 2 dimensional one. Thus the position of the manipulator can be found if the lenghts of the links and the angles θ1 and θ2 are known. If the length of the link 1 is `L1` and that of link 2 is `L2`, and the coordinates of the pin joint and the manipulator are (`x1,y1`) and (`x2,y2`) respectively, then the positions of the pin joint and that of the manipulator is as follows
`x1=L1*cos θ1`
`y1=L1*sin θ1`
`x2=x1+L2*cos θ2`
`y2=y1+L2*sin θ2`
Plotting the values of `(x1,y1)` and `(x2,y2)` for different values of θ1 and θ2, we get the resulting animation as shown below in the conclusion.
Code:
clear all
close all
clc
%Inputs
theta1=linspace(0,90,15);
theta2=linspace(0,90,20);
l1=1;
l2=0.5;
x0=0;
y0=0;
k=1;
for i=1:length(theta1)
angle1=theta1(i);
x1=l1*cosd(angle1);
y1=l1*sind(angle1);
for j=1:length(theta2)
angle2=theta2(j);
x2=x1+l2*cosd(angle2);
y2=y1+l2*sind(angle2);
%Output
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2])
axis([-0.5 1.5 0 2])
pause(0.05)
A(k)=getframe(gcf);
k=k+1;
end
end
%Saving the results as a video
movie(A)
animation=VideoWriter('forward_kinematics.mp4','MPEG-4');
open(animation)
writeVideo(animation,A)
close(animation)
The code above is self explanatory and when it was run, the result as discussed below was obtained.
Conclusion:
The forward kinematics of the 2R robot arm was plotted for different values of θ1 and θ2 and the resulting plots were concatenated into an animation. The animation video is attached below.
Drive link for the Matlab code file and animation video file:
https://drive.google.com/open?id=145sJFJ-vTfAooHpsjNPiMxikTqzhR8bZ