AIM: -
Program for forward kinematics of a 2R Robotic arm manipulator.
Make a movie of the robotic arm movements animation.
GOVERNING EQUATIONS: -
For the given lengths L1 & L2, we have to calculate the coordinate values which are the end points of the links.
theta1 = angle made by the longer link with the horizontal axis.
theta2 = angle made by the shorter link with the horizontal axis.
Taking here the first end of the longer link is (x0, y0) = (0,0) coordinate.
Second end of the longer link & first end of the shorter link is (x1, y1)
Where x1 = L1cos(theta1), y1 = L1sin(theta1)’
Second end of the shorter link is (x2, y2)
Where x2 = x1 + L2cos(theta2), y2 = y1 + L2sin(theta2)
Therefore, the three coordinates are (x0, y0), (x1, y1), (x2, y2).
Objective: -
Program for forward kinematics of a 2R Robotic arm manipulator.
The working angle of the longer link of robotic arm should be (135° to 45°).
The working angle of the longer link of robotic arm should be (90° to 0°).
Make a movie of the robotic arm movements animation.
Body of the content: -
By using the MATLAB, writing program for 2r robotic arm of a manipulator
The code is: -
clear all
close all
clc
% inputs
l1 = 2;% l1 is the length of the first arm ( m )
l2 = 0.8;% l2 is the length of the second arm ( m )
theta1 = linspace(135,45,8);% linspace is used for creating the required no. of values b/w 2 limits.
theta2 = linspace(90,0,8);
ct=1
for i= 1:length(theta1)%length of theta1 means the no. of values in theta1.
THETA1= theta1(i);% here i in the for loop is a loop counter that it tells how many times the for loop going to executed.
for j= 1:length(theta2)% here the benefit with for loop is it's not a array, everytime it executes only one value upto i or j times.
THETA2= theta2(j);
x0 = 0;% coordinates first end of the first link
y0 = 0;
% Note:- for each for loop the loop counter variable should be different.
x1 = l1*cosd(THETA1);% here the angle is in degrees. so, we use "cosd" instead of "cos" which takes the values in radians.
y1 = l1*sind(THETA1);% coordinates for second end of first link & first end of second link
x2 = x1 + l2*cosd(THETA2);% coordinates for the second end of the second link
y2 = y1 + l2*sind(THETA2);
% plotting the arms
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2], 'linewidth', 4)
axis([-2.8 2.8 0 2.8])
pause(0.1)
M(ct) = getframe(gcf); % ct represents each and every frame. In the getframe command calling the 'get current figure (gcf)' and it'll be saved in an array called 'M'
ct=ct+1;
end
end
movie(M)% it means MATLAB generate a movie with all the individual
videofile = VideoWriter('forward_kinematics.avi', 'uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Errors encountered while running the code: -
1.Here I forgot to define the THETA2 and it became error
Solution: - It’s rectified by assigning the theta2 value for it.
2. Here the error was I forgot to mention whether it’s theta1 or theta2
Solution: - It's rectified by assigning the value for theta2 since it’s THETA2.
3. Here I did a typo mistake that I typed “videowriter” instead of “VideoWriter” it’s case sensitive error
Solution: - It's corrected by typing the correct command that is “VideoWriter”.
4. Here I did a typo mistake that I typed “writevideo” instead of “writeVideo” it’s case sensitive error.
Solution: - It’s corrected by typing the correct command that is “writeVideo”.
Plot Results: -
As per the objective the plot got executed and this is the picture of that plot.
Movie link: - This is the movie of the 2R Robotic arm movements animation file, google drive link below.
https://drive.google.com/file/d/1lQWsdJ9f2VaBMAn-B5k7Bp6M5cj3kqOt/view?usp=sharing
Conclusion: -
Program was written for forward kinematics of a 2R Robotic arm manipulator,
Successfully created a movie of its movement's animation and
Most of the errors I found were the typo errors and got solutions to them due to these things I realized and learnt how some new commands are existed.