Sie sind auf Seite 1von 8

Programming Robotic & Automation Applications from Matlab

Fernando Brando, Joo Vaz, J. Norberto Pires


Mechanical Engineering Department
University of Coimbra
Polo II Campus, 3030 Coimbra, Portugal
brando, vaz, norberto @robotics.dem.uc.pt

Correspondi ng Author:
J. Norberto Pires
Mechanical Engineering Department
University of Coimbra
Polo II Campus, 3030 Coimbra, Portugal

Tel. 239 790712


Fax. 239 790701

Programming Robotic & Automation Applications from Matlab


Fernando Brando, Joo Vaz, J. Norberto Pires
Mechanical Engineering Department
University of Coimbra
Polo II Campus, 3030 Coimbra, Portugal
brando, vaz, norberto @robotics.dem.uc.pt

Abstract
In

this

is one of those applications that provide to the user a


paper

object-oriented and distributed

powerful mathematics environment, very popular for

architecture to interface Robotic & Automation (R&A)

teaching and research tasks on R&A. And that is so

equipment with a Personal Computer (PC), introduced in

because Matlab is a powerful linear algebra tool, with a

[12], is used from Matlab [16]. The above mentioned

very good collection of toolboxes that extend its basic

architecture

Win32

functionality. In this paper we present a toolbox that

environments, using standard visual programming tools

enable access to real R&A equipment from the Matlab

(Microsoft Visual C++ and Basic) and mathematical

shell. If used in conjunction with a robotics toolbox

packages (Matlab). Within the paper we focus mainly on

[2][3][4] it will extend significantly their application, i.e.,

using Matlab with the presented architecture. Application

besides robotic simulation and data analysis the user can

examples using an industrial robot are also presented.

interact on-line with the equipment he is using. Our

was

an

designed

to

work

under

personal experience with this tool shows its usefulness for


Keywords :

Robotics,

Automation,

Software

Object-oriented

for

Robotics

programming,

and

research applications, but also for teaching projects. With

Matlab

students, using Matlab means taking advantage of the less

toolbox.

training required to start using it, if we compare with


other programming environments and languages we also

1. Introduction.

use (Microsoft Visual C++ or Visual Basic).

Current Personal Computers have sufficient computing


power that candidate them to be used as host computers in

2. Software design & interfacing Matlab.

industrial

for

Using some equipment from a computer, i.e., exploring

monitoring applications, but also for programming and

the equipment functionality remotely in a distributed way

control applications. Specially they can be used to

means writing specific code and data structures to handle

program and control R&A equipment even when they are

all its functionality. If we want to be able to distribute the

organized in Flexible Manufacturing Cells (FMC) [12].

code and use it in several applications in a easy way, the

Using a PC is also taking advantage of the enormous

best solution is to build a software component (using

variety of applications available on those platforms for

ActiveX [5] or JAVA [6]) and integrate it with each

programming, data analysis and presentation, etc. Matlab

project. Fortunately there are many development tools,

distributed

environments,

not

only

most of them visual, that can act as containers of software


built

using

the

above

DDE Client
Applications
DDE Server

mentio ned

technologies.

OLE
ActiveX
Force/Torque
Sensor Object

Force/Torque
Sensor Board

offer to Matlab a collection of services to be acces sed

OLE

lot of solutions in the market that use DDE to expose

ActiveX
Force/Torque
Sensor Object

services to other applications [14][15].

RPC
Server

Messages

using the Matlab DDE implementation [1][7]. There are a

DDE Services

ActiveX
Robot
Communication
Object

Since Matlab is an interpreted language and can act as


Board
NT Kernel
Driver

DDE Callback
Function
OLE

Interfacing Matlab may be done just by using DDE [5].

DDE client, it is fairly easy to build a DDE server that can

DDE

Portm
aper

components

Windows
Dialog
OLE

RP
C
Ca
Sy
lls
nc
.A
nsw
ers
Asy
nc. M
sg.

Robot Control System

RPC
Server
Programs

alls
CC
RP
ers
nsw
c. A
Syn

ActiveX
Robot
Communication
Object

Another way is by using Matlab MEX functions,


embedding into Matlab the software components or

Win32 Application

libraries used to explore the equipment functionality.

Fig. 1 - Basic software architecture [12][16].

Services (client and server sides) can be thought as


"options" of a multi-parameter driven function that can be

In this paper we focus only on the interface to an

called

data

industrial robot (ABB IRB1400 using the S4 control

representation protocols. Implementing service calls using

system). The interested reader can find the interface to

MEX functions is straightforward. In conclusion, the

other equipment in [12][16], and download freely this

basic idea is simple. For each equipment we need to

software

design and build a server (if it is not yet available) to

http://www.dem.uc.pt/norberto/.

remotely

using

some

calling

and

and

other

related

tools

from

expose the equipment functionality as remote services.


The technology to build the server is highly dependent on

3. Interfacing an Industrial Robot.

the equipment resources and computing facilities, but if

The module briefly presented here (MATABBS4) [16]

possible some kind of RPC (Remote Procedure Calls) [8]

works with any ABB robot equipped with the S4

mechanism should be used. Software controls that explore

controller [9]. It implements calls to all services available

these services should then be available as basic tools to

from the robot controller (RPC servers). ABB S4

develop remote and distributed applications using the

controllers implement RPC server programs [10] with

selected equipment(s). Finally, the Matlab interface to

variable access services, file and program management

those equipments is built just by emb edding the above

services and system status services. To access those

mentioned software controls into MEX functions.

services the host computer (client) must implement RPC

That has been done for several type of R&A equipment

calling code through an ethernet or serial connection

[12][16]: a robotic manipulator, a force/torque sensor, a

(both using TCP/IP protocols). ABB also developed an

microcontroller board, a CCD camera, etc. The all

Application Specific Protocol (ASP) called RAP [10] to

collection of functions constitutes the Matlab toolbox

be used with these services. The RAP messaging protocol

MATROBCOM.

works in the same way as MMS specified for MAP


networks

[11].

To

implement

the

PC-Robot

RAPID
Aplication

communication code based as mentioned on RPCs using

Error in 'motor_on' RPC call: Error Code: -1114

RAP, the facility developed by the Sun Microsystems


Open Computing (ONC) Group named SUN RPC 4.0

ans = -1114. The returned error code means "Invalid


System State", and is printed on ABB manuals.

ported to Windows NT 4.0 or later, has been used. User


services may be implemented using the basic RPC

>> matabbs4 ('program_prep', line)

services, written using the Rapid programming language


(available at the robot controller). A simple switch-case-

ans = 0
>> matabbs4 ('program_run', line)

do loop driven by a parameter remotely controlled would

ans = 0

do the job. The all list of functions available in the


module is presented in Table I.

To check system state the command is,


>> matabbs4 ('sysstate', line)'

The robot may be connected to the computer using a

ans =

serial port or preferably an ethernet port, both using

? Error code (0 = OK).

TCP/IP protocols. If a local area netwo rk is available,

? Controller State (Stand By).

several users/computers may be connected to the robot at

the same time (with a line or channel open), and then

? Operational State (Auto Mode).

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

? Number of Programs Loaded (1).


? Program Controller State (Stopped State).
? Program State (Initiated).
? Space Available on System Memory (%).

MATABBS4.
The user should check system state after any system
To open a connection to the robot the command is,

change state command to confirm system change and to

>> line = matabbs4 ('open', 'babylon', 'reserved')

determine when to start commanding the system. For

line = 1

example, if a 'program_run' command is issued the user

where 'babylon' is the name of the robot as declared in the

should wait until the controller state is 'Run State = 4',

DNS table or system "hosts" file.

before starting using the features of the loaded robot


program. Checking the system state can be performed in

Load and start a program,

cycle until a condition is met, or by monitoring the RPC

>> matabbs4 ('program_load', 'flp1:\example.prg', line)

messages from the robot.

ans = 0
Table I - Functions available in the MATABBS4 module [16].

>> matabbs4 ('motor_on', line)


ans = 0

If the robot is not in "AUTO MODE" then,


>> matabbs4 ('motor_on', line)

Function
open
close
motor_on
motor_off
prog_stop

Brief Description
Opens a communication line with a
robot (RPC client)
Closes a communicatio n line.
Go to Run State
Go to Standby State
Stop running program

prog_run
prog_load
prog_del
prog_set_mode
prog_get_mode
prog_prep
pgmstate
ctlstate
oprstate
sysstate
ctlvers
ctlid
robpos
read_xxxx

read_xdata
write_xxx

write_xdata
digin
digout
anain
anaout

Start loaded program


Load named program
Delete loaded program
Set program mode
Read actual program mode
Prepare Program to Run (Program
Counter to begin)
Get Program Controller State
Get Controller State
Get Operational State
Get System State
Get Controller Version
Get Controller ID
Get current robot position
Read variable of type xxxx (there
are calls for each type of variable
defined in RAPID [9])
Read user defined variables
Write variable of type xxxx (there
are calls for each type of variable
defined in RAPID [9])
Write user defined variables
Read digital input
Set digital output
Read analog input
Set analog output

9.0000e+009

? Position of External Axis 1

9.0000e+009

? Position of External Axis 2

9.0000e+009

? Position of External Axis 3

9.0000e+009

? Position of External Axis 4

9.0000e+009

? Position of External Axis 5

9.0000e+009

? Position of External Axis 6

Note: 9.0000e+009 means that the external axis is not


currently in use.

Reading and acting on IO,


>> matabbs4 ('digin', 5, line) ?
digital input 5.
ans = 1

output 7.
ans = 0
>> matabbs4 ('anain', 2, line) ?
analog input 2.

>> matabbs4 ('robpos', line)'

ans = 3453

? Error code.

Signal is ON

>> matabbs4 ('digout', 7, 1, line) ? to activate the digital

To read current robot position the command is,

ans =

to read the value of

to read the value of

>> matabbs4 ('anaout', 1, 236, line) ? to write the value


236 on analog output 1.

4.6833e+002

? Cartesian X position.

2.0689e+002

? Cartesian Y position.

1.2061e+003

? Cartesian Z position.

5.2125e -002

? Quaternion (q 1 ).

-2.3500e-001

? Quaternion (q 2 ).

4.3565e -001

? Quaternion (q 3 ).

-8.6733e-001

? Quaternion (q 4 ).

? Configuration data (ABB CF1).

>> matabbs4 ('read_bool', 'name', line) ?

? Configuration data (ABB CF4).

state of a 'bool' variable.

1.0000e+000

? Configuration data (ABB CF6).

ans = 1

? Configuration data (ABB CFx).

ans = 0

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
reading the

Variable is TRUE.

Suppose that we have a robot program (written in RAPID

>> matabbs4 ('write_num', 'decision', 1, line)

[9], a robot programming language from ABB Robotics)

ans = 0

running, which is switched by a variable named, let say,


'decision'. The basic structure of the program would be

checking between each vector if the last comma nd was

something like (using a C-type definition),

already performed, i.e., when the next call outputs -1,

while never_end;
switch decision

>> matabbs4 ('read_num', 'decision', line)


The resulting motion would not be continuous but a

case 1: call routine_1; break;

sequence of "steps". A continuous motion can be easily

case 2: call routine_2; break;

achieved by redesigning routine_1 to accept a matrix of

'robtargets' and defining zones sufficiently large to avoid

case n: call routine_n; break;

stops between each point of the trajectory. We

end_switch;
end_while;

implemented a 'play_trj' service as described to accept


trajectories with up to 500 points.

Suppose again that routine_1 moves the robot from actual

Note: With the new versions of RAPID there is also the

position to another one defined by a position variable

possibility to command joint vectors directly using the

named 'new_pos' of the type robtarget. Routine_1 should

new 'jointtarget' structures. With the new versions, with a

then be something like,

slight modification in routine_1 we can start commanding

PROC routine_1
MoveJ to new_pos;

joint vectors directly (the write jointtarget calls were also


implemented in MATABBS4).

decision = -1;
ENDPROC

Figure 2 shows a two-finger gripper attached to the robot

From within Matlab we can then use the MATABBS4

through a tool changer (from ATI Inc., USA). A

module to command new positions to the robot. Those

force/torque sensor is also included (from JR3 Inc., USA),

positions could be defined as a set of joint vectors

although it is not used in this example. The gripper is

specifying the joint angles to be achieved. We should then

based on a pneumatic module (from Zaytran Inc., USA),

run a forward kinematics function to obtain the positions

having an air pressure regulator to control the grasp force.

in cartesian coordinates, with orientation in quaternions

Currently there is no force feedback, so we use an open-

and using the ABB configuration definition. For that we

loop control approach based on the mapping between the

can use any forward kinematics function from one of the

analog input to the air pressure regulator and the force

available robotics toolboxes [2][3][4] and then convert the

between the fingers. That mapping was obtained by

4x4 transformation matrices into 'robtarget' structures. In

taking a few measures of commanded pressure (digital

[4] there is a function that does it all, outputting a matrix

value to the ADC) and the obtained grasp force, using a

with one 'robtarget' per matrix line. If we name that

F/T sensor inserted between the two fingers. The open

matrix 'pos' we could then command it to the robot with

loop transfer function was then obtained using the Matlab

the commands,

function 'polyfit'. This means that before commanding the

>> matabbs4 ('write_robtarget', 'new_pos', pos[1,:], line)

gripper to close, we need to select the required analog

ans = 0

value (actually the digital value to the ADC of the analog

Move to final position and place object,

board) appropriate to the desired grasp force,

>> matabbs4 (write_robtarget, new_pos, pos_3, line)


>> matabbs4 (write_num, decision, 1, line)
? MOVE pos_3
>>matabbs4 (digout, 1, 0, line) ? PLACE object
Move away,
>> matabbs4 (write_robtarget, new_pos, pos_2, line)
>> matabbs4 (write_num, decision, 1, line)
? MOVE pos_2.
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

Fig. 2 Two finger pneumatic gripper.

remotely before commanding any motion. For example, if


we write routine_1 in the form,

>>ana_value = pressure_force_map (required_force)


ana_value = digital value to command to the ADC

PROC routine_1
SetAcc n_acc;

A simple pick-and-place operation would be:

MoveJ to n_pos, with n_vel & new_prec;

Open Gripper and approach object,

SetAcc default_acc;

>> matabbs4 ('digout', 1, 0, line)

? OPEN Gripper

Move to grasp position and pick object,

decision = -1;
ENDPROC

>>matabbs4 (digout, 1, 0, line) ? OPEN Gripper


>> matabbs4 (write_robtarget, new_pos, pos_1, line)

where, 'n_acc', 'n_vel' and 'n_prec' are parameters that we

>>matabbs4 (write_num, decision, 1, line)

can change remotely and have predefined default values.

? MOVE pos_1

In this case, the motion to point 3 above, for example,

To select the grasp force,

should be commanded as follows,

>> ana_value = pressure_force_map (5)

>> matabbs4 ('write_num', 'n_acc', n_acc, line)

>> matabbs4 (anaout, 1, ana_value, line)

>> matabbs4 ('write_speeddata', 'n_velc', n_speed, line)

>> matabbs4 (digout, 1, 1, line)

>> matabbs4 ('write_zonedata', 'n_prec', n_precision, line)


? PICK object

? SET Values

Aproach final position (suppose that from pos_1 to pos_2

>> matabbs4 ('write_robtarget', 'n_pos', pos_3, line)

there are no obstacles),

>> matabbs4 ('write_num', 'decision', 1, line)

>> matabbs4 (write_robtarget, new_pos, pos_2, line)


>> matabbs4 (write_num, decision, 1, line)
? MOVE pos_2

? MOVE pos_3
This pick and place operation was used for playing chess
were the robot moves the pieces. The application will be
presented in the conference, and uses different grasp
forces for each type of chess piece. User plays chess with

the mouse, the robot moves the pieces and confirms

[3] Corke PI., "A Robotics Toolbox for Matlab", IEEE

moving operations (which updates user screen), and the

Robotics and Automation Magazine, 1996;3(1):24-

CCD camera enables final visual verification of players

32.

moves.

[4] Pires JN. and S da Costa JMG., "Ferramentas de

4. Timing

Software para Controlar, Programar e Monitorizar

All calls to the robot require between 10 and 15 ms

um

depending on the data structure to write or read, if an

Computadores

ethernet connection is used. If a serial connection is used

Mechanical

(19200 bps) the access time goes up to around 200 ms.

1998;2(1):43-67.

Rob

Manipulador

Industrial

Pessoais",

Engineering

usando

Ibero-American

Association

Magazine,

All calls are made with confirmation, i.e., a code is sent

[5] Box D., "Essential COM", Addison-Wesley, 1998

back informing about call success or cause of failure.

[6] Camplone M. and Walrath K., The JAVA TM

5. Conclusion.
In this short paper we demonstrated one technique to
interface R&A equipment with personal computers. The
paper focuses on using the Matlab environment to
interface the selected equipment. The solution is based on
a distributed software architecture that may be used to
include support to other type of equipment. In fact other
modules were built with it, not presented in the paper, to
handle force/torque sensors, CCD cameras, PLCs and
microcontrollers. With this type of interface even non-

Tutorial, 2nd Edition, Addison-Wesley, 1998.


[7] Matlab API Reference, The MathWorks Inc., USA,
http://www.mathworks.com.
[8] Bloomer

J.,

"Power

Programming

with

RPC",

O'Reilly & Associates, Inc., 1992.


[9] ABB

IRB1400

Users

Manual,

ABB

Flexible

Automation, 1997.
[10] RAP, Service Protocol Definition, ABB Flexible
Automation, 1996.
[11] Halsall

F.,

"Data

Communications,

Computer

trained users can easily use actual R&A equipment, since

Networks and Open Systems", Third Edition,

Matlab is a fairly simple environment to use. This is

Addison-Wesley, 1992.

particularly true with students, as our personal experience

[12] Pires JN, S da Costa JMG, Object Oriented and

clearly show. The ideas presented here were then applied

Distributed Approach for Programming Robotic

to an industrial robot and demonstrated with an example

Manufacturing Cells, IFAC Journal on Robotics and

were the robot moves the pieces of a chess game, played

Computer Integrated Manufacturing, February 2000.

by two users on different computers . More info about this

[13] Pires

JN,

Controlo

de

Fora

em

Robs

work including videos may be found in the URL:

Manipuladores Industriais, Ph.D. Thesis, University

http://www.dem.uc.pt/norberto/seminarios/

of Coimbra, June, 1999.


[14] Factory

References:
[1] Matlab Users Guide, The MathWorks Inc., USA,
http://www.mathworks.com.
[2] Gourdeau R., "Object Oriented Programming for

Suite

2000,

Wonderware

Inc,

USA,

http://www.wonderware.com
[15] ABB

DeskWare,

ABB

Flexible

Automation,

http://www.abb.se.
[16] Pires JN, Using matlab to interface robotic and

Robotic Manipulator Simulation", IEEE Robotics and

automation

equipment,

IEEE

Robotics

Automation Magazine, 1997;4(3):21-29.

Automation Magazine, September 2000.

And

Das könnte Ihnen auch gefallen