Simulation of forward kinematics of a 2R robotic arm
Aim:
To simulate the forward kinematics of a 2R robotic arm.
Objective:
To animate and simulate the motion of the 2R robotic arm in the given workspace.
Theory:
Forward kinematics means the use of kinematic equations of a robot to compute the position of the arm of the robot from specified values for the joint parameters.
A robotic arm is a usually a programmable robot manipulator having similar functions as a human arm. In our robotic arm there are 2 links forming a kinematic chain which allows for both rotational and translational motion. These types of robots are vastly used in industries such as automobile, electronics, welding etc.
Input Parameters:
L1=length of link 1
L2=length of link 2
Theta1=angle made by link 1 w.r.t x-axis
Theta2=angle made by link 2 w.r.t x-axis
(X0, Y0) = starting point of link 1
(X1, Y1) = ending point of link 1 and starting point of link 2
(X2, Y2) = ending point of link 2
Explanation of code:
- Length of first link is assumed to be 1 m
- Length of second link is assumed to be 0.5 m
- Theta1 and Theta2 varies from 0 to 90 degree in 4 partitions
- The value of counter is set to 1 which increases by 1 for every iteration of loop
- Double for loops are used for iteration of the robotic arm position
- First for loop is for link 1 and second for loop is for link 2
- The positions of link 1 and link 2 is itearted and plotted in a graph
- saveas and sprintf command were used to save each iteration.
- ImageMagick was used to create the animation in gif file.
Code:
Programming language used=MATLAB
Software used=Octave
%Stimulate the forward kinematics of 2R robotic arm
clear all
close all
clc
%length of first link in metre
l1=1;
%length of second link in metre
l2=0.5;
%Angle made by the first link wrt x-axis
theta1=linspace(0,90,4);
%angle made by the second link wrt x-axis
theta2=linspace(0,90,4);
%counter pointer
ct=1;
%for creating animation of 2R robotic arm
for i=1:length(theta1)
for j=1:length(theta2)
THETA1=theta1(i);
THETA2=theta2(j);
%Staring coordinates of link 1
X0=0;
Y0=0;
%Ending coordinates of link 1 and starting coordinates of link 2
X1=l1*cosd(THETA1);
Y1=l1*sind(THETA1);
%Ending coordinates of linl 2
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.5 0 1.5])
pause(0.1)
file_text=sprintf("robotic_arm%d.png",ct)
saveas(gca,file_text);
ct=ct+1;
endfor
endfor
Output:
As the animation is a gif file, you can view or download it from the below google drive link:
https://drive.google.com/open?id=1kojNhibKSsuH-2wlrXgtL1UO9sD0Y6Gp