Project

Forward kinematics of a 2R Robotic Arm

AIM: Write a program in MATLAB to simulate the forward kinematics of a 2R Robotic Arm.

Robotic arm

Robotic arm is the one type of mechanical robot which is run with the help of programming. It is used for the industrial application like welding, material handling, drilling, painting, etc. Forward kinematics refers for compute the end of the second link.

For the simulate the forward kinematics of a 2R Robotic Arm, First we have to write the program for showing the both link(arms of robot) as a line in graph than we have to rotate the link 1 & 2 with the use of loop for change the value of theta than this motion is used for the make a movie.

Step-wise explanation of code for the present the robotic arm with line:

  1. First, we have to assign the length of the links (arms of robot). So, I will give the value of the length of links in command window.
  2. We have to assign value of theta1 and theta2.
  3. We have to give the first coordinate of link1 (x0, y0) = (0,0).
  4. We have to give the second coordinate of link1 (x1, y1) = (L1cosθ1, L1sinθ1). It is also the first coordinate of link2.
  5. We have to give the second coordinate of link2 (x2, y2) = (x1+L1cosθ2, y1+L1sinθ2).
  6. For the plot the line for link in graph Line command is use.

For simulation of robotic arm, we have to make some changes which is as following:

  1. First copy the input from the above program.
  2. For simulation we require different values of θ1 and θ2. So, I will give the increment in both angle in command window.
  3. We need to calculate the all coordinate according to the value of angles I use the while loop with the condition of θ1 & θ2 <= 90̊.
  4. But for the simulation of link2 we need to calculate the all the value of θ2 for every value of θ1. So, while loop of the θ2 is under the while loop of θ1.
  5. Then copy the main calculation part of above program.
  6. When we run this program than combination of every θ1 & θ2 is shown in different figure which is confusing to understand.
  7. So, for the proper simulation counter command is used above the first while loop with initial value 1.
  8. We have to give the proper the value of X and Y axis.
  9. We have to make the new variable to store the frame of the current figure.
  10. We have to give increment to counter command.
  11. Then after the while loop, we have to create the movie of variable which is use to store the frame. So, the final animation is created.

The errors faced while programming & steps taken to overcome those errors:

1.While loop of θ2 is run only one time. After the increment in θ1 inner loop is not run.

Updates: I have to write one line in while loop before the inner while loop for take the value of θ2 is zero every time the first while loop is run.

2.I make mistake in value of y2 coordinate.

Updates: I correct the value of y2 coordinate.

Screenshots showing errors thrown in command window

1.

2.

Program for the plot the robotics arm

%Write a program  to simulate the forward kinematics of a 2R Robotic Arm
clear all 
close all
clc

%input
l1=input('input the length of link_1=')
l2=input('input the length of link_2=')

theta1=30;
theta2=60;

x0=0;
y0=0;

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

x2=x1+l2*cosd(theta2);
y2=y1+l2*sind(theta2);
               
line([x0 x1],[y0 y1],'linewidth',3,'color','r')
line([x1 x2],[y1 y2],'linewidth',3,'color','b')

Input in command window

input the length of link_1=1

l1 =

     1

input the length of link_2=0.75

l2 =

    0.7500

Output of the above program

Program for simulate the forward kinematics of a 2R Robotic Arm

%Write a program  to simulate the forward kinematics of a 2R Robotic Arm
clear all 
close all
clc

%input
l1=input('input the length of link_1=')
l2=input('input the length of link_2=')

theta1=0;
increment_in_theta1 = input('input the increment in theta1=')
theta2=0;
increment_in_theta2 = input('input the increment in theta2=')

ct=1
 while theta1<=90
       THETA1 = theta1
       theta2=0;
       
          while theta2<=90
               THETA2 = theta2
    
               theta2 = theta2+increment_in_theta2;
               
               x0=0;
               y0=0;
               x1=l1*cosd(THETA1);
               y1=l1*sind(THETA1);

               x2=x1+l2*cosd(THETA2);
               y2=y1+l2*sind(THETA2);
               
               plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
               axis([-0.1 1.75 0 1.75])
               pause(0.03)

               M(ct)=getframe(gcf);
               ct=ct+1


      end
    
 theta1=theta1+increment_in_theta1;
    
end

movie(M)
Videofile= VideoWriter('forward_kinematics_2R_roboticsarm.avi','uncompressed AVI');
open(Videofile)
writeVideo(Videofile,M)
close(Videofile)

Animation Link

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.