Medical Robotics and Technologies for
Computer Assisted Surgery
Introduction to the MATLAB Robotics Toolbox
What is MATLAB?
What is MATLAB (in Robotics)?
What is MATLAB Robotics Toolbox (Peter Corke)?
What is MATLAB Robotics System Toolbox?
MATLAB Robotics Toolbox
(Peter Corke)
Prof. Ferrigno
MATLAB Robotics System
Toolbox
MATLAB: General description
Current folder: shows
the content of the current
folder
Editor: useful for writing
scripts and personal functions
Command window: main interface in
which is possible to write commands
Workspace:
stores all the
active
variables
Command
history:
stores the
previously
executed
commands
Warning: each script of function, in order to be executed, have to be in the matlab search path
Prof. Ferrigno
Matlab: general settings
Menu bar: File, Edit, ..., Help
To add a toolbox or a custom folder with personal functions use the Set
Path command from menu File and save.
Example, add the Robotic toolbox: then Set Path, choose Add with
Sub Folders and select the toolbox folder rvctools
Peter Corke, ROBOTICS TOOLBOX for MATLAB
http://www.petercorke.com/Toolboxes.html
Prof. Ferrigno
In case of problems
Multiple solutions:
help <command>: shows the description of a command;
Doc <command>: shows a pop-up with detailed explanations;
Help menu: shows a fancy description of the command, with also search
fucntionality and examples;
Internet:
Mathworks
Google
Stack Overflow
Prof. Ferrigno
Matlab Tips:
load a file and calculate the mean value
VarName = load(NomeFile.txt');
MeanVarName = mean(VarName);
M = mean(A,dim) returns the mean values for elements along the
dimension of A specified by scalar dim. For matrices, mean(A,2) is a
column vector containing the mean value of each row.
Prof. Ferrigno
Matlab Tips:
3D coordinates graphical representation
scatter3(X,Y,Z,S,C) displays colored circles at the locations specified by the vectors X, Y, and Z (which
must all be the same size).
S determines the size of each marker (specified in points). S can be a vector the same length as X, Y,
and Z or a scalar. If S is a scalar, MATLAB draws all the markers the same size.
C determines the colors of each marker. When C is a vector the same length as X, Y, and Z, the values
in C are linearly mapped to the colors in the current colormap. When C is a length(X)-by-3 matrix, it
specifies the colors of the markers as RGB values. C can also be a color string (see ColorSpec for a
list of color string specifiers).
scatter3(X,Y,Z) draws the markers in the default size and color.
scatter3(X,Y,Z,S) draws markers at the specified sizes (S) in a single color.
scatter3(...,markertype) uses the marker type specified instead of 'o' (see LineSpec for a list of marker
specifiers).
scatter3(...,'filled') fills the markers.
Prof. Ferrigno
Transformations:
using the Robotics Toolbox (MANUAL)
- Define a point P in the ground reference O-xyz
Vector definition v = [2; 6; 4];
v = [2 6 4]; v=2*[1 3 2];
- Define an homogeneous transform with the origin coincident with P
T = transl(v);
- Define a rotation around the axes x/y/z of 10/-15/50 deg
Rx = rotx(10*pi/180);
q = [10 -15 50]*pi/180;
Ry = roty(-15*pi/180);
T = trchain('Rx(q1) Ry(q2) Rz(q3)', [q(1) q(2) q(3)]);
Rz = rotz(50*pi/180);
T(1:3,4) = v;
T(1:3,1:3) = Rx*Ry*Rz;
trplot(T); trprint(T); tranimate(T0,T1);
Prof. Ferrigno
Definition of a rigid body: Gram-Schmidt
algorithm
P2
[x2, y2, z2]
P3
P1
[x1, y1, z1]
Define a vector (vec1) between two
points and make it with unit norm
(vec1N)
Define a second vector (vec2_temp)
using starting point of the first vector
and a third point and normalize it.
Calculate the cross product between
them (vec3) and normalize it.
0 0 0
x p3
y p 3
z p3
Calculate the cross product between
vec3 and vec1 to find vec2 that is
orthogonal to both of them (and
normalize it)
Define then a proper origin
Prof. Ferrigno
Matlab Tips:
vector algebra
10
When v1 and v2 have the same dimensions ([3x1] 3D space)
Matrix multiplication
v1*v2
Dot product
dot(v1,v2)
Cross product
cross(v1,v2)
Norm
norm(v1)
Normalize
v1/norm(v1)
Element-wise
.* ./
Prof. Ferrigno