Simulation the forward kinematics of a 2D Robotic Arm
Aim: Simulation the forward kinematics of a 2R Robotic Arm.
Problem Statement:
There are two links in robotic arm. First link o length of l1 which are making angle of theta1 with positive X-axis & second link of length of l2 which are making angle theta2 with positive X-axis & connected to end of first link. We have to write program for movement of both links with respect to changing in angles.
Program:
% Program for calculating Drag Force against a cyclist
% Step 1
clear all
close all
clc
% Step 2
% Defining lengths of both links
l1=1;
l2=0.5;
% Step 3
% Defining both angles
theta1=linspace(0,90,20);
theta2=linspace(0,90,20);
% Step 4
% Defining variable which will be halepful for making movie
ct=1;
% Step 5
% To create many plot, we are using for loop
for i=theta1
% Step 6
% Considering starting point of link 1
X0=0;
Y0=0;
% Step 7
% Calculating value of ending point of link 1 wrt various angles
X1=l1*cosd(i);
Y1=l1*sind(i);
% Step 8
% To create many plot, we are using for loop
for j=theta2
% Step 9
% Calculating value of ending point of link 2 wrt various angles
X2=X1+l2*cosd(j);
Y2=Y1+l2*sind(j);
% Step 10
% Plotting plot for various angle of theta1 & theta2
plot([X1 X2],[Y1 Y2],[X0 X1],[Y0 Y1],'linewidth',3);
% Step 11
% Defining limits of both axis
axis([-0.1 1.6 -0.1 1.6]);
% Step 12
% For pausing each for loop for 0.01s
pause(0.01);
% Step 13
% Storing each screen array
M(ct)=getframe(gcf);
ct=ct+1;
end
end
% Step 14
% Creating & Storing Movie
movie(M)
videofile=VideoWriter('2D_Link.avi','uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile);
Result
Stepwise Explaination:
Step 1 Explanation:Clearing command window & workspace, closing of all plot.
Step 2 Explanation:Defining the length of both links
Step 3 Explanation:Defining the both angles (theta1 & theta2) which are changing from 0-90 in interval of 10 by using linspace
Step 4 Explanation:Defining variable ct which will be helpful for creating movie of our plot.
Step 5 Explanation:We want to create many plots for link 1 with respect to different value of theta1, hence we are using for loop.
Step 6 Explanation:Defining staring co-ordination of link 1.
Step 7 Explanation:Calculating co-ordination of end point of link 1
Step 8 Explanation:We want to create many plots for link 2 with respect to different value of theta2, hence we are using for loop.
Step 9 Explanation:Calculating co-ordination of end point of link 2.
Step 10 Explanation:Plotting both links with respect to corresponding value of theta1 & theta2.
Step 11 Explanation:Defining limit for both axes.
Step 12 Explanation:Pausing each plot for certain time.Step 13 Explanation:Storing each figure in array M.
Step 14 Explanation:Creating & Storing Movie with help of this program.
Error & Solution
When I ran program for first time then there was unusual reason showing there. Movie which was stored in my drive was not complete movie, just vertical single line. However, plot was complete & showing all animations. Hence I understood that there is some problem in storing movie. When I read this program again thoroughly, then I came to know that I have missed to write program to increase value of ct. Hence it is storing last plot which is vertical line. Then I wrote program ct=ct+1 which have become solution to my problem.