Project

Matlab Program to simulate the forward kinematics of a 2R Robotic Arm

Aim:

To write a Program in Matlab to simulate the forward kinematics of a 2R Robotic Arm, as shown in the video and to Create an animation file of the plots.

Objectives:

  1. The main motive is to determine the motion of the robotic arm manipulator in its workspace using a MATLAB program.
  2. And to create an animation file(.avi) for the robotic arm movement in its workspace.

Theory:

Forward kinematics is the use of the kinematic equations of a robot to compute the position of the end-effector from specified values for the joint parameters. The kinematics equations of the robot are used in robotics, computer games, and animation.

The essential concept of forward kinematic animation is that the positions of particular parts of the model at a specified time are calculated from the position and orientation of the object, together with any information on the joints of an articulated model.

Software used:

MATLAB R2020(Online)

MATLAB CODE:

%Forward Kinematics of a 2R Robotic arm
clear all
close all
clc
 
%inputs
l1 = 1;     %length of link 1
l2 = 0.5;   %length of link 2

theta1 = linspace(0,90,15);   %assigning values for theta 1
theta2 = linspace(0,90,15);   %assigning values for theta 2
ct=1;                         %counter value

%for loop
for i = 1:length(theta1)      
    THETA1 = theta1(i);
    for k = 1:length(theta2)      %nested for loop
        THETA2 = theta2(k);
        %Coorinates of the links
        x0 = 0;
        y0 = 0;

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

        x2 =  x1 + l2*cosd(THETA2);
        y2 =  y1 + l2*sind(THETA2);

        %plotting the coordinates
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'LineWidth',4)
        axis([-1 1.5 0 1.5]);    %assigning axis
        pause(0.03);             %pause the frame
        M(ct) = getframe(gcf);   %getting the frame
        ct = ct+1;               %incrementing counter variable 
    end                          %end of nested for loop
end                              %end of for loop

%writing the plot to a video file
movie(M)
videofile = VideoWriter('robotic_armuntitled','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

Output simulation Video Link:

Code Explanation:

  1. The length of the arms are assigned to variables l1&l2 where L1=1 & L2=0.5.
  2. Angles are defined as theta1 and theta2 respectively using ‘linspace’ command.
  3. Angle 1 referring to theta1=linspace(0,90,15) where value varies from 0 to 90 degrees with 15 equally separated values. theta1 is the angle made by link 1 from the horizontal x axis.
  4. Angle2 referring to theta2=linspace(0,90,15) where value varies from 0 to 90 degrees with 15 equally separated values. theta2 is the angle made by link 2 from the horizontal x axis.
  5. Counter denoted by ‘ct’ is set to 1. Counter helps in carrying out the iteration to get each plot for each position of links.
  6. for loop is used to compute the position of the arms at different angles and different iterations are obtained for every varying theta value of theta1 & theta2.
  7. We then plot the coordinates.
  8. getframe’ is used to obtain new frames for each iteration.
  9. The frames are then stitched into an .avi format video .

Errors faced:

1)Unrecognized variable:

Mentioned the variable ‘M’ in lowercase instead of uppercase.

Rectification: The varivble ‘M’ changed to uppercase.

2)Incorrect datatype argument in call to function ‘write’

Mentioned the function ‘writeVideo' as 'write'.

Rectification:Correct function name ‘writeVideo’ is changed.

Conclusion:

Finally the movements of both the Robotic links is determined using MATLAB. It is a useful way of determining the movements of links in the determined workspace. Similar codes along with additional coordinates can also be used to determine the movement of robotic arms having more than two links in a workspace.

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.