Project

Simulation of forward kinematics of 2R Robotic arm

Theory

Kinematics is the analysis of motion without considering forces. Here, we only need geometric properties such as lengths and degrees of freedom of the manipulator bodies.

Forward kinematics refers to the use of the kinematic equations of a robot to compute the position of the end-effector from specified values for the joint parameters.

If we know the geometry of the robot and all its joint positions, we can do the math and figure out the position and orientation of any point on the robot.

Project Setup

In this project, the forward kinematics of a 2R robotic arm is simulated using Matlab. The basic setup of the robotic arm used in this project is shown in the figure below. The length of the arm1 is taken as l1 and the length of arm2 is taken as l2. The value of l1 and l2 are 3m and 1.5m respectively. The angle between the x-axis and the arm1 is taken as theta1 similarly, the angle between the x-axis and arm2 is taken as theta2

Matlab

%Length of the robotic arms - here the values for l1 and l2 are given as inputs

%Angle between the horizontal and the robotic arm - here the values for theta1 and theta2 are given in the form of an array. Arm1 moves between 10 deg - 80 deg and arm2 moves between 270 deg and 405 deg (45+360 - for anticlockwise rotation)

%For - End Loop - In order to simulate the forward kinematics we need to find the intermediate position of arm 1 and arm2. For...End loop is used to achieve this. Arm1 has 10 intermediate angles and arm2 has 50 intermediate angles.

The initial position of Arm1 is x0,y0, and the final position is x1,y1. The final position of arm 1 is the initial position of arm2. The final position of arm2 is x2, y2.

%Plotting - The intermediate values computed is plotted using the Plot command

%Conversion of Plot into Video - The plot of each value is converted into a separate frame and all the frames are combined together into a single video file. The file type of the video file is Motion JPEG AVI. The framerate is set at 10 frames per second to have a better view of the movement of the robotic arms.

clear all
close all
clc

%Length of the robotic arms 
l1=3;
l2=1.5;

%Angle between the horizontal and the robotic arm
theta1 = linspace(10,80,10);
theta2 = linspace(270,405,50);


%For End Loop
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([-1 5 -2 5])
pause(0.01)
V(ct)=getframe(gcf);
ct=ct+1;

    end
end

%Conversion of plot into Video
movie(V);
videofile=VideoWriter('Animation.avi','Motion JPEG AVI');
videofile.FrameRate=10;
open(videofile);
writeVideo(videofile,V);
close(videofile);

Output screenshot:

Animated video of the output

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.