Project

Animation of 2R Robotic Arm

Problem Statement :-

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

Theory :-

Forward kinematics :-

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

The kinematics equations of therobot are used in robotics, computer games, and in animation. The reverse process that compuyes the joint parameters that achieve a specified position of the end effector is known as inverse kinematics.

2R Robotic Arm :-

2R robotic arm ia a robotic arm with two degree og freedom. 2R robotic arm has two links which rotate in a two dimensional plane with each of links have a single degree of freedom.

A 2R robotic arm is shown in figure.

In the figure 2R robotic arm is shown. This arm contain two links, link 1 and link 2, the length of tese both links are l1 and l2 respectively. It is consider that link 1 is fixed to the horizontal and making an angle θ1 with horizontal. One end of link 2 is connected to link 1 and make with horizontal θ2.

It is consider that the start point coordinate of link 1 is (X0, Y0) and end point coordinate of link 1 is (X1, Y1). similarly for link 2 start and end point coordinates are (X1, Y1) and (X2, Y2), respectively.

Let X0 = 0 and Y0 = 0.

From figure and use of trigonometry formula we can say that

X1 = l1. Cos (θ1) Y1=l1. Sin (θ1)

X2=X1+l2. Cos(θ2) Y2=Y1+l2. Sin(θ2)

By using this equation we will solve the problem.

Procedure to create MATLAB program :-

To solve this problem first we provide some input data. This input data contain Arm length (l1 and l2), angle (θ1 and θ2) and the position of absolute coordinate(X0, Y0). After giving this data we will calculate the value of the other coordinates by using above equation. To calculate the values of the coordinate for different angles we will use for loop. By using the for loop we get position of the links for different angles. By using plot command we will get graphical form of data. For create an animation of this data we use movie command. This movie command create the movie of this data and by using video writer command we get this movie in directory.

MATLAB program :-

%Animation of 2R Robotic Arm Challenge
clear all
close all
clc

% Input Arm length
l1 = 2;
l2 = 1.5;

% Input Angle
theta1= linspace(0,90,18);
theta2= linspace(0,90,30);

% Input Position of (x0,y0)
x0 = 0;
y0 = 0;

k=1; % A constant for getting movie frame.
% Calculate (x1,y1)
for i=1:length(theta1)
    THETA1=theta1(i);
    
    % Calculating x2, y2 for corresponding theta2 by taking theta 1 value
    % one by one
    for j=1:length(theta2)
        THETA2=theta2(j);
     
        % Calculate coordinates (x1, y1)
        x1= l1* cosd(THETA1); 
        y1= l1* sind(THETA1);

        % Calculate (x2,y2)
        x2= x1 + l2*cosd(THETA2);
        y2= y1 + l2*sind(THETA2);
    
        % Plot
        plot([x0 x1], [y0 y1],[x1 x2], [y1 y2], 'linewidth',3);
        axis([-2 5 -1 5])
        pause(0.01)
        
        % getframe command returns the movie frame. 
        M(k)= getframe(gcf); 
        k=k+1;
 end
end

% Play the movie in matrix M 
movie(M) 
% Assign animation file name and file format
videofile= VideoWriter('robot_arm_challenge.avi','uncompressed AVI' );
% Open the video file for writing
open(videofile)
% Write the video file with the plot frames in the M array.
writeVideo(videofile,M)
% Close the video file after writing.
close(videofile)

Screenshot of Output:-

Animation Video Link:-

https://youtu.be/DvfaPTxYo3I

Errors during programming:-

1. During programming, errors are mainly arise due to Case sensitivity of variable name. For that error is shown as "undefine variable".

2. Second error arise due case sensitivity of videowriter command.

Conclusion:-

By this project successfully program the 2R robotic arm and get the animation of the arm.

END.

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.