Project

2R Robot Simualtion

Aim:

To simulate a 2R robot model using octave.

Description:

A robot is made of individual components called 'links'. Each of these links is connected using 'joints'. These joints dictate the degree of freedom of links with respect to each other and thereby governing its overall motion. Based on the number of links, joints, and overall movement the robots are classified into many types. A 2R-Robot is one such type that has 3 links connected by 2 Revolute joints.

Any robot in motion can be defined in one of two ways, Forward Kinematics and Inverse Kinematics.

  1. Forward Kinematics: In this method, the angle made by each link with a reference axis is given so the overall orientation of the robot and its end-effector position(end pint of the last link) are defined.
  2. Inverse Kinematics: In this method, the end effector position of the robot is defined and all the other parameters are calculated.

In this project, a Forward kinematic method is selected.

Method :

  1. Each arm is made by plotting a line with common endpoints.
  2. Then one end is fixed and positions of all the other edges are defined as functions of angles and lengths with respect to the fixed end.
  3. Here instead of shifting the arms suddenly loops are used to gradually move the arms.
  4. During the motion, the intermediate positions are captured.
  5. All these captured plots are stiched to make an animation.

Code :

%setting the workspace
clear all
close all
clc

% defining the initial conditions
theta1=0;
theta2=0;
theta3=0;
l_1=2;
l_2=1.6;
l_3=1.4;

%Defining the motion of the first link
theta_1=linspace(0,45,45);
theta2=0;
theta3=0;
l_1=2;
l_2=1.6;
l_3=1.4;
ct=0;

for i=1:45
theta1=theta_1(i);
x_1=0;
y_1=0;

x_2=l_1*cosd(theta1);
y_2=l_1*sind(theta1);

x_3=x_2+l_2*cosd(theta2);
y_3=y_2+l_2*sind(theta2);

x_4=x_3+l_3*cosd(theta2);
y_4=y_3+l_3*sind(theta3);
%plotting the position
plot([x_1 x_2],[y_1 y_2],'linewidth',5,[x_2 x_3],[y_2 y_3],'linewidth',5,[x_3 x_4],[y_3 y_4],'linewidth',5);
axis ([0 5 0 5])
pause(0.03)

%creating the animation
grid on
text=sprintf('output%d.png',ct);
saveas (gca,text);
ct=ct+1;
end
% Defining the motion of 2nd link
theta1=45;
theta_2=linspace(0,20,20);
theta3=0;
l_1=2;
l_2=1.6;
l_3=1.4;

for i=1:20
theta2=theta_2(i);
x_1=0;
y_1=0;

x_2=l_1*cosd(theta1);
y_2=l_1*sind(theta1);

x_3=x_2+l_2*cosd(theta2);
y_3=y_2+l_2*sind(theta2);

x_4=x_3+l_3*cosd(theta2);
y_4=y_3+l_3*sind(theta3);

plot([x_1 x_2],[y_1 y_2],'linewidth',5,[x_2 x_3],[y_2 y_3],'linewidth',5,[x_3 x_4],[y_3 y_4],'linewidth',5);
axis ([0 5 0 5])
pause(0.03)

grid on
text=sprintf('output%d.png',ct);
saveas (gca,text);
ct=ct+1;
end
%defining the motion of the third link
theta1=45;
theta2=20;
theta_3=linspace(0,-10,10);
l_1=2;
l_2=1.6;
l_3=1.4;

for i=1:10
theta3=theta_3(i);
x_1=0;
y_1=0;

x_2=l_1*cosd(theta1);
y_2=l_1*sind(theta1);

x_3=x_2+l_2*cosd(theta2);
y_3=y_2+l_2*sind(theta2);

x_4=x_3+l_3*cosd(theta3);
y_4=y_3+l_3*sind(theta3);

plot([x_1 x_2],[y_1 y_2],'linewidth',5,[x_2 x_3],[y_2 y_3],'linewidth',5,[x_3 x_4],[y_3 y_4],'linewidth',5);
axis ([0 5 0 5])
pause(0.03)

grid on
text=sprintf('output%d.png',ct);
saveas (gca,text);
ct=ct+1;
end

Plots / Animations :

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.