You are on page 1of 93

&


:5591

U M L

, 2009

U M L



(.. 5591)


10/07/2009

K.

U M L

H (Unified Modeling Language)


, ,
.
UML
,
. , ,

. UML

. ,
,
.
UML
. , UML
,
Festo MPS. ,
Festo MPS
.

.........................................................................................10
1
1.1
1.2
1.3
1.4
1.5

.....................................................................12
.....................................................................13
.......................................................................15
..............................................................17
..............................................................20

2
2.1
2.2
2.3
2.4
2.5

FestoMPS.........12

UML........................................22

.................................................................................22
.....................................................................................23
UML...................................................................24
UML......................................................25
UML ..........39


......................................................44

3.1 .....................................................................................44
3.2 .......................................................45
3.2.1 ............................................................45
3.2.2 ................................................................48
3.3 ...................................................52
3.3.1 .....................52
3.3.2
.......58
3.3.3 ...........................59

.........................62

4.1
...................................................62
4.2
................................................................................66
4.3
..................................................................................70
4.4
.........................................................................74
4.5 ,
.....................................................77
5

.........................80

..............................................................................90
.......................................................................................92


UML
.
,
(patterns) ,
(stereotype)
, (traceability)

.
, . .


.



,
,
,
.

. , ,
.
.

.

. , ,
, .
,
.
,

.
, (Unified Modeling
Language),
,
.
, .

.


. UML
,

. , UML


.
UML
. ,
UML
, Festo MPS,
Java .

10


Festo MPS.

1 FestoMPS. To Festo MPS



Festo .
, ,
.
.
2 UML
. , UML
.
UML UML
2.0. , UML
, .
3
Festo MPS UML.

.
,

Festo MPS.
4 Java
Festo MPS. :
,
,

.
5 Festo MPS.
Festo MPS
.
Socket.
Java
.

11


Festo MPS

1.1
Festo MPS (Modular Production System)
Festo
( 1.1).
:

(Distribution station )
(Test station)
(Processing station)
(Warehouse station)

(workpieces),
(, , ), (,
) .

(actuators). (sensors) ,
, ,
, .

12

1.1 Festo Modular Production System


[1].

1.2
.
(push out cylinder / feeder),

.
( ) .

(Converter) . 1.2
.

13

1.2

Converter .
Converter
( ). ( 1.3)

1.3 Converter

(actuators)
1.1:

14

1.1

1.3


.
( ) (,
). (Elevating
platform)
(pneumatic cylinder for the elevator platform / Elevator)
( 1.4).
,
.
(Transport belt)
(Shift out cylinder).

15

1.4

. 1.5
.

1.5

16

- (
- )
Shift out cylinder. - ,
:

Shift out cylinder
.
(actuators)
1.2

1.2

1.4
.
-1

. -1 .
90 -2
(Drilling machine) ( 1.6). -2
.
(holder)
(brack in).

(pneumatic lifting cylinder).

(brack out).
90 -3 ( 1.7).

17

1.6

-3
(Checking machine).
(pneumatic testing cylinder)
. 90
-4.

1.7

18

-4
(Warehouse Cylinder)
.
(actuators)
1.3.

1.3

19

1.5


. .
( 1.8)

1.8

20

21

UML

2.1
,
(Unified Modeling Language UML)
, , ,
(artifacts)
[2]. UML industry standard

( ).


. ,
.
,
(patterns)
, (stereotype)
, (traceability)

. , UML
,
.[3]
UML .
UML ,
.
,
,
.
UML : ,
, ,
, , .

22

2.2
,
Fortran, Pascal C, 1970
(software crisis).
(Structured
Analysis and Design) .
Simula (1967),

1980 Smalltalk, C++
Java.
,
90 , ,
. [4]

Rational Software Corporation 1994 Grady Booch
James Rumbaugh. ,
, Booch -2
James Rumbaugh. 1995
Ivar Jacobson, OOSE Objectory
. UML
,
Unified
Modeling Language.
UML, :
( )
.
(artifacts).
, , . ,
,
. [3]
UML (UML 1.1) 1997.
(UML 1.3, UML 1.4, UML 1.5),
.
UML 2.0,
OMG (Object Management Group) 2005,
UML 2.2.

23

2.3 UML
UML.
,
(view). ,
.

. ,
.
,
.
,
.
(coherent)

. UML ( 2.1) :

2.1 UML [5]


(Use case view) :
,
(actors).
.
(use case diagrams)
(activity diagrams).

,
.
,
.

.

24

(Logical view) :
,
. ,
.
,
, , .
(Component view) :
.
.
, ,
, .
(Concurrency view) :
. ,
, ,
,
.
,
.
( , ,
), (
).
(Deployment view) :
, ()
, .
.

2.4 UML
UML :

(Use case diagram)


(Class diagram)
(Sequence diagram)
(Collaboration diagram)
(Statechart diagram)
(Activity diagram)
(Component diagram)
(Deployment diagram)

. [3][4][6]

25


UML
,
.

(actors).
(use cases).
.
,
, .
2.2:

association

generalization
UseCase

<<include>>

Actor

<<extend>>

2.2

,
,
.

, .
,

.
, ,
. ,
,
.
actor,
. 2.2.

, ,
.


.
26

,
.
(scenario),
(execution path) .
2.2.
:
1. .
2. .
3. ,
.
,
.
,
.
:
(extends), (uses includes) (grouping).
2.2.

, ,
.
.

.

,

. , ,
,
. ,
.

Festo MPS ( 2.3):

27

2.3 Festo MPS

28


.
, ,

.
, .

, ,
,
,
.


UML
, .

.

,
.
,
.

.

.
,
(problem domain model).
.
, , ,
,
.

,
. , ,

,
. , ,

,
, .. .
,
UML ,
. ,
,
.

29

, ,
.

.


. ,
. 2.4.
.

Feeder ( 2.4):

2.4 Feeder

UML :
: =
:
( ):
-, +, #,~
, ,
.
,
, UML
.
.
,
, (..
)
. UML
,
(link).
:
,
.
:
.

30

:

.
:
.
.
.
.
: ,

.
.
:
- - (whole-part).

,
. ,
. 3.6
FestoMPS.

2.6
:
.
, ,
,
. ,
.
: (interface)
.

(realization).
Festo MPS: ( 2.7)

31

2.7
UML ,
.
( Boole)
. UML
,
{}. , UML
(Object Constraint Language OCL).
Festo MPS
( 2.8)

2.8 FestoMPS

32



. ,
.


-
.

(lifeline). ,
UML (stimuli).

.
:
:
. ,

. .
,
. ,
.
:
. ,

-
.
.
:
.
, ..
:
.

.
,

[else],
.

,
, ... ,

33


.
2.9
Front position reached actor Feeder.

2.9 Front position


reached



.
,

.

.
.
,
(
).

2.9 2.10

34

2.10


,
.




.
(finite state
machine) . ,

. ,

.
,

.
.
,
.
.
UML ,
:

35

(event)
.
.
,
/.
(state)
.
,
,
.
.
.

. ,
,
,
.
Festo MPS
Feeder 2.11 .

2.11 Feeder



.

, .
,
,
36

.
,
, .

.

UML.
,


2.12 .

Activity1

2.12

() .
,

.

( )
.
,
,
.


(component)
,
.
.

.
.
, .
,
.

37

, ,
.

.
.


.

.
.
UML .



()
.
.
(node)
,
.
,
, ,
.

.
( )
.

,
.

.

, /,

,


.

38

2.5 UML

UML
,
.

.
H UML

,
( tagged attributes OCL [7]),
( ) (
classifiers tagged attributes). ,
:

(domain-specific) ,
(patterns) .
, ,

.
,
.

, ,
UML
.
,
, , [8]
, profile
UML domainspecific building blocks (
)
, profile
.
UML profile

platform resources ,
.

. [8]
UML Platform profile
embedded system platforms. domain-specific classifiers
,
UML UML Profile for Schedulability, Performance and Time

39

Specification ( Real-Time UML Profile) [9].



platforms
.

executable models


.


[10], UML
. 2.13

2.13 [10]
( 2.13
) concept
. concept
, ,
,
. concept


-.
o .
.
application models
, 2.14 :

40

2.14 application model [10]



,
UML.
. translatable
model,
[10]. 2.13
,
UML.
,
. ,
application model.
,
. executable UML,
.
,
. ,
,

. (actions)
executable UML.
,
.

executable UML .

.
model compiler. executable UML
model, .
2.14
2.15 .

41

2.15 [10]
elements executable UML.
, Class
, State
.
(metamodel).
model compiler ,
.
,
.
.
,
.
model compiler
C,C++ Assembly.
model-driven
. open model compiler
.
debugger. prototyper
,
hardware.
,

executable UML model debugging ,
.
, .

42

, .

. [10]

43

3.1

open source CASE tool StarUML. StarUML
, UML/MDA (Model Driven Architecture)
, Win32.

UML ,
Rational Rose. [11]
StarUML UML 2.0,
: , ,
, , ,
, , , robustness diagram
composite structure diagram. ,
(package diagram)
editor .
To StarUML / :

modeling features

UML
C++, C# Java
Reverse engineering
JPG/XMI format
load/execution time UML

verification

44

SVG format
Win32 platform
stub code,
,
.

3.2

.

.

3.2.1


.

.
, Feeder, o Converter, Elevator, o Shift-out cylinder, o
Rotating disc, Drilling machine, Checking machine o Warehouse cylinder.

.

.

. ,

.

,
,
.
.
, :
Front position reached ( actor Feeder)
Back position reached ( actor Feeder)
Workpiece in position A
Workpiece sucked in
Right stop reached

45

Left stop reached


Workpiece in position B
Front position reached ( actor Shift out cylinder)
Back position reached ( actor Shift out cylinder)
Elevator up
Elevator down
Workpiece in position 1
Workpiece in position 2
Workpiece in position 3
Workpiece in position 4
Rotation done
Workpiece bracked-in
Workpiece bracked-out
Lifting cylinder up
Lifting cylinder down
Checking cylinder up
Checking cylinder down
Cylinder returned to disc
Piece removed from table
Vakuum has been started
Initialize system
Start
Stop
Urgent stop
Get status

:
Use case:
Actor: Operator
Description: .
Feeder . use case
.
Use case: Front position reached.
Actor: Feeder
Description: O Feeder
. Feeder
.
. use case .
Use case: Elevator down.
Actor: Elevator
Description: O Elevator
.
Elevator . ,
. Shift out
cylinder . use case .
3.1 FestoMPS:
46

3.1 Festo MPS

47

3.2.2

.
,
.
,
: entity objects, interface
boundary objects control objects.
information space.
(information)
, ,
.
(behavior)
. .
(presentation)
.
information space.

, . [12]
entity objects ,
.
.
interface objects
. , control objects
entity interface object.
.
3.2.

3.2


. ,
,
interface objects.

,
(process) .

48


OOSE [12], ,
,

.
.
Front position reached actor Feeder,
Feeder
,
. Feeder ,
, interface object,
Feeder. , entity object,
Feeder.
entity object FeederSR (FeederSoftwareRepresentation).
Feeder ,
,
. , control
object,
Feeder, FeederController. ( 3.3)

3.3 Front position reached


.

Back position reached actor Feeder,


o Feeder
.

Converter,
(position A). , control object

(Distribution Unit), Feeder Converter.
,
control object DistributionUnitController. ( 3.4)

3.4 Back position reached

49


,
entity object. , entity objects: FeederSR, ConverterSR,
ElevatorSR,
ShiftOutCylinderSR,
RotatingDiscSR,
DrillingMachineSR,
CheckingMachineSR WarehouseCylinderSR. ,
entity object WorkPiece.
DetectionModule,
(, ) piece
entity object,
control object DetectionModuleController.
,

, control object. ,
control objects: FeederController, ConverterController,
ElevatorController,
DetectionModuleController,
ShiftOutCylinderController,
RotatingDiscController, DrillingMachineController, CheckingMachineController
WarehouseCylinderController.

workPieces .
. workPiece
. ,
workPiece
( ) . ,
workPiece ,
0 .

(centralized control), (control logic)
control object. ,
control objects: DistributionUnitController, TestingUnitController
ProcessingUnitController. ,
controller, FestoMPSController.
,
interface objects Feeder, Converter, Elevator, DetectionModule,
ShiftOutCylinder, RotatingDisc, DrillingMachine, CheckingMachine
WarehouseCylinderMachine.
,
. , interface
object Operator .
(
3.5):

50

3.5

,
.

51

3.3


, .
(module decomposition),
,
. (architectural
design) (detail design). [13]
,

,

,

.
,

, . ,
,
,
.

3.3.1


.

,
.

.


.

.

. ,
, InstanceName :
ClassName.

52


. 3.6
Start system. start
FestoMPSController, DistributionUnitController.
DistributionUnitController FeederController,
moveForward FeederSR,
Feeder .

3.6 Start System

3.7
frontPositionReached.

53

3.7 Front position


reached

3.8
backPositionReached.

3.8 Back position


reached

54

3.9
elevatorUp. ElevatorSR Elevator
,
ElevatorController elevatorUp. O ElevatorController
checkHeight piece
ElevatorSR moveDown,
Elevator .
TestingUnitController, o
FestoMPSController. O FestoMPSController movePiece
ProcessingUnitController, piece
.

3.9 Elevator Up

3.10
checkingCylinderDown.

55

3.10 Checking cylinder


down
stop units,
control unit ,
,
SR (SoftwareRepresentation) .

,

.

,
.
.
, 2

.

,
.
3.11
FeederSR. FeederSR backPosition.
moveForward Feeder
moveForward MovingForward.
56

frontPositionReached,
FeederController frontPositionReached
Feeder stop FrontPosition.
.

3.11 FeederSR

3.12
DrillingMachineSR.
vakuumed
.
.
,
.

57

3.12 DrillingMachineSR

3.3.2


Java TCP Sockets. [14]
SensorListener,
socket
SR .
OutSocket,
SR
socket
.
. (
3.13)

58

3.13

3.3.3
,
,
,
.
.


,
.
(active) ,
,
overhead . SensorListener,
.

59

SR ,
Controllers.
DetectionModuleController, SR
, . ,
Controllers, DistributionUnitController, TestingUnitController
ProcessingUnitController,
,
FestoMPSController .
Monitor,
monitor . SR
SR
monitor ,
SensorListener. , DistributionUnitController,
TestingUnitController ProcessingUnitController
Controllers monitor
. , monitor FestoMPSController
.


( 3.14).

60

3.14
61


.
Java Eclipse. StarUml
,
stub code,
.
,

.

4.1


SensorListener OutSocket ,
Socket. java.net Java platform
Socket ServerSocket
.

port, SensorListener. ,
port,
OutSocket.
SensorListener Server
. SensorListener,
,
. closeConnection

. , startServer
ServerSocket port,
. connect,
SensorListener .
accept
Socket, clientSocket, .

62

, inBR
Client, . ,
, socket SensorListener
readLine,
Monitor
. SensorListener.
public class SensorListener extends Thread
{
private static ServerSocket serverSocket = null;
private static Socket clientSocket = null;
private static BufferedReader inBR;
private static InputStreamReader inISR;
private static InputStream inIS;
private static String inputLine;
private static String outputLine;
private Monitor feederM,converterM;
private int port;
public SensorListener(int port){
this.port=port;
}
public void run()
{
System.out.println("\nListening on port "+port+"...\n");
do
{
try
{
try
{
closeConnection();
}
catch(Exception e) { }
StartServer();
Connect();
do
{
if((inputLine = inBR.readLine()) == null)
{
break;
}
if(inputLine.equals("feeder.backPos"))
feederM.sendCommand("backPos");
if(inputLine.equals("feeder.frontPos"))
feederM.sendCommand("frontPos");
if(inputLine.equals("converter.rightStop"))
converterM.sendCommand("rightStop");
/****
****/
if(inputLine.equals("die"))
{
System.exit(0);
}
} while(true);
closeConnection();

63

}
catch(Exception e)
{
System.out.println("Error:\n"+e.toString());
}
} while(true);
}
private void StartServer()
{
try
{
serverSocket = new ServerSocket(port);
}
catch(IOException e)
{
System.out.println("Could not listen on port:
"+port+"\n"+e.toString());
System.exit(-1);
}
}
private void Connect()
{
try
{
clientSocket = serverSocket.accept();
}
catch(IOException e)
{
System.err.println("Accept failed.");
System.exit(1);
}
try
{
inIS = clientSocket.getInputStream();
inISR = new InputStreamReader(inIS);
inBR = new BufferedReader(inISR);
}
catch(IOException e)
{
System.out.println("Connection failed.\n"+e.toString());
System.exit(1);
}
}
public static void closeConnection()
{
try{
inBR.close();
clientSocket.close();
serverSocket.close();
}
catch(IOException e){
System.out.println("CloseConnection failed.\n");
System.exit(1);
}
}

64

SensorListener
SensorListener SR
SR monitor
SR ,
busy waiting. Monitor
:
public class Monitor {
private boolean empty=true;
private String command;
public synchronized String getCommand(){
while(empty){
try{wait();}
catch(InterruptedException e){}
}
empty=true;
return command;
}
public synchronized void sendCommand(String command){
this.command=command;
empty=false;
notify();
}
}

Monitor

OutSocket Client
.
. H
connect Socket
( )
localhost port ServerSocket
.
out,
Server. out socket
sendCommand. OutSocket:

public class OutSocket{


Socket echoSocket;
PrintWriter out;
int port;
public OutSocket(int port)
{
echoSocket = null;
out = null;
this.port = port;

65

connect(port);
}
void sendCommand(String command)
{
if(out != null)
{
out.print(command);
out.flush();
System.out.println(command+" Sent to Port:
"+Integer.toString(port));
} else
{
System.out.println(command+" NOT sent to Port:
"+Integer.toString(port));
}
}
void connect(int port)
{
try
{
echoSocket = new Socket("localhost", port);
out = new PrintWriter(echoSocket.getOutputStream(),
true);
System.out.println(Integer.toString(port)+"
Connected!");
}
catch(UnknownHostException e)
{
System.out.println("Don't know about host: loopback");
}
catch(IOException e){}
}
void disConnect()
{
try
{
out.close();
echoSocket.close();
}
catch(Exception e) { }
}
}

OutSocket

4.2

FeederSR,
ConverterSR, FeederController, ConverterController DistributionUnitController.

66

FeederSR monitor feederM


Feeder.
Feeder
Feeder, outSocket,
. ,
FeederController . ,
FeederSR FeederController Feeder,
moveForward moveBackward. ,
outSocket
. , getStatus
. ConverterSR.
FeederSR :
public class FeederSR extends Thread{
private boolean backPos,frontPos,movingBackward,
movingForward=false;
private String command;
public void run(){
while(true){
command=feederM.getCommand();
if(command.equals("frontPos")){
outSocket.sendCommand("feeder.stop\n");
frontPos=true;
movingForward=false;
feederController.frontPosReached();
}
if(command.equals("backPos")){
outSocket.sendCommand("feeder.stop\n");
backPos=true;
movingBackward=false;
feederController.backPosReached();
}
}
}

public void moveBackward(){


FestoControlApplic.outSocket.sendCommand("feeder.moveB\n");
movingBackward=true;
frontPos=false;
}
public void moveForward(){
FestoControlApplic.outSocket.sendCommand("feeder.moveF\n");
movingForward=true;
backPos=false;
}
public String getStatus(){
String status=new String("feeder status: ");
if(backPos)
status=status.concat("backPos");
if(frontPos)

67

status=status.concat("frontPos");
if(movingBackward)
status=status.concat("movingBackward");
if(movingForward)
status=status.concat("movingForward");
return status;
}
}

FeederSR

FeederController FeederSR
backPosReached frontPosReached DistUnitController
movePiece. FeederController Feeder
,
,
distUnitController feederAtBackPos
monitor distUnitControllerM. distributionUnitController
movePiece,
Feeder .
ConverterController.
FeederController:

public class FeederController {


public void backPosReached(){
distUnitControllerM.sendCommand("feederAtBac
kPos");
}
public void movePiece(){
feederSR.moveForward();
}
public void frontPosReached(){
feederSR.moveBackward();
}
}

FeederController
DistUnitController monitor
distUnitControllerM FeederController
ConverterController units
feederAtBackPos posAFree. Feeder
, FeederController
movePiece, Feeder . O
DistUnitController ConverterController
convAtLeftStop pieceInPosA,
. ,
FestoController monitor festoControllerM. ,
DistUnitController

FestoController

68

movePieceInPosB startFeeder. movePieceInPosB


FestoController
,
ConverterController movePiece,
Converter . , startFeeder
FestoController, ,
FeederController movePiece.
DistUnitController :
public class DistUnitController extends Thread{
boolean feederAtBackPos=false;
boolean posAFree=false;
String command;
public void run(){
while(true){
command=distUnitControllerM.getCommand();
if(command.equals("feederAtBackPos")){
feederAtBackPos=true;
}
if(command.equals("posAFree")){
posAFree=true;
}
if(feederAtBackPos && posAFree){
feederController.movePiece();
feederAtBackPos=false;
posAFree=false;
}
}
}

public void movePieceInPosB(){


converterController.movePiece();
}
public void convAtLeftStop(){
festoControllerM.sendCommand("convAtLeftStop");
}
public void pieceInPosA(){
festoControllerM.sendCommand("pieceInPosA");
}

public void startFeeder(){


feederController.movePiece();
}
}

DistUnitController

69

4.3

ElevatorSR,
SOC_UpSR, SOC_DownSR, DetectionModuleController, ElevatorController,
SOC_UpController, SOC_DownController, TestingUnitController.
ElevatorSR
Elevator monitor elevatorM elevatorUp elevatorDown.
Elevator
outSocket .
ElevatorController.
, ElevatorSR moveUp move Down
ElevatorController,
outSocket .
SOC_UpSR SOC_DownSR.
ElevatorSR :
public class ElevatorSR extends Thread{
private boolean upStop,downStop,movingUp,movingDown=false;
private String command;
public void run(){
while(true){
command=elevatorM.getCommand();
if(command.equals("elevatorUp")){
outSocket.sendCommand("elevator.stop\n");
upStop=true;
movingUp=false;
elevatorController.elevatorUp();
}
if(command.equals("elevatorDown")){
outSocket.sendCommand("elevator.stop\n");
downStop=true;
movingDown=false;
elevatorController.elevatorDown();
}
}
}
public void moveUp(){
outSocket.sendCommand("elevator.moveUp\n");
movingUp=true;
downStop=false;
}
public void moveDown(){
outSocket.sendCommand("elevator.moveDown\n");
movingDown=true;
upStop=false;
}
}

ElevatorSR

70

DetectionModuleController
, piece setColor
setHeight, SensorListener.
piece position B
monitor detectionModuleM. piece
checkColor checkMaterial.

. TestingUnitController
piece monitor
testingUnitControllerM. , getHeight
testingUnitController piece.
DetectionModuleController :
public class DetectionModuleController extends Thread {
private boolean pieceInPosB;
private String command;
public String color;
public int height;
public void run(){
while(true){
command=detectionModuleM.getCommand();
if(command.equals("pieceInPosB")){
if(checkMaterial() && checkColor()){
testingUnitControllerM.sendCommand("vali
dPiece");
}
else
testingUnitControllerM.sendCommand("invalid
Piece");
}
}
}

public boolean checkMaterial(){


return true;
}
public int getHeight(){
return height;
}

public boolean checkColor(){


if(color.equals("java.awt.Color[r=0,g=0,b=0]"))
return false;
else
return true;
}
public void setColor(String color){
this.color=color;
}

71

public void setHeight(int height){


this.height=height;
}
}

DetectionModuleController

ElevatorController ElevatorSR
elevatorUp elevatorDown. Elevator
piece testingUnitController,
testingUnitController,
Elevator .
Elevator
piece testingUnitController
,
. , movePieceUp
moveElevatorDown testingUnitController Elevator
.
ElevatorController :
public class ElevatorController {
private boolean heightValid;
private int height;
public void elevatorUp(){
height=testingUnitController.getHeight();
if(heightValid=checkHeight())
testingUnitController.heightValid();
else
elevatorSR.moveDown();
}
public void elevatorDown(){
if(!heightValid){
testingUnitControllerM.sendCommand("invalidPiece");
heightValid=true;
}
else
testingUnitController.posBFree();
}
public void movePieceUp(){
elevatorSR.moveUp();
}
public boolean checkHeight(){
if(height!=20)
return false;
else
return true;
}

72

public void moveElevatorDown(){


elevatorSR.moveDown();
}
}

ElevatorController

TestingUnitController monitor
testingUnitControllerM
units . , heightValid
pos0Free,
FestoController. , movePieceInPos0
FestoController, ShiftOutCylinder
. , getHeight
ElevatorController,
DetectionModuleController. TestingUnitController
:
public class TestingUnitController extends Thread{
String command;
public void run(){
while(true){
command=testingUnitControllerM.getCommand();
if(command.equals("validPiece")){
elevatorController.movePieceUp();
}
if(command.equals("invalidPiece")){
socDownController.moveInvalidPiece();
}
if(command.equals("socUpAtBackPos")){
elevatorController.moveElevatorDown();
}
}
}
public void heightValid(){
festoControllerM.sendCommand("heightValid");
}

public void posBFree(){


festoControllerM.sendCommand("posBFree");
}
public void movePieceInPos0(){
socUpController.movePiece();
}
public int getHeight(){
return detectionModuleController.getHeight();
}
}

73

TestingUnitController

4.4


RotatingDiscSR, DrillingMachineSR, CheckingMachineSR, WarehouseCylinderSR,
RotatingDiscController, DrillingMachineController, CheckingMachineController,
WarehouseCylinderController, ProcessingUnitController.
RotatingDiscSR
monitor. piece
RotatingDiscController,

. , RotatingDiscSR
RotatingDiscController rotate,
RotatingDisc .
RotatingDiscSR :
public class RotatingDiscSR extends Thread{
private boolean rotating=false;
private boolean pieceInPos0, pieceInPos1, pieceInPos2,
pieceInPos3=false;
private String command;
public void run(){
while(true){
command=rotatingDiscM.getCommand();
if(command.equals("pieceInPos0")){
rotatingDiscController.pieceInPos0();
pieceInPos0=true;
}
//

if(command.equals("rotationDone")){
outSocket.sendCommand("rotating
Disc.stop\n");
rotating=false;
rotatingDiscController.rotationDone();
}
}
}
public void rotate(){
outSocket.sendCommand("rotatingDisc.rotate\n");
rotating=true;
pieceInPos0=false;
pieceInPos1=false;
pieceInPos2=false;
pieceInPos3=false;
}
}

74

RotatingDiscSR
RotatingDiscController piece
ProcessingUnitController. ,
rotationDone RotatingDiscSR,
ProcessingUnitController 0 . ,
rotateDisc ProcessingUnitController
RotatingDiscSR. RotatingDiscController
:
public class RotatingDiscController {
public void pieceInPos0(){
processingUnitControllerM.sendCommand("pieceInPos0");
}
// pieceInPos1,2,3
public void rotationDone(){
processingUnitController.pos0Free();
}
public void rotateDisc(){
rotatingDiscSR.rotate();
}
}

RotatingDiscController

ProcessingUnitController monitor
RotatingDisc
DrillingMachine, CheckingMachine WarehouseCylinder.
piece 1,2,3
Controller
piece. piece 0
,
RotatingDisc . ,

RotatingDisc
. , ProcessingUnitController
0 RotatingDiscController
FestoController. ProcessingUnitController
:
public class ProcessingUnitController extends Thread{
private boolean pieceInPos0, pieceInPos1, pieceInPos2,
pieceInPos3=false;
private boolean drilling,checking,removingPiece=false;
private String command;
public void run(){
while(true){
command=processingUnitControllerM.getCommand();
if(command.equals("pieceInPos3")){

75

pieceInPos3=true;
warehouseCylinderController.remove
Piece();
removingPiece=true;
}
if(command.equals("pieceInPos2")){
pieceInPos2=true;
checking=true;
checkingMachineController.moveChecking
MachineDown();
}
if(command.equals("pieceInPos1")){
pieceInPos1=true;
drilling=true;
drillingMachineController.moveLifting
CylinderDown();
}
if(command.equals("pieceInPos0")){
pieceInPos0=true;
festoController.resetPos0();
if((!pieceInPos1) && (!pieceInPos2) &&
(!pieceInPos3)){
rotatingDiscController.rotate
Disc();
}
}
if(command.equals("drillingDone")){
drilling=false;
if(!checking && !removingPiece){
rotate();
}
}
if(command.equals("checkingDone")){
checking=false;
if(!drilling && !removingPiece){
rotate();
}
}
if(command.equals("pieceRemoved")){
removingPiece=false;
if(!checking && !drilling){
rotate();
}
}
}
}
public void rotate(){
rotatingDiscController.rotateDisc();
pieceInPos3=false;
pieceInPos2=false;
pieceInPos1=false;
}
public void pos0Free(){
festoControllerM.sendCommand("pos0Free");
}
}

ProcessingUnitController
76

4.5


FestoController. piece
Converter , piece
.
posBFree, converterAtLeftStop pieceInPosA.

DistributionUnitController movePieceInPosB.
piece
piece 0
. ,
heightValid pos0Free. , FestoController
resetPos0 ProcessingUnitController piece 0,
. ,
startSystem , DistributionUnitController
Feeder .
FestoController :

public class FestoController extends Thread{


private String command;
boolean posBFree=true;
boolean convAtLeftStop=true;
boolean pieceInPosA=false;
private boolean pos0Free=true;
boolean heightValid=false;
public void run(){
while(true){
command=festoControllerM.getCommand();
if(command.equals("heightValid")){
heightValid=true;
if(pos0Free){
heightValid=false;
pos0Free=false;
testingUnitController.move
PieceInPos0();
}
}
if(command.equals("posBFree")){
posBFree=true;
}
if(command.equals("convAtLeftStop")){
convAtLeftStop=true;
}
if(command.equals("pieceInPosA")){
pieceInPosA=true;
}
if(command.equals("pos0Free")){
pos0Free=true;
if(heightValid){

77

pos0Free=false;
heightValid=false;
testingUnitController.move
PieceInPos0();

}
}
if(posBFree && convAtLeftStop && pieceInPosA){
distUnitController.movePieceInPosB();
posBFree=false;
convAtLeftStop=false;
pieceInPosA=false;
}
}
}
public void startSystem(){
distUnitController.startFeeder();
}
public void resetPos0(){
pos0Free=false;
}
}

FestoController

78

79

,

Festo
MPS. ( 5.1)

5.1 Festo MPS

80

sockets.
,
8258 8259.
Simulator Festo MPS
[15].

( 5.2) :

5.2 Festo MPS Simulator


ActuatorListener OutSocket. ActuatorListener
Server .
socket
unit monitor
UnitMonitor. ActuatorListener
SensorListener . OutSocket,
Client, socket
SensorListener .
OutSocket
.

Feeder, Converter, Elevator, SOC_Up,
SOC_Down,
Belt, RotatingDisc, DrillingMachine, CheckingMachine
WarehouseCylinder.
monitor ,
81


, OutSocket.
Interface
Unit, .


( 5.3):

82

5.3

83

SimGui,
:
public class SimGui extends Frame
{
Image offscreenImage;
Graphics offscreenGraph;
Dimension frameDim;
Insets frameInsets;
public SimGui(String title)
{
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt){
dispose();
System.exit(0);
}
});
setSize(600, 400);
setResizable(false);
DimensionscreenDim=Toolkit.getDefaultToolkit().getScreenSize();
frameDim = getSize();
setLocation((screenDim.width - frameDim.width) / 2,
(screenDim.height - frameDim.height) / 2);
setVisible(true);
}

public void update(Graphics g){


offscreenGraph.setColor(getBackground());
offscreenGraph.fillRect(0, 0, frameDim.width,
frameDim.height);
offscreenGraph.setColor(Color.black);
.....
}
catch(Exception e){
System.out.println("*");
}
super.paint(g);
g.drawImage(offscreenImage, 0, 0, this);
}

public void paint(Graphics g)


{
update(g);
}
public void addNotify()
{
super.addNotify();
offscreenImage = createImage(frameDim.width,
frameDim.height);

84

offscreenGraph = offscreenImage.getGraphics();
frameInsets = getInsets();
}
}

SimGui

WorkPiece,
Component add SimGui.
PieceStack.
WorkPiece
. nextPiece ,
. PieceStack WorkPiece
.
public class PieceStack {
private WorkPiece pieces[];
private int i=-1;
public PieceStack(){
pieces=new WorkPiece[10];
pieces[0]=new WorkPiece(Color.RED,0,0,20,20);
pieces[1]=new WorkPiece(Color.BLUE,0,0,20,20);
pieces[2]=new WorkPiece(Color.YELLOW,0,0,20,20);
pieces[3]=new WorkPiece(Color.RED,0,0,20,20);
pieces[4]=new WorkPiece(Color.ORANGE,0,0,20,20);
pieces[5]=new WorkPiece(Color.RED,0,0,20,19);
pieces[6]=new WorkPiece(Color.BLUE,0,0,20,20);
pieces[7]=new WorkPiece(Color.YELLOW,0,0,20,20);
pieces[8]=new WorkPiece(Color.BLACK,0,0,20,20);
pieces[9]=new WorkPiece(Color.ORANGE,0,0,20,20);
}
public WorkPiece nextPiece(){
i++;
i=i % 10;
pieces[i].setVisible(true);
return pieces[i];
}
}

PieceStack
public class WorkPiece extends Component{
public int xCoord;
public int yCoord;
public int width;
public int height;
public Color color;
public String name;
public WorkPiece(Color color, int xCoord, int yCoord,
int width, int height){
super();
this.name=name;
this.xCoord = xCoord;

85

this.yCoord = yCoord;
this.width = width;
this.height = height;
this.color = color;
this.setLocation(xCoord, yCoord);
this.setSize(width, height);
this.setForeground(color);
this.setVisible(true);
addNotify();
simGui.add(this);
}
public void paint(Graphics g){
simGui.offscreenGraph.setColor(color);
simGui.offscreenGraph.fillRect(xCoord, yCoord, width,
height);
}
}

WorkPiece

UnitGui, .
public class UnitGui extends Component {
int xCoord;
int yCoord;
int width;
int height;
Color color;
String shape;
public UnitGui(Color color, int xCoord, int yCoord, int width, int height,
String shape){
super();
this.xCoord = xCoord;
this.yCoord = yCoord;
this.width = width;
this.height = height;
this.color = color;
this.shape=shape;
this.setLocation(xCoord, yCoord);
this.setSize(width, height);
this.setForeground(color);
this.setVisible(true);
addNotify();
simGui.add(this);
}
public void paint(Graphics g){
simGui.offscreenGraph.setColor(color);
if(shape.equals("Rect"))
simGui.offscreenGraph.fillRect(xCoord,

yCoord,width,height);
if(shape.equals("Oval"))
simGui.offscreenGraph.fillOval(xCoord, yCoord,
width, height);
}
}

UnitGui
86

Feeder .
speed
unitGui, .
, Feeder piece
setPiece. Feeder
monitor feederM .
moveF Feeder piece
set monitor screenPainterM ScreenPainter
update . runFrontPosSensor
.
outSocket .
, setPiece Converter piece,
piece outSocket
piece . stop,
monitor ActuatorListener,
command .
public class Feeder extends Thread implements Unit{
String name;
int speed;
UnitGui unitGui;
WorkPiece piece;
private String command;

public Feeder(String name, Color color, int xCoord, int yCoord,


int width, int height, int speed){
this.name =name;
this.speed = speed;
unitGui = new UnitGui(color, xCoord, yCoord, width,
height,"Rect");
setPiece(pieceStack.nextPiece());
}
public void run(){
while(true){
command=feederM.getCommand();
while(command.equals("moveF")){
if(piece!=null){
if(unitGui.xCoord!=90){
unitGui.xCoord++;
piece.xCoord++;
screenPainterM.set();
runFrontPosSensor();
try{
Thread.sleep(speed);
}
catch(InterruptedException
ie){ }
}
else
command="stop";
}
}

87

while(command.equals("moveB")){
if(unitGui.xCoord!=10){
unitGui.xCoord--;
screenPainterM.set();
runBackPosSensor();
try
{
Thread.sleep(speed);
}
catch(InterruptedException ie) { }
}
else
command="stop";
}
}
}
public void runFrontPosSensor(){
if(unitGui.xCoord==80){
outSocket.sendCommand("feeder.frontPos\n");
try{
for(int i = 1; i <= 10; i++){
piece.xCoord++;
screenPainterM.set();
Thread.sleep(speed);
}
converter.setPiece(piece);
outSocket.sendCommand("converter.
pieceInPosA\n");
piece=null;
}
catch(InterruptedException e) { }
}
}
public void runBackPosSensor(){
if(unitGui.xCoord==20 ){
outSocket.sendCommand("feeder.backPos\n");
setPiece(pieceStack.nextPiece());
}
}

public void stopUnit(){


command="stop";
}
public void setPiece(WorkPiece piece){
this.piece=piece;
piece.xCoord=60;
piece.yCoord=270;
}
}

Feeder

.

88

89


UML
Festo MPS.
UML

.
CASE tool StarUML
.

stub code
.
Eclipse,

. , StarUML
,
.

,
,

.

, . ,

UML profile,
,
real-time Java.

90

91


[1]

., Using IEC61499 in control and automation: The FESTO


MPS case study , 2006

[2]

Booch G., Rumbaugh J. and Jacobson I., The Unified Modeling Language
User Guide, Addison Wesley, Boston, MA, 1999

[3]

Eriksson ., Penker ., UML Toolkit, John Wiley.

[4]

., , 2005

[5]

Wuyts R, UML: History and Overview


http://www.ulb.ac.be/di/rwuhttp://www.ulb.ac.be/di/rwuyts/INFO025_2
004/04-UML-Overview.pdfyts/INFO025_2004/

[6]

., ., ., ., .,
UML,
2006

[7]

J. Warmer, A. Kleppe, The Object Constraint Language: Precise Modeling


with UML, Object Technology Series, Addison-Wesley, 1999.
Chen R., Sgro1 M., Lavagno L., Martin G., Sangiovanni-Vincentelli A.,
Rabaey J., UML and Platform-based Design, IEEE Computer Society 2002

[8]

[9]

B. Selic, A Generic Framework for Modeling Resources with UML, IEEE


Computer, June 2000

[10]

Mellor S. From UML to embedded system: Is it possible?


http://www.eetimes.com/esc/showArticle.jhtml?articleID=184417422

[11]

StarUML The Open Source UML/MDA platform


http://staruml.sourceforge.net/en/

[12]

Ivar Jacobson, Object-Oriented Software Engineering: A Use Case Driven


Approach, Addison Wesley 1992

[13]

., ,
2007

[14]

The Java Tutorials: All about sockets


http://java.sun.com/docs/books/tutorial/networking/sockets/

[15]

., Java
:
..

92

You might also like