Representation of Robots in MatLAB
Representation of Robots in MatLAB
Research Notes
Representation of Robots in Matlab
This paper presents a new software tool, namely RoboClass, to include and manage realistic
robots and elements of the environment in Matlab simulations. These elements are loaded from
CAD models using an STL-¯le and can be as detailed as desired. All the steps involved in the
process are explained in detail. Furthermore, two illustrative examples are considered to show
the e®ectiveness and versatility of the proposed approach: the ABB-IRB120 industrial robot
and the CSA research robot. The developed tool is especially useful both for robotics research
and teaching.
1. Introduction
Nowadays, software tools are used in many engineering areas [1–3]. Matlab is a
technical software environment that has become a standard in many ¯elds of engi-
neering and education, including control systems and robotics [4]. This software
allows the user to program using a high-level language specially designed for nu-
merical computation, statistical analysis and data visualization. To this aim, Matlab
includes a high amount of mathematical libraries and toolboxes that work fast and
keep the code clear. In this sense, some toolboxes and open source code can be found
for robotics although none of them are especially devoted to improve the visualiza-
tion quality of the elements involved.
This paper presents a new open-source software tool, namely RoboClass, devel-
oped to improve the appearance of serial robots to get a much more realistic
23
24 A. Sanchez et al.
This toolbox was the ¯rst one of its type and is still a reference for robotics research
and teaching. In fact, it is probably the most used library in robotics nowadays all
over the world and, typically, new contributions in this area are compared with it.
The Kuka Control Toolbox [8] integrates a good amount of functions for robot
simulation but only Kuka robots can be involved. The IGES Toolbox [9] is designed
to load Initial Graphics Exchange Speci¯cation (IGES) format ¯les to Matlab and
operate with models. To do that, it adds commands and utilities to perform plots,
transformations and projections. The Puma project [10] simulates a six degrees-of-
freedom (DOFs) 3D Puma 560 robot with pre-loaded easy models to help the user on
the visual comprehension of the robot position. In addition, it includes a GUI with
slides to move the joints. This approach has inspired other practice program projects
[11], where students are encouraged to choose a robot and build a simulator to better
understand the kinematics related to it. Dynamics can be simulated using SimMe-
chanics [12], which is a library in SolidWorks software to model mechanical systems
and that uses Simulink toolbox to perform the control of the systems. Simbad [13] is a
Java 3D robot simulator dedicated to help researchers and programmers at study of
situated arti¯cial intelligence, machine learning, and arti¯cial intelligence algorithms
but, like other robot simulators as [14, 15] is focused on teaching purposes and not to
use it in an actual environment.
Moreover, the class also includes many functions of the Robotics Toolbox [7] to
improve its versatility.
RoboClass creates robot objects from an external con¯guration ¯les, therefore, it
is possible to build di®erent robots in the same workspace, perform cooperative
simulations or even include realistic elements of the environment loading STL-¯les as
well.
RoboClass has been developed for serial arms, but it is feasible to use it with other
kinematic architectures such as parallel robots. In this case, the class should be
modi¯ed to use it with this kind of mechanism but it will generate a di®erent class for
that particular mechanical structure.
As public information, a ¯le called RoboClass.zip can be downloaded from the
website: http://personales.upv.es/luigraca/RoboClass/code.htm.
This ¯le contains all the information regarding the class itself, Robotics Toolbox
Matlab functions, several samples of use and many STL-¯les for di®erent robots. The
Representation of Robots in Matlab 27
general procedure to work with a serial robot is described in four basic steps: (1)
Generation or downloading the STL-¯les; (2) Editing of the con¯guration ¯le; (3)
Creation and use of functions; (4) Visualization. In next section, the procedure to
deal with these basic steps is detailed.
The data structure has another ¯eld called Real. The purpose of this ¯eld is
containing the drivers to manipulate an actual robot. Thus, this ¯eld will have the
Matlab conversion of the manufacturer commands, which are di®erent for each robot
brand. The development related to this ¯eld is not included in this work and remains
as future work.
28 A. Sanchez et al.
Next, the ¯ve ¯elds indicated above for the con¯guration ¯le are explained.
General Parameters. The user must introduce the name of the robot model. If the
main path has the pwd command, it will detect automatically the class path. In
stlpath specify the folder where the STL-¯les are.
nameRobot ¼ <'robotName'>;
path ¼ pwd;
stlpath ¼ <STL files path>;
Kinematics. Robot kinematics describes the motion of the rigid bodies related to the
robot joint angles. The kinematic parameters of the con¯guration ¯le are: the robot
DOFs, the DH parameters and a vector with the rotational or prismatic character for
each joint as shown below:
dof = <degrees of freedom>;
originTr = <placement matrix>;
joinType = <joints vector>;
theta = <DH theta vector>; % theta is the kinematic joint angle
d = <DH d vector>; % d is the kinematic link offset
a = <DH a vector>; % a is the kinematic link length
alpha = <DH alpha vector>; % alpha is the kinematic link twist [2]
Dynamics. Robot dynamics describes how the robot moves in response to the ac-
tuator torques or forces. Dynamic vectors and the Jacobian matrix of each joint
de¯nes this information. Dynamic parameters must be given by the manufacturer in
order to perform dynamic calculations, as can be seen in Fig. 4.
STL Info. The STL structure contains a ¯eld for each of the N-links of the robot.
Each link has a ¯eld with the number of the previous joint and other M-¯elds, one for
each element composing the link. Each element ¯eld has the name and color of one
STL-¯le.
LinkN.Link ¼ <linkNumber>; LinkN.robot ¼ [];
LinkN.element1.name ¼ <'nameStlFile'>;
LinkN.element1.color ¼ <color in [r g b] format>;
...
LinkN.elementM.name ¼ <'nameStlFile'>;
LinkN.elementM.color ¼ <colorin[rgb]format>;
View Info. The view ¯eld contains the plot values: maximum and minimum limit of
each axis and the angles of the camera (azimuth, i.e. horizontal rotation, and the
vertical elevation).
minX ¼ <minimum value axis X>;
maxX ¼ <maximum value axis X>;
minY ¼ <minimum value axis Y>;
maxY ¼ <maximum value axis Y>;
minZ ¼ <minimum value axis Z>;
maxZ ¼ <maximum value axis Z>;
cameraAZ ¼ <azimuth>;
cameraEL ¼ <elevation>;
In order to visualize a robot in movement insert this function within a for loop.
The function con¯gView can adjust the viewing parameters. If the p does not receive
parameters, it adjusts the plot view to a standard.
MyRobot.configView();
If this function receives a vector v, it can adjust the view of the plot. This vector
can have three di®erent sizes: azimuth (Az) and vertical elevation (El), the XYZ axes
limits, or all of them.
v ¼ [Az El]
v ¼ [XMIN XMAX YMIN YMAX ZMIN ZMAX]
v ¼ [XMIN XMAX YMIN YMAX ZMIN ZMAX Az El]
MyRobot.configView(v);
The user can simulate the interaction between the robot and other objects. To
insert objects in the workspace use the external class LoadObject (<¯leName>,
<color>, Tr):
To create and show the axes of the reference system use the external class
RefSystem:
SR ¼ RefSystem();
Note that it is required to add the External classes folder to the Matlab path in
order to create objects of these classes. To do this, in Matlab interface, click with the
right button of the mouse on the folder you want to add and select Add to
Path ! Selected Folders.
. Type the command guide in the Matlab console and the quick start window will
appear. In that window, select Blank GUI and press OK button. In the editing
window add a slider object for each of the robot joints. Click on the image of each
slide with the second mouse button to open the properties. To be able to identify
what slide is linked to each joint, rename the ¯eld slider of each slide with the name
of the joint that the slide will change. Edit Max and Min ¯elds with maximum and
minimum rotation for each joint too. Save the ¯le as guideRobot.m and open that
¯le with the text editor.
Representation of Robots in Matlab 31
. Execute the function robotGuide OpeningFcn after the guide is opening. That
function must create the robot and a vector to handle the angles from the slides.
handles.MyRobot ¼ Robot(configFile());
handles.q ¼ zeros(1,handles.MyRobot.kinematics.dof);
. Link each slide to the robot joint angles. To do that, it is necessary to add some
code under the callback function of each slide. The code must get the angle from
the slide, set the robot position and save the values with guidata function.
handles.q(<jointN>) ¼ get(hObject,'Value');
handles.MyRobot.plot(handles.q);
guidata(hObject, handles);
. Follow the step above to add as much elements as needed. The general guide is
described below:
show with the slides,
add an element in the editing window,
open the guide ¯le,
add the code linking the robot parameters with the object values.
(1) Identify links and joints: Links are numbered from 0 (base) to n (end-e®ector).
Joints are numbered from 1 to n. In this version of the procedure, joint i connects
links i 1 and i.
(2) De¯ne the reference frames for the internal links: Locate zi axis along the axis of
joint i þ 1. The origin of the frame Oi is positioned along joint i þ 1 axis. If the
z-axes are parallel, Oi is arbitrarily chosen. Otherwise, it is located in the in-
tersection between zi and the common normal to zi1 and zi . yi axis is chosen to
compose a right-hand frame.
(3) De¯ne the reference frames for the extremit links: z0 is located along the axis of
joint 1. x0 and y0 are arbitrary. xn axis is normal to the joint n axis, while yn and
zn are arbitrarily de¯ned.
(4) Identify the DH parameters for each link: ai is the distance between zi1 and zi .
di is the distance between xi1 and xi . ai is the angle between zi1 and zi
measured along xi , while yi is the angle between xi1 and xi , measured along zi .
(5) Determine the homogeneous transformation matrices for each joint.
32 A. Sanchez et al.
z’i y’i yi i z i
i
O’i x’i xi
yi-1 z i-1 Oi
x i-1
Oi-1
4. Application Examples
Two examples are shown below to illustrate the applicability of the proposed class.
The ¯rst one is referred to the ABB-IRB120, see Fig. 6, which is a 6-DOFs
commercial industrial robot. It will be shown how to export the links of the IRB120
robot from Autodesk Inventor, to set the con¯guration ¯le to consider its behavior, to
use the basic functions and to make a GUI to move each joint.
Representation of Robots in Matlab 33
In the export window shown in Fig. 7, introduce the name of the ¯le to be created,
and select STL-¯le in the type ¯eld. Click on options button, select binary format and
set the resolution of the model. It is possible to check the export resolution clicking on
the preview button. Note that less resolution results in a model with fewer faces. This
impacts directly on the appearance of the link/s, see Fig. 8 and the performance of
the simulation, see Fig. 9.
(a) 862 faces IRB120 Link 3 model (b) 43.146 faces IRB120 Link 3 model
(a)
(b)
Fig. 9. Load time versus Number of faces. (a) ASCII ¯les. (b) Binary ¯les.
Di®erent simulations have been done to compare the load time of STL ASCII and
binary ¯les depending on the number of triangles. Table 1 shows load times for a
complete robot. Loading binary ¯les is always faster than loading ASCII ¯les.
However, as the complexity of the model increases, the di®erence between load times
raises dramatically. Figure 9 shows how fast ASCII load time raises up when the
number of triangles increases in comparison to binary load times. In this example,
there are seven ¯les: base, ¯ve links and ¯nal e®ector. All the ¯les are stored in a
folder called stl IRB beside the RoboClass folder.
Face number Load ascii time (s) Load binary time (s) Ratio
15120 4.195026 0.076050 55
30249 10.873158 0.118491 92
75622 48.718367 0.214152 227
151255 200.434706 0.401590 499
302513 788.170335 0.777622 1014
756290 5037.88186 2.308548 2182
36 A. Sanchez et al.
the model in Red-Green-Blue (RGB) format. The code must be modi¯ed as shown in
Sec. 3.
base.Link ¼ 0;
base.robot ¼ [];
base.element1.name ¼ 'IRB120n base';
base.element1.color ¼ [0.89 0.39 0.21];
View Info. The selected maximum and minimum axes limit and camera angles are
shown below:
minX ¼ 0:4; minY ¼ 0:8; minZ ¼ 0:4; maxX ¼ 1:0; maxY ¼ 1:8;
maxZ ¼ 1:0; AZ ¼ 40; EL ¼ 10;
MyIRB ¼ Robot(configIRB());
To show a plot of the robot in the export position use the showRobot
function.
MyIRB.showRobot()
MyIRB.setTransparency(0.5)
To set the robot in a speci¯c con¯guration, introduce a vector with the joint
angles in radians.
for i¼0:0.05:pi/2,
MyIRB.showRobot([i/4 i/4 0 i 0 0]);
drawnow;
end;
elevation to 10 degrees. To set a speci¯c view, e.g. x½0:5; 0:5; y½0:4; 0:4;
z½0; 0:8, azimuth ¼ 40 and vertical elevation ¼ 10, type the command:
MyIRB.configView([0.5 0.5 0.4 0.4 0 0.8 40 10]);
Fig. 10. Custom Schunk Arm (CSA), a 7-DOFs robot, with a detail view of link 3.
Representation of Robots in Matlab 39
show the robot with the updated position. Then, save the values with guidata
function.
handles.q(1) ¼ get(hObject,'Value');
handles.MyIRB.showRobot(handles.q);
guidata(hObject, handles);
To add more elements to the guide as in Fig. 6 the same steps are repeated.
5. Conclusion
In this paper, a novel open-source software tool to simulate realistic serial robots in
Matlab has been presented. The library allows loading the CAD models of the robot
links from ASCII or binary STL format in order to avoid a representation of the robot
based on wires. As such, it allows performing very realistic simulations (e.g. see Fig. 6 in
comparison to Fig. 1) in an easy and fast way, which is useful both for research and
teaching purposes due to the increase in simulation accuracy. The e®ectiveness and
usability of RoboClass use has been demonstrated throughout two application
examples. The class presented in this paper is ready to adapt the CAD models of each
robot manufacturer to Matlab environment in order to control serial robots in a
realistic scene. This adaptation must be done only once for a given robot before using it.
Since the class creates the robot parts from external con¯guration ¯les, it is
possible to include di®erent robots in the same workspace, see Fig. 12, or even to
include other elements of the manufacturing process (e.g. elements of the production
line, security elements, manipulated pieces, etc.) in order to get a more complete
simulation scene.
Although the class has been developed for serial arms, it is possible to use it with
other kinematic architectures, like parallel kinematic machines. The class is basically
a wrapper for the mechanical information (STL and dynamic parameters) and the
robot analysis libraries (Robotics Toolbox). When using another toolbox for parallel
robots, like the one for a 3UPS1S robot in [17] or the toolbox for planar 3RRR device
[18], the class could be extended to use it with this kind of mechanism but it will be a
di®erent class for each parallel robot, not a generalized class like in the case of serial
robots.
The developed tool is especially useful both for robotics research and teaching in
order to show a realistic representation of the robot and its environment in the
widespread software Matlab. Moreover, the user can customize the open source code
to its requirements and use the advanced functions to get an accurate simulation.
The main advantages of the simulation tool developed in this work are
listed below
References
1. M. Bashari, E. Bagheri and W. Du, Dynamic software product line engineering: A ref-
erence framework, Int. J. Softw. Eng. Knowl. Eng. 27(2) (2017) 191–234.
2. K. Honda, H. Washizaki and Y. Fukazawa, Generalized software reliability model con-
sidering uncertainty and dynamics: Model and applications, Int. J. Softw. Eng. Knowl.
Eng. 27(6) (2017) 967–993.
3. Z. K. Aghdamand and B. Arasteh, An e±cient method to generate test data for software
structural testing using arti¯cial bee colony optimization algorithm, Int. J. Softw. Eng.
Knowl. Eng. 27(6) (2017) 951–966.
4. M. Flanders and R. C. Kavanagh, Build-A-Robot: Using virtual reality to visualize the
Denavit–Hartenberg parameters, Comput. Appl. Eng. Edu. 23(6) (2015) 846–853.
5. N. A. Bates, A. L. McPherson, R. J. Nesbitt, J. T. Shearn, G. D. Myer and T. E. Hewett,
Robotic simulation of identical athletic-task kinematics on cadaveric limbs exhibits a lack
of di®erences in knee mechanics between contralateral pairs, J. Biomech. 53(28) (2017)
36–44.
6. A. Doshi, R. T. Smith, B. H. Thomas and C. Bouras, Use of projector based augmented
reality to improve manual spot-welding precision and accuracy for automotive
manufacturing, Int. J. Adv. Manuf. Technol. 89(5–8) (2017) 1279–1293.
7. P. Corke, A robotics toolbox for MATLAB, IEEE Robot. Autom. Mag. 3(1) (1996)
24–32.
8. F. Chinello, S. Scheggi, F. Morbidi and D. Prattichizzo, Kuka control toolbox, IEEE
Robot. Autom. Mag. 18(1) (2011) 69–79.
42 A. Sanchez et al.