Project

Forward Kinematics of 2R Robotic Arm

Aim : Program to simulate the Forward Kinematics of a 2R Robotic Arm

Step-Wise Explanation of the Code :

  1. First we have to assign the lengths of the 2 links(i.e arms)
  2. We have to assign the values for theta
  3. We have to give the intial co-ordinates for the x and y for the links
  4. Then we have to give the next co-cordinates for the link 1 i.e(L1)
  5. Then we have to give the Intial co-cordinates for the link 2 i.e(L2 same as the final co-odrinates of the link 1 )
  6. Then we have to give the final Co-odrinates of the robotic arm i.e(L2)
  7. Then by giving a rel
  8. avent plotting data the graph is obtained for the Robotic Arm as shown in the fig(Robotic arm)

For making the robotic arm to movi i.e (for different values of the theta )

  1. Intially copy same inputs from the prevoius code
  2. For differenet values of theta we have to create a array using linespace command i.e(as shown in the code)
  3. For assinging the different values for the thetas we have to use for loop one for theta1 and again a for loop for theta2 (assiging them 2 different variables namely i & j)
  4. Then under the 2nd for loop we have to paste the main caluclation part form the 1st code i.e the co-ordinates and the ploting commands
  5. When we excute this the output of the program will be in the single in the graph whic is bit confusing as shown in the fig(2nd output)
  6. So for making it into proper output i.e as animation as attached we have to do the following steps
  7. We have to use counter commond i.e outsid the first for loop the intial value will be 1 then in the 2nd for loop we have to increment it by 1
  8. After this we have to give the proper axis for the plotting
  9. we have to store the output in the induviual grame and assign it to a variable 'M'
  10. Finally by creating a movie of the variable M the animation is created

Errors Faced while programming & Rectifying the error :

1) Undefined function 'Clear' for input arguments of type ' char '.

Error in Kinematics_Robot (line 3)

ANS : i Rectified it by changing the correct command

2) Undefined function or variable 'L1cosd'.

Error in kinematics_robot (line 16)
x1 = L1cosd(theta1);

ANS : I had not typed the astric mark (i.e multiplication) so i rectified my error

3) Error : File : kinematics_robot_for.m Line: 15 column: 1

Atleast One end is missing: the statement may begin here.

ANS : i rectified it by by correct commands

4) Cannot find a excat (case-sensetive) match for 'Movie'

The closest match is : movie in C:\

ANS : i rectified ut by correct case sensitive

Screen shots showing Error in Commond Window :

1)

2)

3)

4)

Program :

% A program for forward Kinematics of ROBOTIC ARM

clear all
close all
clc

%Inputs 
l1= 1;
l2= 0.5;

theta1= 30;
theta2= 50;

%Co-ordinates 
x0= 0;
y0= 0;

x1= l1*cosd(theta1);
y1= l1*sind(theta2);

x2= x1 + l2*cosd(theta2);
y2= y1 + l2*sind(theta2);

%Plotting
line([x0 x1],[y0 y1],'linewidth',1.5,'color','b');
line([x1 x2],[y1 y2],'linewidth',1.5,'color','r');
% A program for forward Kinematics of ROBOTIC ARM

clear all
close all
clc

%Inputs 
l1= 1;
l2= 0.5;

theta1= linspace(0,90,25)
theta2= linspace(0,90,25)

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',1.5)
    axis([-0.1 1.5 0 1.5])
    pause(0.03)
    M(ct)= getframe(gcf);
    ct=ct+1;
    end
    
end
movie(M)
videofile = VideoWriter('Kinematics_Robot.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

Output :

1)

2)

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.