Simulation of a SCARA robot using MATLAB robotics toolbox

Lets say we want to drive the robot end-effector in constant velocity along a rounded rectangular path to mimic a glue dispensing application. The Jacobian can be used to find the angular velocities required in order to maintain the end-effector velocity constant. The referenced robot is Adapt S350 SCARA, but only 2 degrees of freedom are used. The simulation can be done in MATLAB using the robotics toolbox as follows.



%clear all;

a1= 12.5;
a2 =25.5;
theta1 = pi/4;
theta2 = pi/8;
d3 =2;

%Initial position
ini_x = -9;
ini_y = 20;
ini_z = 0;
ini_q = [0.399    2.100 0];
% Time between two points in seconds
t = 0.05;

% Number of points along the path
pts = 485;

% Time segments for plotting graphs
tGraph  = 0:0.05:t*pts;

%Defining the robot
L1 = Link([theta1 0 a1 0 0]);
L2 = Link([theta2 0 a2 pi 0]);
L3 = Link([0 d3 0 0 1]);
L = SerialLink([L1 L2 L3]); = 'SCARA';

%Initializing Matrices for linear and angular velocity storage
linearVs = zeros(pts,3);
angularVs = zeros(pts,3);
SCARADrawn_XYZp = zeros(pts,3);


%Initial Pose
T = transl(ini_x, ini_y, ini_z);
qs = L.ikine(T, [0.399    2.100 0], [1 1 1 0 0 0])
plot(L ,qs,'workspace', [-pi pi -pi pi -5 5])
qs = qs';

for i = 1:pts
%Calculating the Jacobian for the current coordinate
T = transl(contour(i,1),contour(i,2),0);
qs = L.ikine(T, qs, [1 1 1 0 0 0]);
J = jacob0(L, qs);

Jxyz = J(1:3,:);

%Calculating the required angular velocities
qd = inv(Jxyz)*  [contour(i,3) contour(i,4) 0 ]';
angularVs(i,:) = qd';

xd = Jxyz*qd;

% Angular displacement
qs =  qs' + qd*t;


% Plot the robot
plot(L ,qs','workspace', [-pi pi -pi pi -5 5])

% XY Plot
Tfkine = L.fkine(qs');
p = transl(Tfkine);
hold on;
plot(p(1), p(2))
SCARADrawn_XYZp(i,:) = p';


The contour matrix has 4 columns for position x, position y, velocity x, velocity y and the number of rows equals to the number points along the path. The time between two points is set to 0.05s. By defining the matrix contour as desired, the required angular velocities for the joints can be found.


2 thoughts on “Simulation of a SCARA robot using MATLAB robotics toolbox

  1. hi, i am getting error in contour line (T = transl(contour(i,1),contour(i,2),0); and qd = inv(Jxyz)* [contour(i,3) contour(i,4) 0 ]’;) and it shows error as “Z must be at least a 2×2 matrix”.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s