Project

Simulation of forward kinematics of a 2-R robot

Aim:

To simulate the forward kinematics of a 2-R robotic arm

Governing equations

For a line of length from a point (`X_1, Y_1`) and making an angle theta with the horizontal, the coordinates of the end point, (`X_2, Y_2`) are given by:

`X_2` = `X_1+l*costheta`

`Y_2` = `Y_1+l*sintheta`

Setup

Objective

The objective of this program is to simulate the forward kinematics of a 2R robot in order to determine the final position of its manipulator, in other words, the workspace of the robot.

Forward kinematics is the process of finding the position and velocity of a robot, given parameters like joint angles, length of links or angular velocities.

A 2R robot refers to a robot having 2 links and 2 rotation joints. It has several applications in welding industry, material handling, assenmbly opertations etc.

The workspace of a robot is defined as the set of points that can be reached by the end effector of the robot. In other words, it is the area in which the mechanism of the robot is working.

In order to simulate the forward kinematics of a 2R robot, firstly its geometrical parameters are defined. This includes the coordinates of the first rotational joint, length of both the links and the range of inclination of the links with the horizontal.

By using the trigonometric relations, the coordinates of the second rotational joint and the end effectors are determined.

Once the plots for various configurations of the links are generated, different figures are stitched together to create an animation.

Program

% WAP for forward kinematics of a 2-R robot.

clear all
close all
clc

%inputs
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,20);
l1 = 2; %length of link 1
l2 = 1; %length of link 2
ct = 1; %counter

for i=1:length(theta1)  % length(theta1)= number of elements in array theta1
    THETA1 = theta1(i); % THETA1 is a single element containing different values from theta1
    for j=1:length(theta2)
        THETA2 = theta2(j);  
        x0 = 0; %starting x of link 1
        y0 = 0; %starting y of link 1

        x1 = l1*cosd(THETA1); %ending x of link 1 = starting for link 2
        y1 = l1*sind(THETA1); %ending y of link 1

        x2 = x1 + l2*cosd(THETA2); %ending x of link 2
        y2 = y1 + l2*sind(THETA2); %ending y of link 2

       %plotting
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',4)
        axis([-0.1,3,0,3]);
        pause(0.02)
        X(ct)=getframe(gcf); %gcf is get current figure
        ct = ct+1;

    end
end

% creating animation
movie(X)
videofile = VideoWriter('forward_kinematics_2R_robot.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,X)
close(videofile)

Outputs

Conclusion

The simulation of forward kinematics of a 2R robot was successfully comlpleted. Similarly, a program could be generated for a robotic arm with higher degrees of freedom, having motion in all three axes.

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.