Project

Kinematics of 2R robotic arm

AIM: To write a program to simulate the 2R robotic arm in MATLAB

THEORY: A robotic arm is a type of mechanical arm, and is a part of Mechatronics. It is usually programmable, with similar functions to a human arm; the arm may be the sum total of the mechanism or may be part of a more complex robot. The links of such a manipulator are connected by joints allowing either rotational motion or translational (linear) displacement. The links of the manipulator can be considered to form a kinematic chain.

There are two links in the arm, we can name it as L1 and L2.

There is manipulator at the end of link 2 at point C. This program generates the simulation for link 1 and link 2.

The position of pt. A is (X0,Y0), pt. B is (X1,Y1) and for pt. C is (X2,Y2). Variation of θ1 and θ2 is between 00 and 900. This program calculates the position of both links at the interval of 100 for both angles. Assuming pt. A to be at origin, then position of both links in terms of θ is given by:-

X0=0

Y0=0

X1=L1*cos(θ1)

Y1=L1*sin(θ1)

X2=X1+L2*cos(θ2)

Y2=Y1+L2*sin(θ2)

PROGRAM

%Program for simulation of forward kinematics of robotic arm  
clear all
close all
clc
 
%Inputs
%length of links (m)
l1 = 1; 
l2 = 0.5; 
%Angles of links from 0 to 90 (degree)
theta1 = linspace(0,90,10);  
theta2 = linspace(0,90,10);
 
%Counter for animation
ct=1;
 
%Loops for calculating the position of manipulator
for i = 1:length(theta1)
    THETA1=theta1(i);
    for j = 1:length(theta2)
        THETA2=theta2(j);
        
        %Coordinates of links
        x0 = 0;
        y0 = 0;
 
        x1 = l1*cosd(THETA1);
        y1 = l1*sind(THETA1);
 
        x2 = x1+l2*cosd(THETA2);
        y2 = y1+l2*sind(THETA2);
        
        %Plot
        figure(1);
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',2);
        axis([-0.1 1.5 0 1.5]);
        grid on;
        pause(0.03);
        M(ct)=getframe(gcf);
        ct=ct+1;
 
    end
end
 
%Generation of animation
movie(M);
videofile=VideoWriter('forward_kinematics.avi','uncompressed avi');
open(videofile);
writeVideo(videofile,M);
close(videofile);

OUTPUT

1) Output of workspace:

2) Output of animation:

The output of animation is uploaded on YouTube with link:

https://youtu.be/jhdp5seDPLg

This animation was generated in avi format, but converted to mp4 format using FormatFactory software to reduce the size of the file.

EXPLANATION

  • clear all, close all, clc are written for clearing the workspace, command window and also to close any plots.
  • Input values are taken for parameters like length of links and angles of links with the horizontal lines.

linspace() is used here to generate 10 values between 0 and 90.

  • Every iteration of the loop will be saved as a frame for generation the animation, hence for this a counter is used as ‘ct’, which will change its value for every iteration.
  • Loops will be used for calculating the position of manipulator. Inner loop calculates the position of link 2 and outer loop calculates the position of link 1.

Outer loop runs for 10 times. For every iteration of outer loop, inner loop runs 10 times. For every iteration of inner loop, position of both links are calculated and then plotted on the graph using plot(). axis() is used for giving the values to the axis of the graph. pause() is used for giving pause to every iteration of the loops, so that frames can be saved for animation. In this manner position of manipulator is calculated.

  • Animation is created by generating frames for each plots. getframe() is used for generating frames for each iteration. Frames are saved in ‘M’. ‘M’ is an array of 1 row. Its column value is decided by the no of iteration which is 100. Each frame is saved in new column of ‘M’, hence counter value (ct) needs to be increased every time. That why ct+1 is used, which increases its value by 1 after every iteration.
  • After the for loop is completed, the generated frames are compiled together to make an animation and saved in ‘videofile’. First ‘videofile’ is created using VideoWrite(), then the file is opened using open(), then all frames are compiled together and written on it using write(), then the file is closed using close().

Errors

  1. Error for misspelling the theta1:

This error was corrected by changing the name from ‘theta’ to ‘theta1’.

2. Error for misspelling the movie():

This error was corrected by changing the name from ‘Movie’ to ‘movie’.

CONCLUSION

  • This program helps in determining the workspace of manipulator of 2R robotic arm.
  • By running the loop for more no. of times, a more smooth animation can be generated.
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.