Matlab Tool
Matlab Tool
J. Norberto Pires
Mechanical Engineering Department
University of Coimbra
Polo II Coimbra, Portugal
http://www.dem.uc.pt/norberto/
[email protected]
1. Introduction.
Matlab [1] is a widely used software environment for research and teaching applications
on robotics and automation, mainly because it is a powerful linear algebra tool, with a
very good collection of toolboxes that extend Matlab basic functionality, and because it is
an interactive open environment. In this short paper we present a toolbox that enables
access to real robotic and automation (R&A) equipment from the Matlab shell. If used in
conjunction with a robotics toolbox [2][3][4] it will extend significantly their application,
i.e., besides robotic simulation and data analysis the user can interact on-line with the
equipment he is using. Our personal experience with this tool shows its usefulness for
research applications, but also for teaching projects. With students, using Matlab means
taking advantage of the less training required to start using it, if we compare with other
programming environments and languages we also use (Microsoft Visual C++ or Visual
Basic).
This paper is organized as follows: Section 2 briefly presents the software architecture
adopted and how it was used to generate the Matlab MEX files presented in the paper.
Section 3 exemplifies application to two types of equipment, complemented with a
generic manipulation example using a robotic gripper. In section 5 the utilization of this
tool with force control experiments is briefly explored. Finally conclusions are drawn in
section 6.
(preferably ActiveX [5] or JAVA [6]). Using a software control means implementing
methods and data structures that hide from the user all the tricky parts about how to
have things done with some equipment, focusing only on using its functions in a easy
way. Beside that, those components are easily integrated into new projects built with
programming tools that can act as containers of that type of software controls, i.e., they
can be added to new projects in a "visual" way.
To interface Matlab the general approach is by using DDE [5]. Since Matlab is an
interpreted language and can act as DDE client, it is fairly easy to build a DDE server that
can offer to Matlab a collection of services to be accessed using the Matlab DDE
implementation [7]. Using DDE is a common and largely used solution to exchange data
between applications, even in industrial environments. For each equipment we need to
have the specific set of services available from the DDE server, and then build the calling
routines as M-files [1]. Simple. But we can do better. Services (client and server sides)
can be thought as "options" of a multi-parameter driven function that can be called
remotely using some calling and data representation protocols. Matlab MEX functions are
parameter driven functions that can be easily used to implement service calls, just by
embedding the previous mentioned libraries or software controls within the MEX function.
We have done that for several types of R&A equipment building a MEX function (or
module) for each one. The all collection of modules constitutes the Matlab toolbox
MATROBCOM. In conclusion, the basic idea is simple. For each equipment we need to
design and build a server (if it is not yet available) to expose the equipment functionality
as remote services. The technology to build the server is highly dependent on the
equipme nt resources and computing facilities, but if possible some kind of RPC (Remote
Procedure Calls) [8] mechanism should be used. Software controls that explore these
services should then be available as basic tools to develop remote and distributed
applications using the selected equipment(s). Finally, the Matlab interface to those
equipments is built just by embedding the above mentioned software controls into MEX
functions.
Submitted to IEEE Robotics and Automation Magazine, November 1999
DDE Client
Applications
DDE Server DDE
DDE Callback
Function
OLE
ActiveX OLE
Force/Torque DDE Services
Sensor Object
ActiveX
Robot
Communication
Object
Force/Torque
Sensor Board
RP
C
Board Sy Ca
nc. lls
NT Kernel An Robot Control System
Driver RPC sw
Messages ers
er
Server
map
Asy
nc. M
Port
sg. RPC
Server
Programs RAPID
Windows Aplication
Dialog lls
OLE C Ca
RP ers
sw
ActiveX OLE
c. An
Force/Torque n
Sy
Sensor Object
ActiveX
Robot
Communication
Object
Win32 Application
In the following sections we'll demonstrate how to implement the above-presented ideas,
using two specific equipments: an industrial robot and a force/torque sensor.
The robot may be connected to the computer using a serial port or preferably an ethernet
port, both using TCP/IP protocols. If a local area network is available, several
users/computers may be connected to the robot at the same time (with a line or channel
open), and then MATABBS4 keeps track of actual open lines/channels. Opening a line
means starting a client connection to the RPC servers running on the robot. In the
following we will demonstrate a few capabilities of the module MATABBS4.
Submitted to IEEE Robotics and Automation Magazine, November 1999
The user should check system state after any system change state command to confirm
system change and to determine when to start commanding the system. For example, if
Submitted to IEEE Robotics and Automation Magazine, November 1999
a 'program_run' command is issued the user should wait until the controller state is 'Run
State = 4', before starting using the features of the loaded robot program. Checking the
system state can be performed in cycle until a condition is met, or by monitoring the RPC
messages from the robot.
Acting on program variables defined in RAPID (see Table I) or user defined variables
(XDATA type),
>> matabbs4 ('write_num', 'name', value, line) writing on a type 'num' variable.
ans = 0
>> matabbs4 ('read_bool', 'name', line) reading the state of a 'bool' variable.
ans = 1 Variable is TRUE.
Suppose that we have a robot program (written in RAPID [9], a robot programming
language from ABB Robotics) running, which is switched by a variable named, let say,
'decision'. The basic structure of the program would be something like (using a C-type
definition),
while never_end;
switch decision
case 1: call routine_1; break;
case 2: call routine_2; break;
…
case n: call routine_n; break;
end_switch;
end_while;
Suppose again that routine_1 moves the robot from actual position to another one
defined by a position variable named 'new_pos' of the type robtarget. Routine_1 should
then be something like,
PROC routine_1
MoveJ to new_pos;
decision = -1;
ENDPROC
From within Matlab we can then use the MATABBS4 module to command new positions to
the robot. Those positions could be defined as a set of joint vectors specifying the joint
angles to be achieved. We should then run a forward kinematics function to obtain the
positions in cartesian coordinates, with orientation in quaternions and using the ABB
configuration definition. For that we can use any forward kinematics function from one of
the available robotics toolboxes [2][3][4] and then convert the 4x4 transformation
matrices into 'robtarget' structures. In [4] there is a function that does it all, outputting a
Submitted to IEEE Robotics and Automation Magazine, November 1999
matrix with one 'robtarget' per matrix line. If we name that matrix 'new_positions' we
could then command it to the robot with the commands,
checking between each vector if the last command was already performed, i.e., when the
following call outputs -1,
>> matabbs4 ('read_num', 'decision', line)
Note: With the new versions of RAPID there is also the possibility to command joint
vectors directly using the new 'jointtarget' structures. With the new versions, with a
slight modification in routine_1 we can start commanding joint vectors directly (the write
jointtarget calls were also implemented in MATABBS4).
Figure 2 shows a two finger gripper attached to the robot through a tool changer (from
ATI Inc., USA). A force/torque sensor is also included (from JR3 Inc., USA), although it is
not used in this example. The gripper is based on a pneumatic module (from Zaytran
Inc., USA), having an air pressure regulator to control the grasp force. Currently there is
no force feedback, so we use an open-loop control approach based on the mapping
between the analog input to the air pressure regulator and the force between the fingers.
That mapping was obtained by taking a few measures of commanded pressure (digital
value to the ADC) and the obtained grasp force, using a F/T sensor inserted between the
Submitted to IEEE Robotics and Automation Magazine, November 1999
two fingers. The open loop transfer function was then obtained using the Matlab function
'polyfit'. This means that before commanding the gripper to close, we need to select the
required analog value (actually the digital value to the ADC of the analog board)
appropriate to the desired grasp force,
Approach final position (suppose that from pos_2 to pos_3 there are no obstacles),
>> matabbs4 ('write_robtarget', 'new_pos', pos_3, line) MOVE pos_3
>> matabbs4 ('write_num','decision', 1, line)
Move away,
>> matabbs4 ('write_robtarget', 'new_pos', pos_3, line) MOVE pos_3
>> matabbs4 ('write_num','decision', 1, line)
This is a very simple example where we didn't care about selecting the velocity, the
position accuracy, the acceleration, etc. All that can be also parameterized remotely
before commanding any motion. For example, if we write routine_1 in the form,
Submitted to IEEE Robotics and Automation Magazine, November 1999
PROC routine_1
SetAcc new_acc;
MoveJ to new_pos, with new_velocity and new_precision;
SetAcc default_acc;
decision = -1;
ENDPROC
where, 'new_acc', 'new_velocity' and 'new_precision' are parameters that we can change
remotely and have predefined default values. In this case, the motion to point 3 above,
for example, should be commanded as follows,
that detects the running operating system (OS) and initializes IO access if the OS used is
Windows NT (a kernel driver should then be present to access the sensor DSP receiver
board). In the following some commands are exemplified.
xa(k-1)
PC/WinNT/Win95 Robot Control System
fd - e(k) Force
ke dxd(k) + xd(k) Position x a(k) fa(k)
+ Control kx Environment
1-z -1
kd Controller
Law
de(k)
Force/Torque
Acquisition
Board
The controller input variables are the force/torque error e(k) and error variation de(k):
where fa (k) is the measured wrench and fd (k) is the measured wrench. The controller
output is the position/orientation accommodation, assumed to be small:
Submitted to IEEE Robotics and Automation Magazine, November 1999
{6} { 6}
? x di (k)? {F } R.{F } ? x di(k)
(2)
{6}
? ? di(k )? {{6F}} R.{F} ? ? di (k)
{6} {6}
where ? xdi(k) is the position accommodation, ? ? di(k) is the orientation
accommodation and {F} and {6} are the frames associated with the wrist force/torque
sensor and robot tip, respectively.
The force control function may implement several force control approaches under the
indirect force control framework: classical approaches (PID controllers), fuzzy, etc.
Nevertheless, the following conditions should be considered:
a) Simplicity. The force control law must be simple and easy/faster to compute to enable
real time.
b) PI-type control. If a null steady state error is to be achieved a PI-type force control
law should be selected. The derivative term is not desirable due to the noise associated
with force readings.
c) Robustness to environment stiffness. The system should work with several
environment stiffness constants (the environment is modeled as a linear spring), which
generally happens under industrial environments.
d) Implementation requirements should not include significant changes to the original
control system.
To command position accommodations to the robot, a routine like the one above
(presented in a simplified form) should b running in the robot controller.
PROC contact
WHILE not_done & not_abort
IF (delta_z <> 0 OR delta_y <> 0 OR delta_x <> 0) THEN
Submitted to IEEE Robotics and Automation Magazine, November 1999
The control cycle implemented in Matlab starts reading the actual force, then computes
the position accommodation, commands the accommodation to the robot and waits to
the end_of_command message (sent when notify_end changes state). The robot sends
an RPC call (named spontaneous message) to a RPC server running in the PC [12][13],
which fires a DDEPoke command to Matlab; if a DDE connection is established Matlab can
detect the message and start the next cycle. Another approach is to check the variable
'notify_end' until it changes state, as already mentioned.
The experimental setup, the force profile commanded to the robot and the measured
force are presented in fig.5.
Submitted to IEEE Robotics and Automation Magazine, November 1999
-2
-4
-6
-8
Fz [N]
-10
-12
-14
-16
-18
-20
0 100 200 300 400 500 600
Amostras
Table III. Levels for fuzzy variables: a1 , b1 , a2 and b2 are set by the user to define the
dead zone. The distribution is similar for the negative ranges (in that case the levels are
also negative).
20 ? 30 20 ? 25 +5
30 ? 40 25 ? 30 +6
40 ? 50 30 ? 35 +7
50 ? 75 35 ? 50 +8
> 75 > 50 +9
The discussion of force control approaches and their implementation details is out of the
scope of this paper. Nevertheless, the interested reader can find some application inside
and results of a fuzzy-PI controller in [13].
Submitted to IEEE Robotics and Automation Magazine, November 1999
6. Conclusion.
In this short paper we showed how to use R&A equipment from within Matlab, based on a
distributed software architecture that may be used to include support to other type of
equipment. In fact we built wit it several other modules, not presented in the paper, to
handle CCD cameras, PLCs and microcontrollers. With this type of interface even non-
trained users can easily use actual R&A equipment, since Matlab is a fairly simple
environment to use. This is particularly true with students, as our personal experience
clearly show. The ideas presented here were then applied to an industrial robot and to an
intelligent sensor (force/torque sensor), and demonstrated with several examples. Finally
a force control experiment was briefly introduced with the objective of demonstrating an
R&D application of the presented setup.