Project

Forward Kinematics of a 2R Robotic Arm using MATLAB

Aim: To simulate the Forward Kinematics of a 2R Robotic arm using MATLAB.

Software used: Octave

Introduction: A robotic arm is a kind of a mechanical arm that is generally programmable. The arm might be a sum total of all the mechanisms or maybe a part of a more complex robot. The robotic arm is commonly a system comprising of various connections, called links. On the off chance when the orientation of the mechanical arm is determined, at that point it is conceivable to figure out the workspace of the arm. The workspace usually refers to all the potential areas that the robot can reach.

Robot kinematics can be partitioned into forward kinematics and inverse kinematics. Forward kinematics is the utilization of the kinematic equations of a robot to compute the position of the end effector from specified values for the joint parameters. The kinematic equations for the robot series chain are obtained by means of a rigid transformation to describe the relative movements permitted for each joint and separate rigid transformation in order to define the dimensions of each link.

The general layout of a 2R Robotic arm is as follows:

Here,

Let ϴ₁ - Angle made by link 1 with the base of the robot

ϴ₂ - Angle made by link 2 with respect to X-axis

Inputs are – l1, l2, ϴ₁ and ϴ₂

Output- Movement of Manipulator

The code for the simulation of the 2R Robotic arm is as follows:

% Forward Kinematics of a 2R Robotic Arm 
clear all
close all
clc 

%Inputs
l1 = 1; %Assuming a length of link 1 as 1m
l2 = 0.5; %Assuming a length of link 2 as 0.5m

%Angles for the arm from 0° to 90°
theta1= linspace (0,90,4);
theta2= linspace (0,90,4);

ct= 1 
for i= 1:length(theta1)
    THETA1=theta1(i);
    for j= 1:length(theta2)
    THETA2= theta2(j);
    
    x0=0; %x coordinate of the start point of link 1
    y0=0; %y coordinate of the start point of link 1 
    
    x1=l1*cosd(THETA1); %x coordinate of the end point of link 1 
    y1=l1*sind(THETA1); %y coordinate of the end point of link 1
    
    x2=x1+l2*cosd(THETA2); %x coordinate of the end point of link 2
    y2=y1+l2*sind(THETA2); %y coordinate of the end point of link 2

    %Plotting
    figure(ct)
    
    
    plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
    
    
    pause(0.03) %pause time for each frame
    axis([-0.1 1.5 0 1.5]) %plot values for x-axis and y-axis
    ct=ct+1;
    
    file_text=sprintf("robotic_arm%d.png",ct);
    saveas(gca,file_text);
    
  
    endfor
    
 endfor
    
    
   
    

Concise Description of the code:

Here, l1 and l2 represent the lengths of the links under consideration, in metric unit 1m and 0.5m respectively.

theta1 and theta2 represent the angles subtended with an equal interval of 4, over a range of 0° to 90°.

linspace is a function that generates linearly spaced vectors.

x0, x1, x2, y0, y1, y2 are the coordinate points of the start and end points of the links 1 and 2 in the XY plane.

x0, y0 – represent start points of link 1

x1, y1 – represent the endpoints of link 1 or the start points of link 2

x2, y2 – represent the endpoints of link 2.

The variable ct considers the count of each frame executed in the angle intervals subtended.

The for loop is a function, which is a repetitive control structure that allows you to efficiently write a loop that needs to be executed a specific number of times.

The plot command represents the mentioned coordinates from x0 to y2 on the graph for visual representation with a linewidth of 3.

The axis command allows one to limit the representation points in the graph generated as output.

The result is generated on the screen, and the expected animation is created.

The visual representation of the animation created is attached below:

Conclusion:

Located the points along with the forward motion of 2 links of varying lengths over a range of 0° to 90°, and generated the corresponding animation of the results achieved.

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.