Project

Simulation of the forward kinematics of a 2R robotic arm in MATLAB

AIM : To simulate the forward kinematics of a 2R robotic arm in MATLAB

THEORY:

  1. Robotic kinematics studies the relationship between the positions, velocities and accelerations of the links of a manipulator which are divided into two types.
  2. Forward kinematics and the inverse kinematics are the methods to calculate co-ordinates of end effector and joint angles respectively.
  3. Forward kinematics is used to get the co-ordinates or position of end effector from all the given angles of the links.
  4. In inverse kinematics, we need to get all the joint angles of the links from a given co-ordinates or given path or trajectory.

MATLAB CODE:

% program to simulate forward kinematics of a 2R robotic arm
clear all
close all
clc

% inputs
l1 = 1.2; % length of first link
l2 = 0.5; % length of second link

theta1 = linspace(0,90,20); % angles traced by the links in degrees from 0 to 90
theta2 = linspace(0,90,20);

count = 1;
for i = 1:20
    THETA1 = theta1(i);
    for j = 1:20
        THETA2 =theta2(j);
        
        x0 = 0; % starting co-ordinates of the 1st link
        y0 = 0;
        
        x1 = l1*cosd(THETA1);      % starting co-ordinates of the 2nd link
        y1 = l1*sind(THETA1);
        
        x2 = x1 + l2*cosd(THETA2); % ending co-ordinates of 2nd link
        y2 = y1 + l2*sind(THETA2);
        
        % plotting
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
        axis([-0.1 2 0 2])       % specifying the limits for the x axis and y axis
        pause(0.05)                % pausing time for each frame
        M(count) = getframe(gcf)   % frames for the animation video
        count = count+1;           % incrementing for the frames
    end
end
movie(M)
videofile = VideoWriter('forward_kinematics_of_2R_Robotic_arm','uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)

Result of the animation is uploaded below:

https://www.youtube.com/watch?v=-1ZZhT_siA8&feature=youtu.be

ERRORS:

The errors which I have faced during coding of forward kinematics of a 2R robotic simulator in matlab is as follows:

The above error has occurred due to not assigning the equal (=) operator.

EXPLANATION:

  1. The lengths (l1,l2) and the angles of two links has been fed as input
  2. To simulate the movement of the end effector, the angles made by the links i.e., which has been represented in the code as theta1 and theta2 will be varied over a range, hence the linspace command has been used.
  3. The co-ordinates (x0,y0) of the starting point of the link1 are taken at origin, hence the co-ordinates will be (0,0).
  4. The co-ordinates of the ending point of 1st link or the starting point of 2nd link have been named as (x1,y1) which are calculated as:

x1 = l1*cosd(theta1)

y1 = l1*sind(theta1)

  1. The co-ordinates of the ending point of 2nd link have been named as (x2,y2) which are calculated as:

x2 = x1 + l2*cosd(theta2)

y2 = y1 + l2*sind(theta2)

cosd and sind commands are used inorder to incorporate angles in degrees.

  1. After getting the coordinates the two links will be plotted on the same graph using plot command.
  2. For each value of theta1, theta2 will be changed over the entire range specified, inorder to incorporate this ‘for’ command have been used.
  3. The final output will be obtained in the form of an animation video clip.

CONCLUSION:Hence, simulation of forward kinematics of a 2R robotic has been achieved by MATLAB.

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.