Project

Forward Kinematics of a 2R Robotic Arm using MATLAB

Aim- To write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm and to create an animation file of the plot.

Introduction-

  • The Robotic Arm consists of 2 arms linked together of lengths l1 and l2.
  • They both operate at an angle of theta 1 and theta 2.
  • Where one end of the link 1 is fixed to the based and the other end of the link 1 is fixed to the link 2. The other end of the link 2 is fixed to the end manipulator.
  • The angle of operation of the end manipulator determines the workspace

Code:

%Forward Kinematics Using For loop
close all
clear all
clc

%Inputs
l1=1
l2=0.5
theta1= linspace(0,90,10);
theta2= linspace(0,90,10);

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',5,'color','r');
axis([-0.1 1.5 0 1.5]);
pause(0.03)
grid on
M(ct)= getframe(gcf);

ct=ct+1
    end
    
end

movie(M)
videofile= VideoWriter('Forward_Kinematics_robot.avi', 'Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

Procedure:

  1. First, the input values for l1, l2, theta 1 and theta 2 are specified in the editor.
  2. The cordinates of the ends of the link are specified.
  3. Since, x0 and y0 ae in orgin and lie at the base line they are (0,0). for x1 and y1, we have to use the formula x1 = l1 × cosd(theta1) , y1 = l1 × sind(theta1) and similary fo x2 and y2, x2 = x1 + l2 × cosd(theta2) , y2 = y2 + l2 × sind(theta2).
  4. Then, this enitre program is written within a for loop. Two for loop are writeen within each othe because we are using two link rods operating where (i) and(j) acts as the counter for these fo loops.
  5. theta 1 and theta2 is assigned to a variable THETA1 and THETA2, so that the value can be incremented automaticaly each time the program is being executed.
  6. The axis is specified for getting a clear graphical representation.
  7. M(ct)= getframe(gcf) is a get frame command that is used to animate the frames that is generated during the program execution.
  8. In the final step, the movie(M) command is used followed by videoWriter command where we should specify the file name and fomat. Thus, the animated file would be generated afte the program is executed.

Output:

Errors:

In this above image, the errorr occured because l2 have been mistakenly specified as l1 causing an undefined function for l2.

In the above picture, the error occured due to two faults. The theta values in the formulas have not been replaced by the variable assigned in the for loop program and the (i) counter must be replaced by (j) to satisfy the nested for loop.

YOUTUBE Video Link: https://www.youtube.com/watch?v=uml0yvJbxtY&feature=youtu.be

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.