Project

2R ROBOTIC ARM SIMULATION

2R ROBOTIC ARM SIMULATOR USING FORWARD

KINEMATICS

FORWARD KINEMATICS

Forward kinematics refers to the use of the kinematic equations of a robot to compute the position of the end-effector from specified values for the joint parameters.

This kinematic robot is mainly a combination of few or many mechanisms, of which each mechanism constitute a certain number of joints and links. The links are connected to each other through joints and hence the links have a relative motion to one another. Each of these links has a limited number of directions in which they can operate, this is called Degrees of Freedom(DOF). A robot is made to carry out a particular operation which is exercised by the End Effector.

The End Effector is operated by moving the links according to the kinematic equations. Kinematic equations are mainly dependent on

  • The length of each link.
  • The angle made by each link relative to a reference surface.

2R ROBOTIC ARM

In this project,

  • 2 links and 2 joints are considered in a Two Dimensional space.
  • Each link has 1 DOF.
  • Each link can move by 90 degrees relative to the horizontal.
  • Link 1 is connected to a rigid surface and link 2 is connected to the link 1.
  • For each position of link 1, link 2 has 90 degrees of rotatory motion.
  • Link 1 has 90 degrees rotation in 10 steps and link 2 has 90 degrees rotation in 40 steps.

The position of the link 1 and the end effector is calculated using,

`x_0=0`

`y_0=0`

`x_1=l_1*cos(theta_i)`

`y_1=l_1*sin(theta_i)`

`x_2=x_1+l_2*cos(theta_j)`

`y_2=y_1+l_2*sin(theta_j)`

Here,

`(x_0,y_0)` = Coordinates of fixed end of link 1.

`(x_1,y_1)` = Coordinates of the joint connecting links 1&2.

`(x_2,y_2)` = Coordinates of position of End effector

MATLAB PROGRAM STRUCTURE

  1. Lengths of both links are initialized. The angle of rotation of both links are 90 degrees, but the link 1 rotates in 10 steps and link 2 rotates in 40 steps. The angle of rotation of each link is initialized and a counter is initialized to 1.
  2. A 'for' loop is used to rotate link 1 through 90 degrees.
  3. A 'for' loop is used within the first 'for' loop to rotate link 2 through 90 degrees. Link 1 rotates in 10 steps and for every step of link 1, link 2 rotates in 40 steps. Within the 'for' loop of link 2, the coordinates of the positions of the fixed end of link 1, the joint joining links 1&2, the end effector are written using the kinematic equations.
  4. Remaining in the same for loop, a 'plot' command to depict the position of the robotic arm is given and the plot is stored in an array of the counter, then the counter is incremented by 1.
  5. As both the for loops gets executed, every plot is stored as an array of the counter. Outside the 'for' loops a code is written to construct a movie from the plots stored in the array.

Syntax:

movie(array name)
videofile = VideoWriter('Video name.format','type of file');
open(videofile);
writeVideo(videofile,array name);
close(videofile);

->movie(array name) , is a function that takes array name as input and enables the formation of a video.

-> VideoWriter('Video name.format','type of file'), is a function that takes video name.format and the type of file(i.e.,compressed or uncompressd) as input and assigns it to a file.

-> open(videofile), it opens the file.

-> writeVideo(videofile,array name), writes all the plot frames into the file and saves it.

-> close(videofile), closes the file.

MATLAB PROGRAM

close all
clear all %#ok
clc

theta1 = linspace(0,90,10); %Link 1
theta2 = linspace(0,90,40); %Link 2

l1 = 1; % Length of link 1
l2 = 0.5; % Length of link 2
ct = 1;
for i = 1:length(theta1)
   for j = 1:length(theta2)
      x0 = 0;
      y0 = 0;
      x1 = l1*cosd(theta1(i));
      y1 = l1*sind(theta1(i));
      x2 = x1+l2*cosd(theta2(j));
      y2 = y1+l2*sind(theta2(j));
      
      % Plot the robotic movement
      plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',2.5);
      axis([-0.8 2 0 2.5]);
      pause(0.01);
      
      M(ct) = getframe(gcf)
      ct = ct+1; 
   end
    
    
    
end    

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

Instances of the output

Click on the link for the Output Animation.

https://youtu.be/w6ryb7jz9dg

Errors observed

Error: Index Exceeds array bounds

Line 16: y1 = l1*sind(theta1(j))

The size of 'theta1' is 10 but that of 'j' is 40. So, when 'j' becomes 11 since 'theta' cannot accommodate any more elements, an error is shown.

Similarly,

Line 17:x2 = x1+l2*cosd(theta2(i))

The size of 'theta2' is 40 but that of 'i' is 10. So, only 10 spaces are filled in 'theta2' and the rest is empty which does not fetch the required output. Line 17 gets executed but the required result will not be obtained. Since line 16 has an error the line 17 has not yet been compiled.

Corrections: Line 16: y1 = l1*sind(theta1(i))

Line 17:x2 = x1+l2*cosd(theta2(j))

Thank You.

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.