Project

Creating Animation of Forward Kinematics of Robotic Arm using MATLAB

% Writing program to create animation of forward kinematics of the
% robotics arm movement

% The arm has two links joined using rotational joint and the arm joined at
% the base also has the rotational joint

% Objective: Creating animation of each arm to move using the predefined
% steps & angular movement

close all % Close all existing figure windows
clear all % Clear workspace
clc % Clear command window

% Inputs
l1 = 1; % Length of the first arm in meter
l2 = 0.5;   % Length of the second arm in meter

% creating equal steps using "linspace" command between the first arm & the
% base
theta1 = linspace(0,90,10); 

% creating equal steps using "linspace" command between the first arm & the
% second arm
theta2 = linspace(0,90,10);

% Creating counter variable to create & capture frames to make animation
ct =1; 

% Inserting for loop to execute the arm movement for each angular step
for i = 1:length(theta1) % executing for loop for the length of the theta1 array 
    THETA1 = theta1(i); % recording the each step of theta1 into new variable
    for j = 1:length(theta2) % executing for loop for the length of the theta2 array 
        THETA2 = theta2(j); % recording the each step of theta2 into new variable
        
        % Inserting the coordinates of th arms
        
        % Initial coordinates of the first arm
        x0 = 0;
        y0 = 0;
        
        % End coordinates of the first arm which is also the inital
        % coordinate of the second arm
        % defining x & y coordinates
        % x1 is the angle between the armand  the x axis, the postion will
        % be determined based on the THETA1 value.
        x1 = l1*cosd(THETA1); 
        % defining angle with the y axis
        y1 = l1*sind(THETA1);
        
        % Locating end point of the second arm as per the movement of the
        % first arm, thats why the length of the first arm has been added
        % into the equation
        x2 = x1 + l2*cosd(THETA2);
        y2 = y1 + l2*sind(THETA2);

        % Plotting the robotic arm
        
        % Plotting two arms as per their coordinates
        plot([x0 x1], [y0 y1],[x1 x2], [y1 y2], 'linewidth', 3)
        
        % Inserting the size of the graph
        axis([-0.1 1.5 0 1.5])
        % Pausing the video 
        pause(0.05)
        % Recording each from into the new variable, called 'M'
        M(ct)= getframe(gcf);
        ct = ct+1; % Giving increment to the counter variable
    end
end

% Creating Animation of the robotatic arm

% Playing recorded frames into M variable
movie(M) 
% Creating object that contains the video & its properties information
videofile = VideoWriter('forward kinematics.avi', 'Uncompressed AVI');
% Opening animation to visualise
open(videofile)
% Stitching each recorded frame into the M variable to make animation using
% the movie command
writeVideo(videofile,M)
close(videofile) % Closing animation

Robotic Arm Animation File:

https://youtu.be/qLs0kqxSki8

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.