Project

Forward Kinematics of a 2R Robotic Arm

Introduction

We can find out the position of manipulator of a robotic arm using forward kinematic equations. It generally characterizes the relative movement of robotic arm joints. If we know the parameters of the robotic arm, then we can simply obtain the forward kinematics using mat lab.

Objective

Here, we have to simulate forward kinematics of a 2R robotic arm and to create an animation of the output plot.

Procedure

Consider a 2R robotic arm with two link named l1 and l2. They are having theta1 and theta2 as the angle with horizontal plane respectively. First we have to find out the position of l1 and then calculate the position of l2 according to l1.

From the basics, we can calculate the position of l1 as x1 = l1*cos (theta1) and x2 = x1 + l2*cos (theta2). Similarly, y1 and y2 are calculated. X0 and y0 is considered as 0. These values are calculated by the mat lab using our programme, which is given below.

% forwad kinematics animation
clear all
close all
clc
%inputs
l1 = 1
l2 = 0.5
theta1 = linspace(0,90,20);
theta2 = linspace(0,90,20);
ct = 1
for i = 1:length(theta1);
    THETA1 = theta1(i);
    for j = 1:length(theta2);
        THETA2 = theta2(j);
        x0 = 0
        y0 = 0
        x1 = l1*cosd(THETA1);
        y1 = l1*sind(THETA1);
        x2 = x1+l2*cosd(THETA2);
        y2 = y1+l2*sind(THETA2);
        % plotting
        
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
        axis([-0.1 1.5 0 1.5])
        pause(0.03)
        M(ct) = getframe(gcf);
        ct = ct+1
    end
end
movie(M)
videofile = VideoWriter('Forwad_kinematics_animation.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

Code Explanation

In the beginning, we are giving the ‘linspace’ command for specifying a range or the theta1 and theta2. So that plot can be made for multiple values. After giving input values, we must assign ‘for’ ‘end’ commands. Programme will run ‘j’ times for one value of ‘i’. So in the end we will get ‘i*j’ number of results. When position calculation is giving, we should enter ‘cosd’instead of cos for getting the values in degree.

For plotting, plot command is used but here we will get multiple plots. So we must stitch it to one and animate it. So frame is specified and pause command is given. For getting animation file we will use movie, video writer commands. Axis command is used to specify the axis and the plot is made.

Results

When the code was executed, plots were formed and animation file got saved.

By strictly following the tutorial , It was able to do this programme without any error.

The animated video file was uploaded to Google drive, and link is given below

https://drive.google.com/file/d/1M7Uh57HlLEI96bh6M7Iz-1Tv16S4ZQP2/view?usp=sharing

We can change the result by giving other values to theta and providing different pause time. Here, pause time is 0.03 and 20 values between 0 and 90 is taken for theta.

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.