Escolar Documentos
Profissional Documentos
Cultura Documentos
São Paulo
2009
Fábio Henrique de Assis
Área de concentração:
Controle e Automação
São Paulo
2009
Este exemplar foi revisado e alterado em relação à versão original, sob
responsabilidade única do autor e com a anuência de seu orientador.
Assinatura do orientador_________________________________
FICHA CATALOGRÁFICA
à minha família.
Agradecimentos
1 Introdução p. 15
1.1 Objetivos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 20
1.3 Contribuições . . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 23
2 Conceitos Básicos p. 25
2.2 UML-RT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 25
2.3.1 CSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 29
2.3.2 Object-Z . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 30
2.3.3 CSP-OZ . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 32
3 Método de Desenvolvimento p. 37
3.3 Testes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 49
3.4.1 Modelagem . . . . . . . . . . . . . . . . . . . . . . . . . p. 50
3.4.2 Implementação . . . . . . . . . . . . . . . . . . . . . . . p. 54
3.4.3 Testes . . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 61
4.2 Requisitos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 64
4.3.1 O Robô . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 66
5.1 Introdução . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 74
5.3.1 BaseReader . . . . . . . . . . . . . . . . . . . . . . . . . p. 81
5.3.2 Remote . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 82
5.3.3 Autonomous . . . . . . . . . . . . . . . . . . . . . . . . . p. 82
5.3.4 S1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 83
5.4.1 Compass . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 85
5.4.2 Altimeter . . . . . . . . . . . . . . . . . . . . . . . . . . p. 86
5.4.3 Sonar . . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 87
5.4.4 BaseWriter . . . . . . . . . . . . . . . . . . . . . . . . . p. 88
5.4.5 ThrusterWriter . . . . . . . . . . . . . . . . . . . . . . . p. 89
5.4.6 Move . . . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 90
5.4.7 S2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 92
5.4.8 Stop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 92
5.4.9 Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 93
5.4.10 AvoidCollision . . . . . . . . . . . . . . . . . . . . . . . . p. 94
5.4.11 Actuator . . . . . . . . . . . . . . . . . . . . . . . . . . . p. 95
6 Resultados p. 98
7 Conclusões p. 106
Referências p. 108
1 Introdução
Hard Real Time Systems: são sistemas onde é imprescindível que as respos-
tas ocorram dentro dos limites de tempo pré-estabelecidos. Nesse caso, os
erros precisam ser todos rastreados de forma a permitir uma ação imediata
de tratamento dos mesmos. Um exemplo de sistema de tempo real crítico
são os sistemas de controle de vôo;
Soft Real Time Systems: sistemas onde os limites de tempo são importan-
tes, mas que ainda continuam funcionando caso algum destes limites seja
rompido ocasionalmente. Um exemplo disso são sistemas de aquisição de
dados;
Real Real Time Systems: são sistemas que são hard real time e que possuem
tempos de resposta muito curtos. Um exemplo seria um sistema de controle
de mísseis;
Firm Real Time Systems: o sistema de tempo real firme, ou firm real time
é aquele no qual tarefas atrasadas não são aproveitáveis, mas ainda funci-
onam corretamente caso alguns prazos ou processos sejam ocasionalmente
perdidos. Sistemas assim costumam ser utilizados em aplicações multimídia
ou de realidade virtual que requerem características avançadas de sistemas
operacionais.
balho será considerada um sistema soft real time, uma vez que não serão feitas
provas nem análises quanto a restrições temporais. Entretanto, tais aspectos farão
parte do projeto.
• Disputa por recursos: diz-se que existe uma disputa por recursos em um
sistema quando existe um recurso compartilhado entre múltiplos processos
e o vencedor determina o comportamento do sistema. Um problema resul-
tante disso, onde a principal causa é a sincronização incorreta de acessos a
1 Introdução 18
1.1 Objetivos
Este trabalho tem por objetivo principal estabelecer um método para de-
senvolvimento de arquiteturas de controle para veículos submarinos utilizando
especificações formais. O método deve apoiar o desenvolvimento da fase de espe-
cificação do projeto até a geração de código para sistemas embarcados.
1.3 Contribuições
Um resumo das notações das linguagens CSP e Object-Z pode ser visto no
Apêndice A.
25
2 Conceitos Básicos
2.2 UML-RT
de sistemas embarcados (AKHLAKI et al., 2006). Apesar do nome Real Time suge-
rir tempo, o foco desta extensão consiste na modelagem da estrutura de sistemas
distribuídos, e não na inserção de facilidades para a inserção do conceito de tempo
nas especificações.
Portas A interação das cápsulas com o ambiente é feita por meio de portas.
Estas geralmente estão associadas a protocolos, que determina o fluxo de
informação através das portas.
Conectores Estes são usados para conectar duas ou mais portas de cápsulas, e
assim descrever as relações de comunicação entre as cápsulas do sistema.
Além da utilização da OCL, pode ser feita uma combinação da UML com
outras linguagens formais para a eliminação de ambiguidades. Segundo Borges
e Mota (2007), existem diversos trabalhos na área de métodos formais relacio-
nados à sua integração com UML. Um exemplo destes trabalhos é o de Polido
(2007), que propõe regras de refinamento entre especificações feitas em UML-RT
para especificações em CSP-OZ. Do ponto de vista da Engenharia de Software, a
integração de métodos formais no processo de desenvolvimento propicia aos dia-
gramas UML uma semântica precisa, o que possibilita sua verificação, e também
2.3 Métodos Formais 27
estabelece uma relação entre o modelo gráfico de mais alto nível e a implemen-
tação final. Isso porque as especificações formais permitem que sejam geradas
condições de verificação das especificações do modelo antes de sua implementa-
ção. Do ponto de vista dos métodos formais, a vantagem de uma combinação
com UML é a possibilidade de se especificar graficamente algumas da caracterís-
ticas comportamentais, estruturais e de orientação a objetos de um sistema em
conjunto com as notações matemáticas. A especificação formal pode então ser
obtida parcialmente com base nos diagramas UML por meio de regras de mape-
amento, de modo a complementar a especificação do modelo desenvolvido. Isso
poderia aumentar a aceitação do uso de uma linguagem de especificação formal
(MOLLER et al., 2008) em áreas onde seu uso ainda é incomum, como por exemplo
no desenvolvimento de software embarcado para robôs submarinos.
software que está em uso no sistema embarcado, uma vez que segundo Hall e
Chapman (2002), a maior parte deles já seria identificada e resolvida no início do
projeto. Esta identificação precoce de erros também implica em menores custos
de projeto, uma vez que torna-se bem mais complicado corrigí-los à medida que o
projeto vai avançando (BOWEN; HINCHEY, 2005; HALL; CHAPMAN, 2002; AMEY,
2002). Existem diversas linguagens de especificação formal, como Z, Object Z,
VDM, B, entre outras. Neste trabalho será utilizada a linguagem CSP-OZ, que
é uma união da álgebra de processos CSP com a linguagem Object Z, e que
será apresentada na seção 2.3.3. Um aspecto considerável na utilização desta
linguagem é o fato de Z e CSP serem dois dos formalismos mais utilizados na
indústria (BORGES; MOTA, 2007).
de testes.
2.3.1 CSP
de confiança na corretude dos mesmos, mas não se pode provar essa corretude
se o sistema aumenta muito em tamanho devido à limitações na capacidade de
análise da ferramenta. Como neste trabalho não serão feitas análises na estrutura
de dados do sistema com o FDR, este problema de explosão no número de estados
não ocorrerá. Como serão feitas apenas checagens com relação à parte dinâmica
do sistema, ou seja, na comunicação entre os processos, o número de estados é
relativamente pequeno e perfeitamente tratável pela ferramenta.
2.3.2 Object-Z
Nome
definição de tipos e constantes
esquema de estados
esquema de operações
Stack [T ]
size : N [class constants]
size = 10
INIT
elements = h i [inicial conditions]
push
∆(elements) [Delta list]
item? : T [method parameters]
#elements < size
elements 0 = hitem?i a elements
pop
∆(elements)
item! : T
elements 6= h i
item! = head elements
elements 0 = tail elements
mos o atributo elements, que consiste em uma sequência (ou seja, um conjunto
ordenado) de elementos do tipo T , que no estado inicial da classe não possui
nenhum elemento, ou seja, a pilha inicia-se vazia.
Para manipulação da mesma, podem ser utilizados os métodos push e pop, que
retiram e adicionam elementos no início da pilha, respectivamente. No método
push, para que seja possível adicionar o elemento item?, o número de elementos
existentes na pilha deve ser menor do que o seu tamanho. Caso essa condição
seja satisfeita, item? é adicionado no início da pilha. Assim como em CSP, os
decoradores “?” e “!” indicam variável recebida do ambiente e variável retornada
ao ambiente, respectivamente. Já o método pop retorna primeiro elemento da
pilha (item!) caso esta não esteja vazia, removendo em seguida este elemento da
pilha.
O exemplo acima serviu apenas para ilustrar superficialmente como seria uma
especificação em Object-Z. Maiores detalhes sobre como construir especificações
completas nessa linguagem podem ser encontradas em Duke e Rose (2000).
2.3.3 CSP-OZ
Neste trabalho será desenvolvida uma arquitetura híbrida, porém sendo im-
plementada apenas sua parte reativa. A camada deliberativa, cujo processo prin-
cipal é o Autonomous, será implementada em trabalhos futuros. A camada reativa
será projetada seguindo-se as idéias da arquitetura Subsumption, de modo que o
veículo evite colisões ao se movimentar. Entretanto, essa característica não será
efetivamente testada, pois não existem sensores embarcados no robô utilizado
capazes de detectar obstáculos no ambiente.
2.5 Conclusões do Capítulo 36
3 Método de Desenvolvimento
MODELAGEM DO SISTEMA
IMPLEMENTAÇÃO DO MODELO
TESTES
Nas seções a seguir serão apresentadas cada uma das fases e etapas do mé-
todo proposto. Um exemplo simples de sua aplicação por meio de um modelo
Produtor / Consumidor, incluindo especificação e implementação, será mostrado
na seção 3.4. Já a sua aplicação em um caso real será mostrada por meio do de-
senvolvimento de uma arquitetura de controle para um robô submarino do tipo
ROV, que fará parte do sistema descrito com maiores detalhes no capítulo 4. A
especificação completa em CSP-OZ da arquitetura, bem como o código fonte de
sua implementação podem ser vistos no capítulo 5.
origem destino:tipo
Além disso, cada canal de comunicação utilizado pelo processo deve ser es-
pecificado na classe como um método cujo nome possui o prefixo “com ” mais
o nome do canal de acordo com o nome indicado no diagrama em gCSP. Este
representa o efeito do uso do canal na classe, que geralmente consiste em uma
passagem de informação. Assim, um canal de nome theChannel resultaria em um
método de nome com theChannel nos dois processos ligados pelo canal.
3.1 Modelagem do Sistema 42
3. Os nomes dos canais no diagrama gCSP são usados como os próprios canais
em CSPM . Estes canais são vistos para os processos como eventos, ou seja,
não aparece na especificação em CSPM nenhum dado passando pelos canais,
embora isso seja o que acontece na prática.
• Uso de uma ferramenta tal como o ProBe1 para explorar possíveis compor-
tamentos da especificação;
• Para cada tipo de canal foi criado um package diferente. O tipo de canal
é definido pelo tipo de dado transferido por ele, ou seja, se o dado transfe-
rido for um inteiro, o canal será do tipo IntegerChannel. Se for transmitir
mensagens, será do tipo MessageChannel, e assim por diante.
• Cada package possui dois tipos de objetos protegidos: Data e Sync, con-
forme mencionados acima. O dado interno armazenado pelo objeto prote-
gido Data possui o mesmo tipo de dado do canal.
• Cada canal presente no diagrama em gCSP deve ser criado (ou instanciado)
dentro do package que representa o seu tipo de canal. Assim, todos os canais
de mesmo tipo são criados dentro do mesmo package. Isso ocorre devido
à restrições impostas pelo RavenSPARK e também facilita o processo de
verificação da implementação.
• O envio e recepção de dados pelos canais se dará por meio da chamada dos
métodos put, get, stay e proceed, da seguinte forma:
– Na Task que envia o dado someData, o código para uso do canal seria,
por exemplo:
Com base nas especificações em CSP-OZ, além de gerado todo o código que
implementa o sistema, são geradas as anotações SPARK para todos os compo-
nentes que serão utilizadas na próxima etapa da metodologia, que é a verificação
do código implementado.
Neste trabalho não serão geradas pré e pós condições para as variáveis e mé-
todos da especificação. Sendo assim, estas também não serão feitas nas anotações
SPARK, e portanto não serão elaborados teoremas ou provas formais. Será in-
tensivamente explorado o conceito de tipagem forte, onde todos os tipos de dados
utilizados na implementação serão pré-definidos e especificados com seus interva-
los de validade. Estes é que serão utilizados pelo examinador em suas análises,
de forma automática.
3.3 Testes
3.4.1 Modelagem
3.4.1.1 Estrutura
3.4.1.2 Componentes
Producer
chan producer consumer : [producerData : DATA]
method produceData
main = produceData → producer consumer → main
myData : DATA
0 ≤ myData ≤ 10 [this is a redundant specification]
INIT
myData = 0
produceData
∆(myData)
myData = 10 ∧ myData 0 = 0
∨
myData ≤ 10 ∧ myData 0 = myData + 1
Este possui o atributo myData do tipo DATA, ou seja, um dado inteiro que
possui um intervalo de valores válidos de zero a dez. Como o intervalo de valores
válidos já foi especificado na declaração do tipo DATA, este não precisa ser repe-
3.4 Exemplo de Aplicação: modelo Produtor/Consumidor 52
Com relação ao canal producer consumer, o efeito de sua utilização pelo pro-
cesso está representado pelo método cujo nome é o mesmo do usado no canal
acrescido do prefixo com , ou seja, com producer consumer . Como o efeito dos
canais no método de desenvolvimento proposto é a troca de informações entre
processos, o método com producer consumer apenas efetua essa troca de infor-
mações, armazenando na variável myData a variável producerData, que é o dado
transmitido pelo processo Producer.
Consumer
chan producer consumer : [producerData : DATA]
method consumeData
main = producer consumer → consumeData → main
INIT
myData : DATA myData = 0
consumeData
∆()
[print the received data on the screen]
3.4.1.3 Checagem
-- Especificacao do Sistema
SYSTEM = Producer [| {| producer_consumer |} |] Consumer
\ {| produceData, consumeData |}
Depois de gerado o script acima, este foi analisado no FDR para verificar
a presença de deadlocks, livelocks e determinismo, conforme mostrado na figura
3.4. Pode-se observar que todos os testes realizados foram bem sucedidos.
3.4.2 Implementação
Depois de verificado o modelo, deve ser feita sua transformação para código
em RavenSPARK. Esta é uma passagem manual, seguindo as regras apresentadas
no capitulo 3.
3.4.2.1 Codificação
----------------------------
-- Default Initial Values --
----------------------------
defaultData: constant DATA := 0;
end DataTypes;
Vale ressaltar que os limites do tipo DATA acima foram obtidos à partir de
sua especificação em CSP-OZ.
package Producer
--# own task producerTask : Producer_task;
3.4 Exemplo de Aplicação: modelo Produtor/Consumidor 55
is
-------------------------------
-- Task that do the real job --
-------------------------------
task type Producer_task
--# global in out DataChannel.producer_consumer_d;
--# out DataChannel.producer_consumer_s;
--# derives DataChannel.producer_consumer_d,
--# DataChannel.producer_consumer_s from &
--# null from DataChannel.
producer_consumer_d;
--# declare Suspends => DataChannel.producer_consumer_s;
is
pragma Priority(10);
end Producer_task;
----------------------------
-- Methods of the package --
----------------------------
procedure produceData(myData: in out DataTypes.DATA);
--# derives myData from myData;
------------------------
-- Task instantiation --
------------------------
producerTask: Producer_task;
end Producer;
end Producer;
package Consumer
--# own task consumerTask : Consumer_task;
is
-------------------------------
-- Task that do the real job --
-------------------------------
task type Consumer_task
--# global in out DataChannel.producer_consumer_d;
--# out DataChannel.producer_consumer_s;
--# derives DataChannel.producer_consumer_d,
--# DataChannel.producer_consumer_s from &
--# null from DataChannel.
producer_consumer_d;
--# declare Suspends => DataChannel.producer_consumer_d;
is
pragma Priority(10);
end Consumer_task;
----------------------------
-- Methods of the package --
----------------------------
procedure consumeData(myData: in DataTypes.DATA);
--# derives null from myData;
------------------------
-- Task instantiation --
------------------------
consumerTask: Consumer_task;
end Consumer;
end Consumer;
3.4 Exemplo de Aplicação: modelo Produtor/Consumidor 57
package DataChannel
--# own protected producer_consumer_d : Data (priority => 10,
suspendable);
--# protected producer_consumer_s : Sync (priority => 10,
suspendable);
is
private
chData : DataTypes.DATA := DataTypes.defaultData;
readyToRead : Boolean := False; -- Initially, there is no data
to read
end Data;
entry stay;
--# global in out Sync;
--# derives Sync from *;
procedure proceed;
--# global in out Sync;
--# derives Sync from *;
private
3.4 Exemplo de Aplicação: modelo Produtor/Consumidor 58
----------------------------
-- Channel Instantiations --
----------------------------
producer_consumer_d: Data;
producer_consumer_s: Sync;
end DataChannel;
procedure proceed
--# global out hasRead;
--# derives hasRead from ;
is
begin
-- Declare the completion of a reading operation
hasRead := True;
end proceed;
end Sync;
end DataChannel;
3.4 Exemplo de Aplicação: modelo Produtor/Consumidor 59
with Producer,
Consumer;
--# inherit Producer,
--# Consumer,
--# DataChannel;
--# main_program;
--# global in out DataChannel.producer_consumer_d;
--# in out DataChannel.producer_consumer_s;
--# derives DataChannel.producer_consumer_d,
--# DataChannel.producer_consumer_s from DataChannel.
producer_consumer_d,
--# DataChannel.
producer_consumer_s;
procedure Main
--# derives ;
is
Pragma Priority(10); -- a priority is mandatory and must appear
here
begin
null; -- all the real work is done somewhere else
end Main;
3.4.2.2 Anotações
3.4.2.3 Checagem
Com base nas anotações adicionadas, o examinador pode executar uma série
de análises na implementação. Neste modelo de Produtor / Consumidor foram
analisados os fluxos de dados e de informações, produzindo o relatório abaixo,
3.4 Exemplo de Aplicação: modelo Produtor/Consumidor 60
DATE : 08−APR−2009 1 8 : 3 0 : 0 1 . 8 2
Options :
d e f a u l t switch f i l e used
i n d e x _ f i l e=r o v _ i n d e x . i d x
w a r n i n g _ f i l e=rov_warning . wrn
notarget_compiler_data
c o n f i g _ f i l e=r o v _ c o n f i g . c f g
s o u r c e _ e x t e n s i o n=ada
l i s t i n g _ e x t e n s i o n= l s t
nodictionary
r e p o r t _ f i l e=RELATORIO . r e p
html
nostatistics
fdl_identifiers
f l o w _ a n a l y s i s=i n f o r m a t i o n
ada95
a n n o t a t i o n _ c h a r a c t e r=#
p r o f i l e =r a v e n s c a r
r u l e s=none
e r r o r _ e x p l a n a t i o n s= o f f
j u s t i f i c a t i o n _ o p t i o n= f u l l
Selected f i l e s :
Main . adb
I n d e x F i l e n a m e ( s ) u s e d were :
C: \ Producer_Consumer \ r o v _ i n d e x . i d x
No Meta F i l e s used
Summary w a r n i n g r e p o r t i n g s e l e c t e d f o r :
Hidden p a r t s
P r i v a t e t y p e s l a c k i n g method o f i n i t i a l i z a t i o n
Notes
Pragmas : P r i o r i t y , I n l i n e , P r o f i l e
Target c o n f i g u r a t i o n f i l e :
Line
1 −− 32− b i t System ( Page 196 o f t h e Spark Book )
2
3 package Standard i s
4
5 t y p e S h o r t _ S h o r t _ I n t e g e r i s r a n g e −2∗∗7 . . 2∗∗7 −1;
6 t y p e S h o r t _ I n t e g e r i s r a n g e −2∗∗15 . . 2∗∗15 −1;
7 t y p e I n t e g e r i s r a n g e −2∗∗31 . . 2∗∗31 −1;
8 t y p e L o n g _ I n t e g e r i s r a n g e −2∗∗31 . . 2∗∗31 −1;
9 t y p e Long_Long_Integer i s r a n g e −2∗∗63 . . 2∗∗63 −1;
10 t y p e F l o a t i s d i g i t s 6 r a n g e −3.40282E+38 . . 3 . 4 0 2 8 2E+38;
11
12 end S t a n d a r d ;
13
14 p a c k a g e System i s
15
16 −− System−Dependent Named Numbers
17
18 Min_Int : c o n s t a n t := −2∗∗63;
19 Max_Int : c o n s t a n t := 2∗∗63 −1;
20
21 Max_Binary_Modulus : c o n s t a n t := 2 ∗ ∗ 6 4 ;
22 Max_Mantissa : c o n s t a n t := 6 3 ;
23
24 −− S t o r a g e −r e l a t e d D e c l a r a t i o n s
25
26 type Address i s p r i v a t e ;
27
28 S t o r a g e _ U n i t : c o n s t a n t := 8 ;
29 Word_Size : c o n s t a n t := 3 2 ;
30
31 −− P r i o r i t y −r e l a t e d D e c l a r a t i o n s (RM D. 1 )
32
33 subtype Any_Priority is Integer range 0 . . 31;
34 subtype P r i o r i t y i s Any_Priority range 0 . . 30;
35 s u b t y p e I n t e r r u p t _ P r i o r i t y i s A n y _ P r i o r i t y r a n g e 31 . . 3 1 ;
36
37 end System ;
2 summarized w a r n i n g ( s ) , c o m p r i s i n g :
2 note ( s )
S o u r c e F i l e n a m e ( s ) u s e d were :
C: \ Producer_Consumer \ Main . adb
C: \ Producer_Consumer \ DataChannel . a d s
C: \ Producer_Consumer \ Consumer . a d s
C: \ Producer_Consumer \ P r o d u c e r . a d s
C: \ Producer_Consumer \ DataTypes . a d s
U n i t name : DataChannel
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : Consumer
3.5 Conclusões do Capítulo 61
No e r r o r s found
No summarized w a r n i n g s
U n i t name : Producer
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : DataTypes
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name :
Unit type : main program
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
1 summarized w a r n i n g ( s ) , c o m p r i s i n g :
1 pragma ( s ) ∗
( ∗ Note : t h e above w a r n i n g s may a f f e c t the validity of the analysis .)
−−End o f f i l e −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
3.4.3 Testes
4.2 Requisitos
Apesar do veículo ser do tipo holonômico1 , ele terá alguns de seus movimentos
restritos, operando com apenas quatro graus de liberdade. O objetivo disso é
tornar mais fácil sua operação por meio de um joystick comum, utilizado em
simuladores de vôo. Sendo assim, sua movimentação se restringe a:
• Movimentos no eixo Z;
• O tempo de duração da missão será indeterminado, uma vez que este opera
por meio de um cabo umbilical transmitindo energia e portanto não é ne-
cessário utilizar baterias.
1
Robôs holonômicos são capazes de se movimentar em qualquer direção, não apresentando
restrições de movimentação. Um exemplo de veículo não-holonômico é um automóvel, que não
pode executar movimentos laterais, por exemplo.
4.3 Componentes do Sistema 66
4.3.1 O Robô
Ele possui uma série de sensores embarcados, cujos nomes juntamente com as
variáveis medidas, taxas de amostragem e precisão dos mesmos são apresentados
na tabela 4.1. Posteriormente será adicionado a este conjunto uma câmera para
a realização de inspeções visuais.
3
A figura 4.3 mostra a interface gráfica desenvolvida para a estação de con-
trole. A exibição das imagens de vídeo recebidas de uma eventual câmera embar-
cada já está implementada.
3
A imagem de fundo na interface é meramente ilustrativa. Esta será substituída pelas
imagens da câmera embarcada do ROV, quando esta for instalada.
4.3 Componentes do Sistema 69
A figura 4.5 mostra esta arquitetura, juntamente com seus modos de comuni-
cação e os módulos de software que são executados em cada componente. Tanto
neste diagrama como no da figura 4.6, os atores representam elementos de hard-
ware presentes no sistema que fornecem, transmitem ou recebem informações, e
portanto englobam os sensores embarcados no robô e o controle utilizado pelo
operador, as redes CAN e Ethernet e os propulsores do robô, respectivamente.
5 Especificação da Arquitetura
do Software Embarcado
5.1 Introdução
Além destes, temos ainda um tipo de dado para representar o conjunto com-
pleto de sonares do robô e as mensagens trocadas entre este e a estação base. No
caso do sonar, o valor de cada leitura individual está normalizado, variando de
zero (ausência de obstáculos) a um (robô no limiar de proximidade de um obs-
táculo). Como o robô utilizado neste trabalho não possui nenhum sonar, apenas
para fins de demonstração será adotado nesta especificação um conjunto com-
posto por quatro sonares, localizados nas posições esquerda, frontal, direita e
inferior do veículo, nesta ordem. Portanto temos:
5.2 Definições Gerais 77
SONAR TYPE
readings : seq R [set of all embedded sonar readings]
∀ i ∈ 0 . . 3 • 0 ≤ readingsi ≤ 1 [restrict to four elements]
Por fim, as mensagens trocadas entre a estação base e o robô são representadas
pelo seguinte tipo básico:
Com base nos tipos básicos definidos acima foram criadas três estruturas de
dados, que por sua vez também são outros tipos de dados, porém mais complexos,
uma vez que representam um conjunto de um ou mais destes tipos básicos.
SensorData
INIT
direction : COMPASS TYPE direction = 0
depth : ALTIMETER TYPE depth = 0
sonar : SONAR TYPE ∀ i ∈ 0 . . 3 • sonari = 0
ControlData
INIT
vx : SPEED TYPE vx = 0
vy : SPEED TYPE vy = 0
vz : SPEED TYPE vz = 0
vTheta : SPEED TYPE vTheta = 0
Por fim, temos a estrutura de dados utilizada para armazenar o torque a ser
aplicado em cada um dos oito propulsores do veículo, representada pela classe
ActuationData.
ActuationData
INIT
thruster 1 : TORQUE TYPE thruster 1 = 0
thruster 2 : TORQUE TYPE thruster 2 = 0
thruster 3 : TORQUE TYPE thruster 3 = 0
thruster 4 : TORQUE TYPE thruster 4 = 0
thruster 5 : TORQUE TYPE thruster 5 = 0
thruster 6 : TORQUE TYPE thruster 6 = 0
thruster 7 : TORQUE TYPE thruster 7 = 0
thruster 8 : TORQUE TYPE thruster 8 = 0
Clock
clock ! : N
[get the computer clock in miliseconds]
5.2 Definições Gerais 79
Periodic
INIT
nextExecution = Clock [starts as soon as possible]
getNextExecution
∆(nextExecution)
[calculates the next execution as absolute delay]
nextExecution 0 = nextExecution + PERIOD
5.3.1 BaseReader
BaseReader
Receive messages from the Base Station.
receivedMsg : MESSAGE
[message received from the Base Station]
Assim como todos os processos neste trabalho, ele executa em um ciclo infi-
nito, com seu comportamento indicado pelo processo main. Ele tem sua execução
sincronizada com a recepção de mensagens da rede ethernet. Isso porque método
receiveMessage é bloqueante, ou seja, o processo fica inativo aguardando uma
mensagem, e só reinicia sua execução com a chegada de uma nova mensagem da
rede.
5.3.2 Remote
Remote
Process responsible for the remote operation mode.
INIT
ctrlData.INIT
decodeMessage
∆(ctrlData)
[decode the received message and store it in ’ctrlData’]
5.3.3 Autonomous
Autonomous
5.3.4 S1
S1
INIT
controlData.INIT
com s1 moveToGoal
∆()
s1Data! : ControlData
s1Data! = controlData
5.4 Camada Reativa 84
Uma classe muito importante da arquitetura, mas que não aparece no dia-
grama da figura 5.1 por não ser um processo, é a BlackBoard. Esta consiste em
uma estrutura de dados compartilhada entre os processos Compass, Altimeter,
Sonar e Sensor, que possui acesso protegido com relação à leitura e escrita de
seus dados. Isso garante que estes processos possam atualizar e ler as informa-
ções dos sensores de maneira assíncrona de forma segura. Assim, os processos
Compass, Altimeter e Sonar podem ser executados em frequências diferentes, de
acordo com seus respectivos hardwares, enquanto que o processo Sensor faz a
leitura e envio dos dados para a estação base a uma frequência controlada de 10
Hz. Nesta implementação todos eles trabalharão nesta mesma frequência.
5.4 Camada Reativa 85
BlackBoard
Shared memory region to store sensor information.
INIT
theReadings.INIT
setDirection setDepth
∆(theReadings) ∆(theReadings)
reading? : COMPASS TYPE reading? : ALTIMETER TYPE
theReadings.direction = reading theReadings.depth = reading
setSonar getSensorReadings
∆(theReadings) ∆()
reading? : SONAR TYPE reading! : SensorData
theReadings.sonar = reading reading! = theReadings
5.4.1 Compass
Compass
Perform a periodic reading of the compass.
inherit Periodic [this is a periodic process]
method getDirection
method saveDirection
INIT
direction.INIT
getDirection saveDirection
∆(direction) ∆(blckBoard )
[get the compass reading] blckBoard .putDirection(direction)
5.4.2 Altimeter
Este é o processo responsável pela leitura do altímetro. Assim como nos pro-
cessos Compass e Sonar, este possui um método get e um set do sensor embarcado
(neste caso o altímetro), responsáveis por ler o valor do hardware do sensor e por
salvá-no no BlackBoard, respectivamente.
5.4 Camada Reativa 87
Altimeter
Perform a periodic reading of the altimeter.
inherit Periodic [this is a periodic process]
method getDepth
method saveDepth
INIT
depth.INIT
getDepth saveDepth
∆(depth) ∆(blckBoard )
[get the altimeter reading] blckBoard .saveDepth(depth)
5.4.3 Sonar
Sonar
Perform a periodic reading of all the sonars.
inherit Periodic [this is a periodic process]
method getSonars
method saveSonars
INIT
∀ i ∈ [0 . . . 3] • sonari = 0
getSonars saveSonars
∆(sonar ) ∆(blckBoard )
[get all sonar readings] blckBoard .putDirection(sonar )
5.4.4 BaseWriter
BaseWriter
Send messages to the ethernet network.
toSend : MESSAGE
5.4.5 ThrusterWriter
ThrusterWriter
Send messages to the Thrusters controller.
INIT
actuationData.INIT
generateMessage
∆(controllerMsg)
controllerMsg 0 = h$i a hi i a hsetpoints.thruster 1ia
hj i a hsetpoints.thruster 2ia
hk i a hsetpoints.thruster 3ia
hl i a hsetpoints.thruster 4ia
hmi a hsetpoints.thruster 5ia
hni a hsetpoints.thruster 6ia
hoi a hsetpoints.thruster 7ia
hpi a hsetpoints.thruster 8i a h$i
5.4.6 Move
Move
com s1 move
INIT
∆(speedData)
speedData.INIT
s1Data? : ControlData
avoidData.INIT
movement.INIT speedData 0 = s1Data?
getNextMovement
∆(movement, avoidData)
if (dangerLevel = normal )
then movement 0 = speedData
avoidData 0 = −speedData
else movement 0 = avoidData
5.4.7 S2
S2
This is the supressor process between the Move and Stop
INIT
ctrlData.INIT
com s2 actuator
∆()
s2Data! : ControlData
s2Data! = ctrlData
5.4.8 Stop
Stop
Behaviour that stop the vehicle if there is no message reception.
inherit Periodic [this is a periodic process]
INIT
lastReception = Clock
stop.INIT [initializes with null speeds]
checkLastReception
∆(lastReception)
[get the time of the last message reception]
com stop s2
∆()
stopData! : ControlData
stopData! = stop
5.4.9 Sensor
Sensor
Joint all sensor informations and pass it to the Base Station.
inherit Periodic [this is a periodic process]
INIT
sensors.INIT
getSensors
∆(sensors)
sensors 0 = blckBoard .getSensorReadings
structureToMessage
∆()
[the sonar data is not sent to the Base Station]
message! : MESSAGE
[joint the sensor values with their respective id’s]
message! = h$i a hd i a sensors.direction a hhi a sensors.depth a h$i
5.4.10 AvoidCollision
AvoidCollision
INIT
avoidData.INIT
∀ i ∈ [0 . . . 3] • sonarDatai = 0
generateAvoid
∆(avoidData)
∀ i ∈ [0 . . . 3] • if (sonarsi > LIMIT ) then avoidData 0 = alert
else avoidData 0 = normal
5.4.11 Actuator
Actuator
Generate the setpoints to the thrusters.
INIT
ctrlData.INIT
setpoints.INIT
generateSetpoints
∆(setpoints)
[generate the setpoints of the thrusters (in a simplified way)]
setpoints 0 .thruster 1 = 10.0
setpoints 0 .thruster 2 = 20.0
setpoints 0 .thruster 3 = 30.0
setpoints 0 .thruster 4 = 40.0
setpoints 0 .thruster 5 = 50.0
setpoints 0 .thruster 6 = 60.0
setpoints 0 .thruster 7 = 70.0
setpoints 0 .thruster 8 = 80.0
assim uma camada reativa e uma deliberativa. Deste modo, funções menos críti-
cas e que demandam mais tempo de processamento como planejamento de traje-
tórias podem ser separadas das funções mais críticas, como leitura de sensores e
detecção de obstáculos. Assim, tarefas com frequências menores não interferem
diretamente em tarefas que devem executar em frequências maiores.
6 Resultados
Como pode ser visto na figura 6.1, o processo ROV Control Module foi tes-
tado com relação à existência de deadlocks, livelocks e determinismo, sendo bem
sucedido em todos eles segundo representado pelas marcações em verde ao lado
do nome do processo. Com relação ao desempenho, o FDR realizou as três análi-
6.1 Verificação do Modelo 99
ses programadas sem grandes problemas. Segundo o relatório obtido pelo FDR,
para o sistema analisado temos as seguintes informações:
DATE : 23−APR−2009 1 1 : 3 8 : 2 8 . 5 5
Options :
d e f a u l t switch f i l e used
i n d e x _ f i l e=r o v _ i n d e x . i d x
w a r n i n g _ f i l e=rov_warning . wrn
notarget_compiler_data
c o n f i g _ f i l e=r o v _ c o n f i g . c f g
s o u r c e _ e x t e n s i o n=ada
l i s t i n g _ e x t e n s i o n= l s t
nodictionary
r e p o r t _ f i l e=RELATORIO . r e p
html
exp_checks
rtc
vcs
nest
nostatistics
fdl_identifiers
f l o w _ a n a l y s i s=i n f o r m a t i o n
ada95
a n n o t a t i o n _ c h a r a c t e r=#
p r o f i l e =r a v e n s c a r
r u l e s=none
e r r o r _ e x p l a n a t i o n s= o f f
j u s t i f i c a t i o n _ o p t i o n= f u l l
Selected f i l e s :
Main_ROV_Embedded . adb
I n d e x F i l e n a m e ( s ) u s e d were :
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ r o v _ i n d e x . i d x
No Meta F i l e s used
Summary w a r n i n g r e p o r t i n g s e l e c t e d f o r :
Hidden p a r t s
P r i v a t e t y p e s l a c k i n g method o f i n i t i a l i z a t i o n
Notes
Pragmas : P r i o r i t y , I n l i n e , P r o f i l e
Target c o n f i g u r a t i o n f i l e :
Line
1 −− 32− b i t System ( Page 196 o f t h e Spark Book )
2
3 package Standard i s
4
5 t y p e S h o r t _ S h o r t _ I n t e g e r i s r a n g e −2∗∗7 . . 2∗∗7 −1;
6 t y p e S h o r t _ I n t e g e r i s r a n g e −2∗∗15 . . 2∗∗15 −1;
7 t y p e I n t e g e r i s r a n g e −2∗∗31 . . 2∗∗31 −1;
8 t y p e L o n g _ I n t e g e r i s r a n g e −2∗∗31 . . 2∗∗31 −1;
9 t y p e Long_Long_Integer i s r a n g e −2∗∗63 . . 2∗∗63 −1;
10 t y p e F l o a t i s d i g i t s 6 r a n g e −3.40282E+38 . . 3 . 4 0 2 8 2E+38;
11
12 end S t a n d a r d ;
13
14 p a c k a g e System i s
15
16 −− System−Dependent Named Numbers
17
18 Min_Int : c o n s t a n t := −2∗∗63;
19 Max_Int : c o n s t a n t := 2∗∗63 −1;
20
21 Max_Binary_Modulus : c o n s t a n t := 2 ∗ ∗ 6 4 ;
22 Max_Mantissa : c o n s t a n t := 6 3 ;
23
24 −− S t o r a g e −r e l a t e d D e c l a r a t i o n s
25
26 type Address i s p r i v a t e ;
27
28 S t o r a g e _ U n i t : c o n s t a n t := 8 ;
29 Word_Size : c o n s t a n t := 3 2 ;
30
31 −− P r i o r i t y −r e l a t e d D e c l a r a t i o n s (RM D. 1 )
32
33 subtype Any_Priority is Integer range 0 . . 31;
34 subtype P r i o r i t y i s Any_Priority range 0 . . 30;
35 s u b t y p e I n t e r r u p t _ P r i o r i t y i s A n y _ P r i o r i t y r a n g e 31 . . 3 1 ;
6.2 Verificação da Implementação 101
36
37 end System ;
2 summarized w a r n i n g ( s ) , comprising :
2 note ( s )
S o u r c e F i l e n a m e ( s ) u s e d were :
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\Main_ROV_Embedded . adb
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ S t a t u s C h a n n e l . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ A c t u a t i o n D a t a C h a n n e l . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ T h r u s t e r W r i t e r . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ Stop . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ A c t u a t o r . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ A v o i d C o l l i s i o n . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\Move . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ S2 . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ S1 . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ B a s e W r i t e r . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ S e n s o r . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ S o n a r . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ A l t i m e t e r . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ Compass . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ Bl ackBoard . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ C o n t r o l D a t a C h a n n e l . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ MsgChannel . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ Remote . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ BaseReader . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ UDP_Sockets . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ C o n s t a n t s . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ DataTypes . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ Shadows . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ D e c o d e r . a d s
C: \ Documents and S e t t i n g s \ f h a s s i s \ Desktop \ROV_Embedded\ Encoder . a d s
U n i t name : StatusChannel
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : ActuationDataChannel
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : ThrusterWriter
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : Stop
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : Actuator
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : AvoidCollision
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : Move
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
6.2 Verificação da Implementação 102
No e r r o r s found
No summarized w a r n i n g s
U n i t name : S2
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : S1
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : BaseWriter
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : Sensor
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : Sonar
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : Altimeter
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : Compass
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
No e r r o r s found
No summarized w a r n i n g s
U n i t name : ControlDataChannel
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : MsgChannel
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : Remote
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
No e r r o r s found
No summarized w a r n i n g s
U n i t name : UDP_Sockets
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
2 summarized w a r n i n g ( s ) , c o m p r i s i n g :
1 hidden part ( s ) ∗
1 p r i v a t e t y p e ( s ) l a c k i n g method o f i n i t i a l i z a t i o n
( ∗ Note : t h e above w a r n i n g s may a f f e c t t h e v a l i d i t y o f t h e analysis .)
U n i t name : Constants
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : DataTypes
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : GNAT
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
U n i t name : Ada . S t r e a m s
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
U n i t name : GNAT. S o c k e t s
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : Decoder
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
U n i t name : Encoder
Unit type : package s p e c i f i c a t i o n
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
No summarized w a r n i n g s
6.3 Testes no Sistema Embarcado 104
U n i t name :
Unit type : main program
U n i t h a s been a n a l y s e d , any e r r o r s are listed below .
No e r r o r s found
1 summarized w a r n i n g ( s ) , c o m p r i s i n g :
1 pragma ( s ) ∗
( ∗ Note : t h e above w a r n i n g s may a f f e c t the validity of the analysis .)
−−End o f f i l e −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Com o sistema embarcado, podem ser feitos diversos testes como análises de
memória, consumo de processamento, tempos de resposta das diversas tarefas do
sistema, entre outros. Como tais análises são bastante complexas e específicas,
pois dependem de uma estratégia pré estabelecida para a realização das mesmas
de acordo com o que se deseja observar do comportamento do sistema, estas
não serão feitas neste trabalho. Foram feitos apenas testes do tipo blackbox no
6.3 Testes no Sistema Embarcado 105
7 Conclusões
Com base nas especificações em CSP-OZ é possível checar tanto o modelo de-
senvolvido quanto sua implementação em código. A checagem do modelo é feita
pelo checador de modelos FDR através de um script na linguagem CSPM , feito
com base na parte CSP da especificação em CSP-OZ. Já a checagem da imple-
mentação é feita pelo examinador da linguagem SPARK com base em anotações
inseridas no código na forma de comentários. Grande parte destas anotações são
geradas a partir das especificações das estruturas de dados da parte Object-Z
dos processos. Neste trabalho não foram criadas anotações relacionadas a pré e
pós condições da estrutura de dados, e portanto não foram realizadas provas for-
mais com o examinador. Este tipo de abordagem deverá ser usada em trabalhos
futuros.
Referências
AMEY, P.; DOBBING, B. High Integrity Ravenscar. In: Ada-Europe. [S.l.: s.n.],
2003. p. 68–79.
BELAPURKAR, A. CSP for Java Programmers. [S.l.], Jun 2005. Disponível em:
<www.ibm.com/developerworks/java/library/j-csp1.html>.
MOTA, A.; FARIAS, A.; SAMPAIO, A. De CSPz para CSPm: Uma ferramenta
transformacional Java. In: Workshop de Métodos Formais, p. 1–10, 2001.
OMG. OMG UML 2.0 OCL specification. October 2003. Disponível em:
<http://www.omg.org/cgi-bin/apps/doc?ptc/03-10-14.pdf>.
TEAM, S. SPARK Examiner - The SPARK Ravenscar Profile. 1.5. ed. [S.l.],
December 2006.
{D | P } Expressão de conjunto
{D | P • t} Abstração de conjunto
PS Conjunto total (Power Set)
]S Tamanho do conjunto
(t1 , ..., tn ) Tuplas ordenadas
S1 × ... × Sn Produto cartesiano
first(t1 , ..., tn ) Seleção de termos
X ∪Y União de conjuntos
X ∩Y Intersecção de conjuntos
X \Y Diferenciação de conjuntos
R Conjunto dos números reais
Z Conjunto dos números inteiros
N Conjunto dos números naturais
N1 Conjunto dos números estritamente positivos
div Divisão inteira
m..n Conjunto dos inteiros entre m e n inclusive
X ↔Y Conjunto das relações entre X e Y
x Ry x está relacionado a R através de y
x ½y x mapeia y
dom R Domínio da relação
ran R Limite da relação
R1 o9 R2 Composição relacional
R∼ Inversa relacional
R(| S |) Imagem do conjunto S através da relação R
S /R Restrição de domínio
R.T Restrição de limites
f (t) Imagem de t sobre a função f
X →
7 Y Função parcial
X →Y Função total
X ½
7 Y Função um para um parcial (injetora parcial)
X ½Y Função um para um total (injetora total)
f ⊕g g sobrescreve f
hi Seqüência vazia
seqX Conjunto da seqüência finita com elementos do tipo T
seq1 X Conjunto de seqüência, não vazia,
finita com elementos do tipo T
ht1 , ..., t2 i Lista de elementos da seqüência
A.1 Notação da linguagem Object-Z 114
P ¤Q Operador de time-out
P 4a Q Interrupção
P [x /y] Substituição
P /s Operador de após (após execução)
P ↓n Restrição para a profundidade de n
LH (P ) Abstração fraca
EH (P ) Abstração forte
MSH (P ) Abstração combinada
a
P −→ Q Transição de ação simples
s
P =⇒ Q Transição de ação múltipla
t
P 7−→ Q Múltiplas transições de ações
τ ∗ (P ) Expansão de P
P ref B P refuta (refuses) B
P div P diverge
T Modelo de traço
N Modelo de falhas/divergências
F Modelo de falhas estáveis
I Modelos de traços/divergências infinitos
U Modelo de falhas/divergências/traços infinitos
D Conjunto de processos determinísticos
Td Possíveis membros determinísticos de T
⊥N Elemento final do modelo
>F Elemento inicial do modelo
vT Refinamento por traços
vFD Refinamento por falhas/divergências
vF Refinamento por falhas
vI Refinamento sobre I
vU Refinamento sobre U
v Refinamento sobre qualquer modelo
P ≤Q Ordem forte
tX Menor limite superior
uX Maior limite inferior
µf Menor ponto fixo
118
−− metodos i n t e r n o s d o s p r o c e s s o s
channel saveReceptionTime
channel getNextExecutionCps −− Compass
channel getNextExecutionAlt −− Altimeter
channel getNextExecutionSnr −− Sonar
channel getNextExecutionSns −− Sensor
channel getNextExecutionStp −− Stop
channel getNextExecutionAvd −− AvoidCollision
channel getMessage , decodeMessage
channel getDirection , saveDirection
c h a n n e l getDepth , s a v e D e p t h
channel getSonar , saveSonar
c h a n n e l sendMessageBwt −− B a s e W r i t e r
c h a n n e l sendMessageTwt −− T h r u s t e r W r i t e r
channel getSensors , structureToMessage
c h a n n e l g e n e r a t e A v o i d , getNextMovement
channel checkLastReception
channel generateSetpoints
channel generateMessage
−− Composicao p r i n c i p a l do S i s t e m a
ROV_Control_Module = BaseReader [ | { | baseReader_remote , baseReader_autonomous | } | ] ( Remote
[ | { | remote_s1 | } | ] ( S1 [ | { | autonomous_s1 , s1_move | } | ] ( Autonomous | | | ( Move [ | { |
move_s2 , avoid_move | } | ] ( S2 [ | { | stop_s2 , s 2 _ a c t u a t o r | } | ] ( A c t u a t o r [ | { |
a c t u a t o r _ t h r u s t e r | } | ] ( T h r u s t e r W r i t e r | | | ( Stop | | | ( A v o i d C o l l i s i o n | | | ( S e n s o r [ | { |
s e n s o r _ b a s e W r i t e r | } | ] ( B a s e W r i t e r | | | ( A l t i m e t e r | | | ( Compass | | | S o n a r ) ) ) ) ) ) ) ) ) ) ) ) )
−− E s p e c i f i c a c a o d o s P r o c e s s o s
Remote = baseR eader_ re mo te −> d e c o d e M e s s a g e −> remote_s1 −> Remote
Autonomous = SKIP
S1 = remote_s1 −> s1_move −> S1
[ ] autonomous_s1 −> s1_move −> S1
Compass = g e t D i r e c t i o n −> s a v e D i r e c t i o n −> g e t N e x t E x e c u t i o n C p s −> Compass
A l t i m e t e r = g e t D e p t h −> s a v e D e p t h −> g e t N e x t E x e c u t i o n A l t −> A l t i m e t e r
S o n a r = g e t S o n a r −> s a v e S o n a r −> g e t N e x t E x e c u t i o n S n r −> S o n a r
S e n s o r = g e t S e n s o r s −> s t r u c t u r e T o M e s s a g e −> s e n s o r _ b a s e W r i t e r −> g e t N e x t E x e c u t i o n S n s −>
Sensor
A v o i d C o l l i s i o n = g e n e r a t e A v o i d −> avoid_move −> g e t N e x t E x e c u t i o n A v d −> A v o i d C o l l i s i o n
Move = s1_move −> avoid_move −> getNextMovement −> move_s2 −> Move
Stop = c h e c k L a s t R e c e p t i o n −> ( ( s t o p _ s 2 −> g e t N e x t E x e c u t i o n S t p −> Stop ) [ ] (
g e t N e x t E x e c u t i o n S t p −> Stop ) )
A c t u a t o r = s 2 _ a c t u a t o r −> g e n e r a t e S e t p o i n t s −> a c t u a t o r _ t h r u s t e r −> A c t u a t o r
T h r u s t e r W r i t e r = a c t u a t o r _ t h r u s t e r −> g e n e r a t e M e s s a g e −> sendMessageTwt −> T h r u s t e r W r i t e r
BaseReader = g e t M e s s a g e −> s a v e R e c e p t i o n T i m e −> baseRe ader _r em ote −> Ba seReade r
B a s e W r i t e r = s e n s o r _ b a s e W r i t e r −> sendMessageBwt −> B a s e W r i t e r
S2 = s t o p _ s 2 −> s 2 _ a c t u a t o r −> S2
[ ] move_s2 −> s 2 _ a c t u a t o r −> S2
−− C h e c a g e n s a u t o m a t i c a s no modelo
a s s e r t ROV_Control_Module : [ d e a d l o c k f r e e [ FD ] ]
a s s e r t ROV_Control_Module : [ livelock free ]
a s s e r t ROV_Control_Module : [ d e t e r m i n i s t i c [ FD ] ]
119
package DataTypes i s
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− DATA TYPE DECLARATIONS USED IN THE IMPLEMENTATION −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
type STATUS i s ( normal , a l e r t ) ;
type S e n s o r D a t a i s
record
d i r e c t i o n : COMPASS_TYPE;
d e p t h : ALTIMETER_TYPE;
s o n a r : SONAR_TYPE;
end record ;
type C o n t r o l D a t a i s
record
vx : SPEED_TYPE;
vy : SPEED_TYPE;
vz : SPEED_TYPE;
vTheta : SPEED_TYPE;
end record ;
type A c t u a t i o n D a t a i s
record
v T h r u s t e r 1 : TORQUE_TYPE;
v T h r u s t e r 2 : TORQUE_TYPE;
v T h r u s t e r 3 : TORQUE_TYPE;
v T h r u s t e r 4 : TORQUE_TYPE;
v T h r u s t e r 5 : TORQUE_TYPE;
v T h r u s t e r 6 : TORQUE_TYPE;
v T h r u s t e r 7 : TORQUE_TYPE;
v T h r u s t e r 8 : TORQUE_TYPE;
end record ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− D e f a u l t I n i t i a l Values −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
d e f a u l t M e s s a g e : constant MESSAGE :=
" ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ " ;
d e f a u l t S t a t u s : constant STATUS := normal ;
d e f a u l t S o n a r : constant SONAR_TYPE := SONAR_TYPE’ ( 0 . 0 , 0 . 0 , 0 . 0 , 0 . 0 ) ;
d e f a u l t C o n t r o l D a t a : constant C o n t r o l D a t a := C o n t r o l D a t a ’ ( vx => 0 . 0 ,
vy => 0 . 0 ,
vz => 0 . 0 ,
vTheta => 0 . 0 ) ;
d e f a u l t S e n s o r D a t a : constant S e n s o r D a t a := S e n s o r D a t a ’ ( d i r e c t i o n => 0 . 0 ,
d e p t h => 0 . 0 ,
s o n a r => d e f a u l t S o n a r ) ;
d e f a u l t A c t u a t i o n D a t a : constant A c t u a t i o n D a t a := A c t u a t i o n D a t a ’
Anexo B -- Códigos Fonte da Arquitetura de Controle 120
( v T h r u s t e r 1 => 0 . 0 ,
v T h r u s t e r 2 => 0 . 0 ,
v T h r u s t e r 3 => 0 . 0 ,
v T h r u s t e r 4 => 0 . 0 ,
v T h r u s t e r 5 => 0 . 0 ,
v T h r u s t e r 6 => 0 . 0 ,
v T h r u s t e r 7 => 0 . 0 ,
v T h r u s t e r 8 => 0 . 0 ) ;
d e f a u l t R e c e p t i o n T i m e : constant Ada . Real_Time . Time := Ada . Real_Time . C l o c k ;
end DataTypes ;
−−−−−−−−−−−−−−−−−−−−−−−−
−− Timing i n f o r m a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
−− S t a r t Time o f t h e program
START_TIME: constant Ada . Real_Time . Time := Ada . Real_Time . C l o c k ;
−−−−−−−−−−−−−−−−
−− P r i o r i t i e s −−
−−−−−−−−−−−−−−−−
TASK_PRIORITY : constant System . P r i o r i t y := 1 0 ;
CHANNEL_PRIORITY : constant System . P r i o r i t y := 1 0 ;
−−−−−−−−−−−−−−−−−−−−−−−−
−− S o c k e t I n fo r m a t io n −−
−−−−−−−−−−−−−−−−−−−−−−−−
BASEREADER_PORT: constant I n t e g e r := 1 4 0 0 1 ;
end C o n s t a n t s ;
with BaseReader ,
Remote ,
BlackBoard ,
Compass ,
Altimeter ,
Sonar ,
Sensor ,
BaseWriter ,
S1 ,
S2 ,
Move ,
AvoidCollision ,
Actuator ,
Stop ,
ThrusterWriter ;
−−# i n h e r i t BaseReader ,
−−# Remote ,
−−# MsgChannel ,
−−# ControlDataChannel ,
−−# BlackBoard ,
−−# Compass ,
−−# Altimeter ,
−−# Sonar ,
−−# Sensor ,
−−# BaseWriter ,
−−# S1 ,
−−# S2 ,
−−# Move ,
−−# AvoidCollision ,
−−# Actuator ,
−−# Stop ,
−−# ThrusterWriter ,
−−# ActuationDataChannel ,
−−# StatusChannel ,
Anexo B -- Códigos Fonte da Arquitetura de Controle 121
pragma P r i o r i t y ( C o n s t a n t s . CHANNEL_PRIORITY) ;
private
chData : DataTypes . A c t u a t i o n D a t a := DataTypes . d e f a u l t A c t u a t i o n D a t a ;
Anexo B -- Códigos Fonte da Arquitetura de Controle 122
pragma P r i o r i t y ( C o n s t a n t s . CHANNEL_PRIORITY) ;
entry s t a y ;
−−# g l o b a l i n out Sync ;
−−# d e r i v e s Sync from ∗ ;
procedure p r o c e e d ;
−−# g l o b a l i n out Sync ;
−−# d e r i v e s Sync from ∗ ;
private
hasRead : B o o l e a n := F a l s e ;
end Sync ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Channel I n s t a n t i a t i o n s −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
a c t u a t o r _ t h r u s t e r _ d : Data ;
a c t u a t o r _ t h r u s t e r _ s : Sync ;
end A c t u a t i o n D a t a C h a n n e l ;
procedure p r o c e e d
−−# g l o b a l out hasRead ;
−−# d e r i v e s hasRead from ;
is
begin
−− Declare t h e c o m p l e t i o n o f a r e a d i n g o p e r a t i o n
hasRead := True ;
end p r o c e e d ;
end Sync ;
end A c t u a t i o n D a t a C h a n n e l ;
package A c t u a t o r
−−# own t a s k actu ato rTa s k : Actuator_task ;
is
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Task t h a t do t h e r e a l j o b −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
task type A c t u a t o r _ t a s k
−−# g l o b a l i n out ControlDataChannel . s2_actuator_d ;
−−# out ActuationDataChannel . ac tua tor _thr us te r _ d ;
−−# out ControlDataChannel . s2_actuator_s ;
−−# out ActuationDataChannel . a c t u a t o r _ t h r u s t e r _ s ;
−−# d e r i v e s ActuationDataChannel . actuator_thruster_d ,
−−# ControlDataChannel . s2_actuator_s ,
−−# ControlDataChannel . s2_actuator_d ,
−−# ActuationDataChannel . a c t u a t o r _ t h r u s t e r _ s from &
−−# null from ControlDataChannel . s2_actuator_d
;
−−# d e c l a r e Suspends => ( ControlDataChannel . s2_actuator_d , ActuationDataChannel .
actuator_thruster_s ) ;
Anexo B -- Códigos Fonte da Arquitetura de Controle 123
is
pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ;
end A c t u a t o r _ t a s k ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Methods o f t h e package −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
procedure g e n e r a t e S e t p o i n t s ( c t r l D a t a : i n DataTypes . C o n t r o l D a t a ;
s e t p o i n t s : out DataTypes . A c t u a t i o n D a t a ) ;
−−# d e r i v e s s e t p o i n t s from c t r l D a t a ;
−−−−−−−−−−−−−−−−−−−−−−−−
−− Task i n s t a n t i a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
actuatorTask : Actuator_task ;
end A c t u a t o r ;
package body A c t u a t o r is
task body A c t u a t o r _ t a s k is
−− c o n t r o l data t o be transformed
c t r l D a t a : DataTypes . C o n t r o l D a t a := DataTypes . d e f a u l t C o n t r o l D a t a ;
−− s e t p o i n t s t o t h e t h r u s t e r s
s e t p o i n t s : DataTypes . A c t u a t i o n D a t a := DataTypes . d e f a u l t A c t u a t i o n D a t a ;
begin
loop
−− g e n e r a t e t h e s e t p o i n t s t o t h e t h r u s t e r s
generateSetpoints ( ctrlData , s e t p o i n t s ) ;
end loop ;
exception
when E r r o r : others =>
Ada . Text_IO . Put_Line ( " E r r o r i n A c t u a t o r " ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Exception_Name ( E r r o r ) ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Excep tion _Message ( E r r o r ) ) ;
end A c t u a t o r _ t a s k ;
procedure g e n e r a t e S e t p o i n t s ( c t r l D a t a : i n DataTypes . C o n t r o l D a t a ;
s e t p o i n t s : out DataTypes . A c t u a t i o n D a t a ) is
pragma I n l i n e ( g e n e r a t e S e t p o i n t s ) ;
begin
s e t p o i n t s . v T h r u s t e r 1 := 1 0 . 0 ;
s e t p o i n t s . v T h r u s t e r 2 := 2 0 . 0 ;
s e t p o i n t s . v T h r u s t e r 3 := 3 0 . 0 ;
s e t p o i n t s . v T h r u s t e r 4 := 4 0 . 0 ;
s e t p o i n t s . v T h r u s t e r 5 := 5 0 . 0 ;
s e t p o i n t s . v T h r u s t e r 6 := 6 0 . 0 ;
s e t p o i n t s . v T h r u s t e r 7 := 7 0 . 0 ;
s e t p o i n t s . v T h r u s t e r 8 := 8 0 . 0 ;
end g e n e r a t e S e t p o i n t s ;
end A c t u a t o r ;
package A l t i m e t e r
−−# own t a s k a l t i m e t e r T a s k : A l t i m e t e r _ t a s k ;
is
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Task t h a t do t h e r e a l j o b −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
task type A l t i m e t e r _ t a s k
−−# g l o b a l out BlackBoard . blckBoard ;
−−# d e r i v e s BlackBoard . blckBoard from ;
is
pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ;
end A l t i m e t e r _ t a s k ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Methods o f t h e package −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
procedure g e t D e p t h ( d e p t h : out DataTypes .ALTIMETER_TYPE) ;
−−# d e r i v e s d e p t h from ;
−−−−−−−−−−−−−−−−−−−−−−−−
−− Task i n s t a n t i a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
altimeterTask : Altimeter_task ;
Anexo B -- Códigos Fonte da Arquitetura de Controle 124
end A l t i m e t e r ;
package body A l t i m e t e r is
task body A l t i m e t e r _ t a s k is
−− s t o r e s t h e a l t i m e t e r r e a d i n g s
d e p t h : DataTypes .ALTIMETER_TYPE;
−− time a t t i b u t e s ( o n l y f o r P e r i o d i c P r o c e s s e s )
n e x t E x e c u t i o n : Ada . Real_Time . Time := C o n s t a n t s .ALTIMETER_START;
PERIOD : constant Ada . Real_Time . Time_Span := C o n s t a n t s . ALTIMETER_PERIOD ;
−− time method ( o n l y f o r P e r i o d i c P r o c e s s e s )
procedure g e t N e x t E x e c u t i o n i s
begin
n e x t E x e c u t i o n := n e x t E x e c u t i o n + PERIOD ;
end g e t N e x t E x e c u t i o n ;
begin
loop
delay u n t i l n e x t E x e c u t i o n ;
−− g e t t h e d e p t h from t h e a l t i m e t e r
getDepth ( depth ) ;
−− s a v e t h e d e p t h i n t o t h e BlackBoard
saveDepth ( depth ) ;
getNextExecution ;
end loop ;
exception
when E r r o r : others =>
Ada . Text_IO . Put_Line ( " E r r o r i n A l t i m e t e r " ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Exception_Name ( E r r o r ) ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Excep tion _Message ( E r r o r ) ) ;
end A l t i m e t e r _ t a s k ;
end A l t i m e t e r ;
package A v o i d C o l l i s i o n
−−# own t a s k a v o i d C o l l i s i o n T a s k : AvoidCollision_task ;
is
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Task t h a t do t h e r e a l j o b −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
task type A v o i d C o l l i s i o n _ t a s k
−−# g l o b a l i n BlackBoard . blckBoard ;
−−# out StatusChannel . avoid_move_d ;
−−# out StatusChannel . avoid_move_s ;
−−# d e r i v e s StatusChannel . avoid_move_d ,
−−# StatusChannel . avoid_move_s from &
−−# null from BlackBoard . blckBoard ;
−−# d e c l a r e Suspends => StatusChannel . avoid_move_s ;
is
pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ;
end A v o i d C o l l i s i o n _ t a s k ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Methods o f t h e package −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
procedure g e t S o n a r R e a d i n g s ( s o n a r s : out DataTypes .SONAR_TYPE) ;
−−# g l o b a l i n BlackBoard . blckBoard ;
−−# d e r i v e s sonars from BlackBoard . blckBoard ;
−−−−−−−−−−−−−−−−−−−−−−−−
−− Task i n s t a n t i a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
avoidCollisionTask : AvoidCollision_task ;
end A v o i d C o l l i s i o n ;
Anexo B -- Códigos Fonte da Arquitetura de Controle 125
package body A v o i d C o l l i s i o n is
task body A v o i d C o l l i s i o n _ t a s k is
−− t o i n d i c a t e t h e s t a t u s o f t h e r o b o t
a v o i d D a t a : DataTypes . STATUS := DataTypes . d e f a u l t S t a t u s ;
−− r e a d i n g s o f t h e sonar
s o n a r s : DataTypes .SONAR_TYPE;
−− l i m i t t h a t i n d i c a t e s t h e p r e s e n c e o f o b s t a c l e s
LIMIT : constant DataTypes . Sonar_Range := 0 . 8 ;
−− time a t t i b u t e s ( o n l y f o r P e r i o d i c P r o c e s s e s )
n e x t E x e c u t i o n : Ada . Real_Time . Time := C o n s t a n t s .COMPASS_START;
PERIOD : constant Ada . Real_Time . Time_Span := C o n s t a n t s .COMPASS_PERIOD;
−− time method ( o n l y f o r P e r i o d i c P r o c e s s e s )
procedure g e t N e x t E x e c u t i o n i s
begin
n e x t E x e c u t i o n := n e x t E x e c u t i o n + PERIOD ;
end g e t N e x t E x e c u t i o n ;
begin
loop
delay u n t i l n e x t E x e c u t i o n ;
−− g e t t h e sonar r e a d i n g s i n t h e BlackBoard
getSonarReadings ( sonars ) ;
−− i n t e r p r e t t h e sonar r e a d i n g s
g e n e r a t e A v o i d ( s o n a r s , LIMIT , a v o i d D a t a ) ;
getNextExecution ;
end loop ;
exception
when E r r o r : others =>
Ada . Text_IO . Put_Line ( " E r r o r i n A v o i d C o l l i s i o n " ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Exception_Name ( E r r o r ) ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Excep tion _Message ( E r r o r ) ) ;
end A v o i d C o l l i s i o n _ t a s k ;
end A v o i d C o l l i s i o n ;
package BaseReader
−−# own t a s k baseReaderTask : BaseReader_task ;
is
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Task t h a t do t h e r e a l j o b −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
task type BaseRea de r_ ta sk
−−# g l o b a l i n Ada . Real_Time . ClockTime ;
−−# out MsgChannel . baseReader_remote_d ;
−−# out MsgChannel . baseReader_remote_s ;
−−# out BlackBoard . blckBoard ;
−−# d e r i v e s MsgChannel . baseReader_remote_d ,
−−# MsgChannel . baseReader_remote_s from &
−−# BlackBoard . blckBoard from Ada . Real_Time . ClockTime ;
−−# d e c l a r e Suspends => MsgChannel . baseReader_remote_s ;
is
pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ;
end BaseReader_ ta sk ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Methods o f t h e package −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
procedure g e t M e s s a g e ( s o c k e t : i n out UDP_Sockets . UDP_Socket ;
r e c e i v e d M s g : out DataTypes .MESSAGE) ;
−−# d e r i v e s receivedMsg from s o c k e t &
Anexo B -- Códigos Fonte da Arquitetura de Controle 126
procedure s a v e R e c e p t i o n T i m e ;
−−# g l o b a l i n Ada . Real_Time . ClockTime ;
−−# out BlackBoard . blckBoard ;
−−# d e r i v e s BlackBoard . blckBoard from Ada . Real_Time . ClockTime ;
−−−−−−−−−−−−−−−−−−−−−−−−
−− Task i n s t a n t i a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
b a s e R e a d e r T a s k : B a seR ea de r_ ta s k ;
begin
−− Create and I n i t i a l i z e t h e s o c k e t
UDP_Sockets . C r e a t e _ R e c e i v e r _ S o c k e t ( mySocket , C o n s t a n t s .BASEREADER_PORT) ;
loop
−− g e t t h e message s e n t from t h e b a s e s t a t i o n
g e t M e s s a g e ( mySocket , r e c e i v e d M s g ) ;
−− s t o r e t h e r e c e p t i o n time
saveReceptionTime ;
−− send i t t h r o u g h t h e o u t p u t channel
MsgChannel . baseReader_remote_d . put ( r e c e i v e d M s g ) ;
MsgChannel . baseReader_remote_s . s t a y ;
end loop ;
exception
when E r r o r : others =>
Ada . Text_IO . Put_Line ( " E r r o r i n Ba seReader " ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Exception_Name ( E r r o r ) ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Excep tion _Message ( E r r o r ) ) ;
end BaseReader_ ta sk ;
−− s a v e t h e time o f t h e message r e c e p t i o n
procedure s a v e R e c e p t i o n T i m e i s
pragma I n l i n e ( s a v e R e c e p t i o n T i m e ) ;
begin
Bl ack Board . b l c k B o a r d . s e t R e c e p t i o n T i m e ( Ada . Real_Time . C l o c k ) ;
end s a v e R e c e p t i o n T i m e ;
package B a s e W r i t e r
−−# own t a s k baseWriterTask : BaseWriter_task ;
is
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Task t h a t do t h e r e a l j o b −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
task type B a s e W r i t e r _ t a s k
−−# g l o b a l i n out MsgChannel . sensor_baseWriter_d ;
−−# out MsgChannel . sensor_baseWriter_s ;
−−# d e r i v e s MsgChannel . sensor_baseWriter_d ,
−−# MsgChannel . sensor_baseWriter_s from &
−−# null from MsgChannel . sensor_baseWriter_d ;
−−# d e c l a r e Suspends => MsgChannel . sensor_baseWriter_d ;
is
pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ;
end B a s e W r i t e r _ t a s k ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Methods o f t h e package −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
procedure s e n d M e s s a g e ( s o c k e t : i n out UDP_Sockets . UDP_Socket ;
msg : i n DataTypes .MESSAGE) ;
−−# d e r i v e s s o c k e t from ∗ ,
−−# msg ;
Anexo B -- Códigos Fonte da Arquitetura de Controle 127
−−−−−−−−−−−−−−−−−−−−−−−−
−− Task i n s t a n t i a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
baseWriterTask : BaseWriter_task ;
end B a s e W r i t e r ;
package body B a s e W r i t e r is
task body B a s e W r i t e r _ t a s k is
begin
−− Create and I n i t i a l i z e t h e s o c k e t
UDP_Sockets . C r e a t e _ S e n d e r _ S o c k e t ( mySocket ,
C o n s t a n t s . BASEWRITER_IP,
C o n s t a n t s .BASEWRITER_PORT) ;
loop
−− −− PARA TESTE
−− f o r I i n 1 . . msgToSend ’ Last l o o p
−− Ada . Text_IO . Put ( msgToSend ( I ) ) ;
−− end l o o p ;
−− Ada . Text_IO . New_Line ;
end loop ;
exception
when E r r o r : others =>
Ada . Text_IO . Put_Line ( " E r r o r i n B a s e W r i t e r " ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Exception_Name ( E r r o r ) ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Excep tion _Message ( E r r o r ) ) ;
end B a s e W r i t e r _ t a s k ;
end B a s e W r i t e r ;
pragma P r i o r i t y ( C o n s t a n t s . CHANNEL_PRIORITY) ;
private
s e n s o r R e a d i n g s : DataTypes . S e n s o r D a t a := DataTypes . d e f a u l t S e n s o r D a t a ;
r e c e p t i o n T i m e : Ada . Real_Time . Time := DataTypes . d e f a u l t R e c e p t i o n T i m e ;
Anexo B -- Códigos Fonte da Arquitetura de Controle 128
end The_BlackBoard ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− I n s t a n c e o f t h e BlackBoard −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
b l c k B o a r d : The_BlackBoard ;
end Bl ackBoard ;
end The_BlackBoard ;
end Bl ackBoard ;
package Compass
−−# own t a s k compassTask : Compass_task ;
is
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Task t h a t do t h e r e a l j o b −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
task type Compass_task
−−# g l o b a l out BlackBoard . blckBoard ;
−−# d e r i v e s BlackBoard . blckBoard from ;
is
pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ;
end Compass_task ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Methods o f t h e package −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
procedure g e t D i r e c t i o n ( d i r e c t i o n : out DataTypes .COMPASS_TYPE) ;
−−# d e r i v e s d i r e c t i o n from ;
−−−−−−−−−−−−−−−−−−−−−−−−
−− Task i n s t a n t i a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
compassTask : Compass_task ;
end Compass ;
−− s t o r e t h e compass r e a d i n g s
d i r e c t i o n : DataTypes .COMPASS_TYPE;
−− time a t t i b u t e s ( o n l y f o r P e r i o d i c P r o c e s s e s )
n e x t E x e c u t i o n : Ada . Real_Time . Time := C o n s t a n t s .COMPASS_START;
PERIOD : constant Ada . Real_Time . Time_Span := C o n s t a n t s .COMPASS_PERIOD;
−− time method ( o n l y f o r P e r i o d i c P r o c e s s e s )
procedure g e t N e x t E x e c u t i o n i s
begin
n e x t E x e c u t i o n := n e x t E x e c u t i o n + PERIOD ;
end g e t N e x t E x e c u t i o n ;
begin
loop
delay u n t i l n e x t E x e c u t i o n ;
−− g e t t h e d i r e c t i o n from t h e compass
getDirection ( direction ) ;
−− s a v e t h e d i r e c t i o n i n t o t h e BlackBoard
saveDirection ( direction ) ;
getNextExecution ;
end loop ;
exception
when E r r o r : others =>
Ada . Text_IO . Put_Line ( " E r r o r i n Compass " ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Exception_Name ( E r r o r ) ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Excep tion _Message ( E r r o r ) ) ;
end Compass_task ;
end Compass ;
pragma P r i o r i t y ( C o n s t a n t s . CHANNEL_PRIORITY) ;
−−# someData ;
private
chData : DataTypes . C o n t r o l D a t a := DataTypes . d e f a u l t C o n t r o l D a t a ;
readyToRead : B o o l e a n := F a l s e ; −− I n i t i a l l y , t h e r e i s no data t o read
end Data ;
pragma P r i o r i t y ( C o n s t a n t s . CHANNEL_PRIORITY) ;
entry s t a y ;
−−# g l o b a l i n out Sync ;
−−# d e r i v e s Sync from ∗ ;
procedure p r o c e e d ;
−−# g l o b a l i n out Sync ;
−−# d e r i v e s Sync from ∗ ;
private
hasRead : B o o l e a n := F a l s e ;
end Sync ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Channel I n s t a n t i a t i o n s −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
s1_par_input_d : Data ; −− data t o remote and autonomous c h a n n e l s ( p a r a l l e l )
remote_s1_s : Sync ;
s1_move_d : Data ;
s1_move_s : Sync ;
s2_actuator_d : Data ;
s 2 _ a c t u a t o r _ s : Sync ;
end C o n t r o l D a t a C h a n n e l ;
procedure p r o c e e d
−−# g l o b a l out hasRead ;
−−# d e r i v e s hasRead from ;
is
begin
−− Declare t h e c o m p l e t i o n o f a r e a d i n g o p e r a t i o n
hasRead := True ;
end p r o c e e d ;
end Sync ;
end C o n t r o l D a t a C h a n n e l ;
−−# sensorId ,
−−# firstIndex ,
−−# lastIndex ;
is
private
−− V a r i a b l e s used d u r i n g t h e d e c o d i f i c a t i o n p r o c e s s
endValue , endMsg : B o o l e a n ;
s e n s o r I d , f i r s t I n d e x , l a s t I n d e x : DataTypes . Message_Index ;
end D e c o d e r ;
package body De c o d e r is
end s a v e S e n s o r V a l u e ;
s e n s o r I d := l a s t I n d e x ;
end g e t S e n s o r V a l u e ;
−− t o e x t r a c t t h e s u b s t r i n g w i t h t h e c o r r e c t i n d e x e s
function e x t r a c t N u m b e r ( Item : DataTypes .MESSAGE;
S i n c e : DataTypes . Message_Index ;
To : DataTypes . Message_Index )
return DataTypes .SPEED_TYPE i s
pragma I n l i n e ( e x t r a c t N u m b e r ) ;
r e s u l t : DataTypes .SPEED_TYPE;
begin
declare
subtype Str_Number i s S t r i n g ( 1 . . To − S i n c e + 1 ) ;
begin
return r e s u l t ;
end ;
end e x t r a c t N u m b e r ;
end D e c o d e r ;
−− t r a n s f o r m s a SensorData i n t o a MESSAGE
procedure s e n s o r T o M e s s a g e ( s t r u c t : i n DataTypes . S e n s o r D a t a ;
msg : out DataTypes .MESSAGE) ;
−−# d e r i v e s msg from s t r u c t ;
−− t r a n s f o r m s an ActuationData i n t o a MESSAGE
procedure a c t u a t i o n T o M e s s a g e ( s t r u c t : i n DataTypes . A c t u a t i o n D a t a ;
msg : out DataTypes .MESSAGE) ;
−−# d e r i v e s msg from s t r u c t ;
end Encoder ;
procedure s e n s o r T o M e s s a g e ( s t r u c t : i n DataTypes . S e n s o r D a t a ;
msg : out DataTypes .MESSAGE)
is
pragma I n l i n e ( s e n s o r T o M e s s a g e ) ;
temp : Bounded_Message . Bounded_String ;
begin
−− l o a d data i n t o t h e temporary bounded s t r i n g
temp := Bounded_Message . Append ( temp , ’ $ ’ ) ;
temp := Bounded_Message . Append ( temp , ’ d ’ ) ;
temp := Bounded_Message . Append ( temp , Ada . S t r i n g s . F i x e d . Trim ( F l o a t ’ Image ( s t r u c t .
d i r e c t i o n ) , Ada . S t r i n g s . Both ) ) ;
temp := Bounded_Message . Append ( temp , ’ h ’ ) ;
temp := Bounded_Message . Append ( temp , Ada . S t r i n g s . F i x e d . Trim ( F l o a t ’ Image ( s t r u c t . d e p t h ) ,
Ada . S t r i n g s . Both ) ) ;
temp := Bounded_Message . Append ( temp , ’ $ ’ ) ;
−− t r a n s f e r data i n t o t h e message
f o r i in 1 . . Bounded_Message . Length ( temp ) loop
msg ( i ) := Bounded_Message . Element ( temp , i ) ;
end loop ;
end s e n s o r T o M e s s a g e ;
procedure a c t u a t i o n T o M e s s a g e ( s t r u c t : i n DataTypes . A c t u a t i o n D a t a ;
msg : out DataTypes .MESSAGE)
is
pragma I n l i n e ( a c t u a t i o n T o M e s s a g e ) ;
temp : Bounded_Message . Bounded_String ;
begin
−− l o a d data i n t o t h e temporary bounded s t r i n g
temp := Bounded_Message . Append ( temp , ’ $ ’ ) ;
temp := Bounded_Message . Append ( temp , ’ i ’ ) ;
temp := Bounded_Message . Append ( temp , Ada . S t r i n g s . F i x e d . Trim ( F l o a t ’ Image ( s t r u c t .
v T h r u s t e r 1 ) , Ada . S t r i n g s . Both ) ) ;
temp := Bounded_Message . Append ( temp , ’ j ’ ) ;
temp := Bounded_Message . Append ( temp , Ada . S t r i n g s . F i x e d . Trim ( F l o a t ’ Image ( s t r u c t .
v T h r u s t e r 2 ) , Ada . S t r i n g s . Both ) ) ;
temp := Bounded_Message . Append ( temp , ’ k ’ ) ;
temp := Bounded_Message . Append ( temp , Ada . S t r i n g s . F i x e d . Trim ( F l o a t ’ Image ( s t r u c t .
v T h r u s t e r 3 ) , Ada . S t r i n g s . Both ) ) ;
temp := Bounded_Message . Append ( temp , ’ l ’ ) ;
temp := Bounded_Message . Append ( temp , Ada . S t r i n g s . F i x e d . Trim ( F l o a t ’ Image ( s t r u c t .
v T h r u s t e r 4 ) , Ada . S t r i n g s . Both ) ) ;
temp := Bounded_Message . Append ( temp , ’m ’ ) ;
temp := Bounded_Message . Append ( temp , Ada . S t r i n g s . F i x e d . Trim ( F l o a t ’ Image ( s t r u c t .
v T h r u s t e r 5 ) , Ada . S t r i n g s . Both ) ) ;
temp := Bounded_Message . Append ( temp , ’ n ’ ) ;
temp := Bounded_Message . Append ( temp , Ada . S t r i n g s . F i x e d . Trim ( F l o a t ’ Image ( s t r u c t .
v T h r u s t e r 6 ) , Ada . S t r i n g s . Both ) ) ;
Anexo B -- Códigos Fonte da Arquitetura de Controle 133
−− t r a n s f e r data i n t o t h e message
f o r i in 1 . . Bounded_Message . Length ( temp ) loop
msg ( i ) := Bounded_Message . Element ( temp , i ) ;
end loop ;
end a c t u a t i o n T o M e s s a g e ;
end Encoder ;
package Move
−−# own t a s k moveTask : Move_task ;
is
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Task t h a t do t h e r e a l j o b −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
task type Move_task
−−# g l o b a l i n out ControlDataChannel . s1_move_d ;
−−# i n out StatusChannel . avoid_move_d ;
−−# out ControlDataChannel . s1_move_s ;
−−# out StatusChannel . avoid_move_s ;
−−# out ControlDataChannel . s2_par_input_d ;
−−# out ControlDataChannel . move_s2_s ;
−−# d e r i v e s ControlDataChannel . s1_move_d ,
−−# ControlDataChannel . s1_move_s ,
−−# StatusChannel . avoid_move_d ,
−−# StatusChannel . avoid_move_s ,
−−# ControlDataChannel . s2_par_input_d ,
−−# ControlDataChannel . move_s2_s from &
−−# null from ControlDataChannel . s1_move_d ,
−−# StatusChannel . avoid_move_d ;
−−# d e c l a r e Suspends => ( ControlDataChannel . s1_move_d , StatusChannel . avoid_move_d ,
ControlDataChannel . move_s2_s) ;
is
pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ;
end Move_task ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Methods o f t h e package −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
procedure getNextMovement ( d a n g e r L e v e l : in DataTypes . STATUS ;
s p e e d D a t a : i n DataTypes . C o n t r o l D a t a ;
a v o i d D a t a : i n out DataTypes . C o n t r o l D a t a ;
movement : out DataTypes . C o n t r o l D a t a ) ;
−−# d e r i v e s movement from avoidData ,
−−# dangerLevel ,
−−# speedData &
−−# avoidData from dangerLevel ,
−−# speedData ;
−−−−−−−−−−−−−−−−−−−−−−−−
−− Task i n s t a n t i a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
moveTask : Move_task ;
end Move ;
−− i n d i c a t e s t h e p r e s e n c e o f o b s t a c l e s
d a n g e r L e v e l : DataTypes . STATUS := DataTypes . d e f a u l t S t a t u s ;
−− l a s t command used i n t h e v e h i c l e
a v o i d D a t a : DataTypes . C o n t r o l D a t a := DataTypes . d e f a u l t C o n t r o l D a t a ;
begin
loop
−− r e c e i v e data from t h e d e l i b e r a t i v e l a y e r
C o n t r o l D a t a C h a n n e l . s1_move_d . g e t ( s p e e d D a t a ) ;
C o n t r o l D a t a C h a n n e l . s1_move_s . p r o c e e d ;
−− r e c e i v e t h e data from t h e A v o i d C o l l i s i o n
S t a t u s C h a n n e l . avoid_move_d . g e t ( d a n g e r L e v e l ) ;
S t a t u s C h a n n e l . avoid_move_s . p r o c e e d ;
−− g e n e r a t e t h e n e x t movement
getNextMovement ( d a n g e r L e v e l , speedData , avoidData , movement ) ;
end loop ;
exception
when E r r o r : others =>
Ada . Text_IO . Put_Line ( " E r r o r i n Move" ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Exception_Name ( E r r o r ) ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Excep tion _Message ( E r r o r ) ) ;
end Move_task ;
end Move ;
pragma P r i o r i t y ( C o n s t a n t s . CHANNEL_PRIORITY) ;
private
chData : DataTypes .MESSAGE := DataTypes . d e f a u l t M e s s a g e ;
readyToRead : B o o l e a n := F a l s e ; −− I n i t i a l l y , t h e r e i s no data t o read
end Data ;
pragma P r i o r i t y ( C o n s t a n t s . CHANNEL_PRIORITY) ;
entry s t a y ;
−−# g l o b a l i n out Sync ;
−−# d e r i v e s Sync from ∗ ;
procedure p r o c e e d ;
−−# g l o b a l i n out Sync ;
−−# d e r i v e s Sync from ∗ ;
private
hasRead : B o o l e a n := F a l s e ;
end Sync ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Channel I n s t a n t i a t i o n s −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
baseReader_remote_d : Data ;
baseReader_remote_s : Sync ;
s e n s o r _ b a s e W r i t e r _ d : Data ;
s e n s o r _ b a s e W r i t e r _ s : Sync ;
end MsgChannel ;
−− Block s u c c e s s i v e r e a d i n g s
readyToRead := F a l s e ;
end g e t ;
procedure p r o c e e d
−−# g l o b a l out hasRead ;
−−# d e r i v e s hasRead from ;
is
begin
−− Declare t h e c o m p l e t i o n o f a r e a d i n g o p e r a t i o n
hasRead := True ;
end p r o c e e d ;
end Sync ;
end MsgChannel ;
package Remote
−−# own t a s k remoteTask : Remote_task ;
is
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Task t h a t do t h e r e a l j o b −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
task type Remote_task
−−# g l o b a l i n out MsgChannel . baseReader_remote_d ;
−−# out ControlDataChannel . remote_s1_s ;
−−# out ControlDataChannel . s1_par_input_d ;
−−# out MsgChannel . baseReader_remote_s ;
−−# d e r i v e s ControlDataChannel . remote_s1_s ,
−−# ControlDataChannel . s1_par_input_d ,
−−# MsgChannel . baseReader_remote_s ,
−−# MsgChannel . baseReader_remote_d from &
−−# null from MsgChannel . baseReader_remote_d ;
−−# d e c l a r e Suspends => ( MsgChannel . baseReader_remote_d , ControlDataChannel . remote_s1_s ) ;
is
pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ;
end Remote_task ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Methods o f t h e package −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
procedure d e c o d e M e s s a g e ( msg : i n DataTypes .MESSAGE;
c t r l : out DataTypes . C o n t r o l D a t a ) ;
−−# d e r i v e s c t r l from msg ;
−−−−−−−−−−−−−−−−−−−−−−−−
−− Task i n s t a n t i a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
remoteTask : Remote_task ;
end Remote ;
−− message r e c e i v e d from t h e b a s e s t a t i o n
baseMsg : DataTypes .MESSAGE := DataTypes . d e f a u l t M e s s a g e ;
−− o u t p u t data t o c o n t r o l t h e v e h i c l e
c t r l D a t a : DataTypes . C o n t r o l D a t a := DataTypes . d e f a u l t C o n t r o l D a t a ;
begin
loop
−− c o n v e r t t h e r e c e i v e d message i n t o a s t r u c t u r e
d e c o d e M e s s a g e ( baseMsg , c t r l D a t a ) ;
Anexo B -- Códigos Fonte da Arquitetura de Controle 136
end loop ;
exception
when E r r o r : others =>
Ada . Text_IO . Put_Line ( " E r r o r i n Remote " ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Exception_Name ( E r r o r ) ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Excep tion _Message ( E r r o r ) ) ;
end Remote_task ;
end Remote ;
package S1
−−# own t a s k s1Task : S1_task ;
is
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Task t h a t do t h e r e a l j o b −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
task type S1_task
−−# g l o b a l i n out ControlDataChannel . s1_par_input_d ;
−−# out ControlDataChannel . remote_s1_s ;
−−# out ControlDataChannel . s1_move_d ;
−−# out ControlDataChannel . s1_move_s ;
−−# d e r i v e s ControlDataChannel . remote_s1_s ,
−−# ControlDataChannel . s1_move_d ,
−−# ControlDataChannel . s1_move_s ,
−−# ControlDataChannel . s1_par_input_d from &
−−# null from ControlDataChannel . s1_par_input_d ;
−−# d e c l a r e Suspends => ( ControlDataChannel . s1_par_input_d , ControlDataChannel . s1_move_s) ;
is
pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ;
end S1_task ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Methods o f t h e package −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−−−−−−−−−−−−−−−−−−−−−−−−
−− Task i n s t a n t i a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
s1Task : S1_task ;
end S1 ;
package body S1 i s
−− o u t p u t data t o c o n t r o l t h e v e h i c l e
c t r l D a t a : DataTypes . C o n t r o l D a t a := DataTypes . d e f a u l t C o n t r o l D a t a ;
begin
loop
end loop ;
exception
when E r r o r : others =>
Ada . Text_IO . Put_Line ( " E r r o r i n S1 " ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Exception_Name ( E r r o r ) ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Excep tion _Message ( E r r o r ) ) ;
end S1_task ;
end S1 ;
−−# ControlDataChannel ;
package S2
−−# own t a s k s2Task : S2_task ;
is
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Task t h a t do t h e r e a l j o b −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
task type S2_task
−−# g l o b a l i n out ControlDataChannel . s2_par_input_d ;
−−# out ControlDataChannel . move_s2_s ;
−−# out ControlDataChannel . stop_s2_s ;
−−# out ControlDataChannel . s2_actuator_d ;
−−# out ControlDataChannel . s2_actuator_s ;
−−# d e r i v e s ControlDataChannel . s2_par_input_d ,
−−# ControlDataChannel . move_s2_s ,
−−# ControlDataChannel . stop_s2_s ,
−−# ControlDataChannel . s2_actuator_d ,
−−# ControlDataChannel . s2_actuator_s from &
−−# null from ControlDataChannel . s2_par_input_d ;
−−# d e c l a r e Suspends => ( ControlDataChannel . s2_par_input_d , ControlDataChannel .
s2_actuator_s ) ;
is
pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ;
end S2_task ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Methods o f t h e package −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−−−−−−−−−−−−−−−−−−−−−−−−
−− Task i n s t a n t i a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
s2Task : S2_task ;
end S2 ;
package body S2 i s
−− t o s t o r e t h e t r a n s m i t t e d data
c t r l D a t a : DataTypes . C o n t r o l D a t a := DataTypes . d e f a u l t C o n t r o l D a t a ;
begin
loop
end loop ;
exception
when E r r o r : others =>
Ada . Text_IO . Put_Line ( " E r r o r i n S2 " ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Exception_Name ( E r r o r ) ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Excep tion _Message ( E r r o r ) ) ;
end S2_task ;
end S2 ;
package S e n s o r
−−# own t a s k sensorTask : Sensor_task ;
is
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Task t h a t do t h e r e a l j o b −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
task type S e n s o r _ t a s k
−−# g l o b a l i n BlackBoard . blckBoard ;
−−# out MsgChannel . sensor_baseWriter_d ;
−−# out MsgChannel . sensor_baseWriter_s ;
−−# d e r i v e s MsgChannel . sensor_baseWriter_d ,
−−# MsgChannel . sensor_baseWriter_s from &
−−# null from BlackBoard . blckBoard ;
−−# d e c l a r e Suspends => MsgChannel . sensor_baseWriter_s ;
is
pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ;
end S e n s o r _ t a s k ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Methods o f t h e package −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
procedure g e t S e n s o r s ( s e n s o r s : out DataTypes . S e n s o r D a t a ) ;
−−# g l o b a l i n BlackBoard . blckBoard ;
−−# d e r i v e s s e n s o r s from BlackBoard . blckBoard ;
procedure s t r u c t u r e T o M e s s a g e ( s t r u c t : i n DataTypes . S e n s o r D a t a ;
Anexo B -- Códigos Fonte da Arquitetura de Controle 138
−−−−−−−−−−−−−−−−−−−−−−−−
−− Task i n s t a n t i a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
sensorTask : Sensor_task ;
end S e n s o r ;
package body S e n s o r is
task body S e n s o r _ t a s k is
−− t o s t o r e t h e s e n s o r r e a d i n g s
s e n s o r s : DataTypes . S e n s o r D a t a := DataTypes . d e f a u l t S e n s o r D a t a ;
−− time a t t i b u t e s ( o n l y f o r P e r i o d i c P r o c e s s e s )
n e x t E x e c u t i o n : Ada . Real_Time . Time := C o n s t a n t s .SENSOR_START;
PERIOD : constant Ada . Real_Time . Time_Span := C o n s t a n t s . SENSOR_PERIOD ;
−− time method ( o n l y f o r P e r i o d i c P r o c e s s e s )
procedure g e t N e x t E x e c u t i o n i s
begin
n e x t E x e c u t i o n := n e x t E x e c u t i o n + PERIOD ;
end g e t N e x t E x e c u t i o n ;
begin
loop
delay u n t i l n e x t E x e c u t i o n ;
−− g e t t h e d i r e c t i o n from t h e compass
getSensors ( sensors ) ;
−− s a v e t h e d i r e c t i o n i n t o t h e BlackBoard
s t r u c t u r e T o M e s s a g e ( s e n s o r s , msgToSend ) ;
getNextExecution ;
end loop ;
exception
when E r r o r : others =>
Ada . Text_IO . Put_Line ( " E r r o r i n S e n s o r " ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Exception_Name ( E r r o r ) ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Excep tion _Message ( E r r o r ) ) ;
end S e n s o r _ t a s k ;
procedure s t r u c t u r e T o M e s s a g e ( s t r u c t : i n DataTypes . S e n s o r D a t a ;
msg : out DataTypes .MESSAGE) i s
pragma I n l i n e ( s t r u c t u r e T o M e s s a g e ) ;
begin
Encoder . s e n s o r T o M e s s a g e ( s t r u c t , msg ) ;
end s t r u c t u r e T o M e s s a g e ;
end S e n s o r ;
package GNAT i s
end GNAT;
package GNAT. S o c k e t s is
end GNAT. S o c k e t s ;
package S o n a r
−−# own t a s k sonarTask : Sonar_task ;
is
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Task t h a t do t h e r e a l j o b −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
task type S o n a r _ t a s k
−−# g l o b a l out BlackBoard . blckBoard ;
−−# d e r i v e s BlackBoard . blckBoard from ;
Anexo B -- Códigos Fonte da Arquitetura de Controle 139
is
pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ;
end S o n a r _ t a s k ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Methods o f t h e package −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
procedure g e t S o n a r ( s o n a r s : out DataTypes .SONAR_TYPE) ;
−−# d e r i v e s sonars from ;
−−−−−−−−−−−−−−−−−−−−−−−−
−− Task i n s t a n t i a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
sonarTask : Sonar_task ;
end S o n a r ;
package body S o n a r is
task body S o n a r _ t a s k is
−− s t o r e s t h e sonar r e a d i n g s
s o n a r : DataTypes .SONAR_TYPE;
−− time a t t i b u t e s ( o n l y f o r P e r i o d i c P r o c e s s e s )
n e x t E x e c u t i o n : Ada . Real_Time . Time := C o n s t a n t s .SONAR_START;
PERIOD : constant Ada . Real_Time . Time_Span := C o n s t a n t s .SONAR_PERIOD;
−− time method ( o n l y f o r P e r i o d i c P r o c e s s e s )
procedure g e t N e x t E x e c u t i o n i s
begin
n e x t E x e c u t i o n := n e x t E x e c u t i o n + PERIOD ;
end g e t N e x t E x e c u t i o n ;
begin
loop
delay u n t i l n e x t E x e c u t i o n ;
−− g e t t h e sonar r e a d i n g s
getSonar ( sonar ) ;
−− s a v e t h e sonar r e a d i n g s i n t o t h e BlackBoard
saveSonar ( sonar ) ;
getNextExecution ;
end loop ;
exception
when E r r o r : others =>
Ada . Text_IO . Put_Line ( " E r r o r i n S o n a r " ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Exception_Name ( E r r o r ) ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Excep tion _Message ( E r r o r ) ) ;
end S o n a r _ t a s k ;
end S o n a r ;
pragma P r i o r i t y ( C o n s t a n t s . CHANNEL_PRIORITY) ;
private
chData : DataTypes . STATUS := DataTypes . d e f a u l t S t a t u s ;
readyToRead : B o o l e a n := F a l s e ; −− I n i t i a l l y , t h e r e i s no data t o read
end Data ;
pragma P r i o r i t y ( C o n s t a n t s . CHANNEL_PRIORITY) ;
entry s t a y ;
−−# g l o b a l i n out Sync ;
−−# d e r i v e s Sync from ∗ ;
procedure p r o c e e d ;
−−# g l o b a l i n out Sync ;
−−# d e r i v e s Sync from ∗ ;
private
hasRead : B o o l e a n := F a l s e ;
end Sync ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Channel I n s t a n t i a t i o n s −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
avoid_move_d : Data ;
avoid_move_s : Sync ;
end S t a t u s C h a n n e l ;
procedure p r o c e e d
−−# g l o b a l out hasRead ;
−−# d e r i v e s hasRead from ;
is
begin
−− Declare t h e c o m p l e t i o n o f a r e a d i n g o p e r a t i o n
hasRead := True ;
end p r o c e e d ;
end Sync ;
end S t a t u s C h a n n e l ;
package S o n a r
−−# own t a s k sonarTask : Sonar_task ;
is
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Task t h a t do t h e r e a l j o b −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
task type S o n a r _ t a s k
−−# g l o b a l out BlackBoard . blckBoard ;
−−# d e r i v e s BlackBoard . blckBoard from ;
is
pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ;
end S o n a r _ t a s k ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Methods o f t h e package −−
Anexo B -- Códigos Fonte da Arquitetura de Controle 141
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
procedure g e t S o n a r ( s o n a r s : out DataTypes .SONAR_TYPE) ;
−−# d e r i v e s sonars from ;
−−−−−−−−−−−−−−−−−−−−−−−−
−− Task i n s t a n t i a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
sonarTask : Sonar_task ;
end S o n a r ;
−− time o f t h e l a s t r e c e i v e d message
l a s t R e c e p t i o n : Ada . Real_Time . Time := Ada . Real_Time . C l o c k ;
−− data w i t h n u l l s p e e d s
s t p D a t a : constant DataTypes . C o n t r o l D a t a := DataTypes . d e f a u l t C o n t r o l D a t a ;
−− time a t t i b u t e s ( o n l y f o r P e r i o d i c P r o c e s s e s )
n e x t E x e c u t i o n : Ada . Real_Time . Time := C o n s t a n t s .COMPASS_START;
PERIOD : constant Ada . Real_Time . Time_Span := C o n s t a n t s .COMPASS_PERIOD;
−− time method ( o n l y f o r P e r i o d i c P r o c e s s e s )
procedure g e t N e x t E x e c u t i o n i s
begin
n e x t E x e c u t i o n := n e x t E x e c u t i o n + PERIOD ;
end g e t N e x t E x e c u t i o n ;
begin
loop
delay u n t i l n e x t E x e c u t i o n ;
getNextExecution ;
end l o o p ;
exception
when E r r o r : o t h e r s =>
Ada . Text_IO . Put_Line ( " E r r o r i n Stop " ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Exception_Name ( E r r o r ) ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Excep tion _Message ( E r r o r ) ) ;
end Stop_task ;
end Stop ;
package T h r u s t e r W r i t e r
−−# own t a s k t h r u s t e r W r i t e r T a s k : ThrusterWriter_task ;
is
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Task t h a t do t h e r e a l j o b −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
task type T h r u s t e r W r i t e r _ t a s k
−−# g l o b a l i n out ActuationDataChannel . ac tuator _thr us t er _d ;
−−# out ActuationDataChannel . a c t u a t o r _ t h r u s t e r _ s ;
−−# d e r i v e s ActuationDataChannel . actuator_thruster_d ,
−−# ActuationDataChannel . a c t u a t o r _ t h r u s t e r _ s from &
−−# null from ActuationDataChannel .
act uat or _ thr u st er_ d ;
−−# d e c l a r e Suspends => ActuationDataChannel . ac tua tor _thr us te r _ d ;
is
pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ;
end T h r u s t e r W r i t e r _ t a s k ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Methods o f t h e package −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−
procedure s e n d M e s s a g e ( msg : i n DataTypes .MESSAGE) ;
−−# d e r i v e s n u l l from msg ;
Anexo B -- Códigos Fonte da Arquitetura de Controle 142
procedure g e n e r a t e M e s s a g e ( s t r u c t : i n DataTypes . A c t u a t i o n D a t a ;
msg : out DataTypes .MESSAGE) ;
−−# d e r i v e s msg from s t r u c t ;
−−−−−−−−−−−−−−−−−−−−−−−−
−− Task i n s t a n t i a t i o n −−
−−−−−−−−−−−−−−−−−−−−−−−−
thrusterWriterTask : ThrusterWriter_task ;
end T h r u s t e r W r i t e r ;
package body T h r u s t e r W r i t e r is
task body T h r u s t e r W r i t e r _ t a s k is
−− s t o r e t h e s e t p o i n t s t o t h e t h r u s t e r s
s e t p o i n t s : DataTypes . A c t u a t i o n D a t a := DataTypes . d e f a u l t A c t u a t i o n D a t a ;
−− message t o t h e c o n t r o l l e r
c o n t r o l l e r M s g : DataTypes .MESSAGE := DataTypes . d e f a u l t M e s s a g e ;
begin
loop
−− g e n e r a t e t h e message t o t h e c o n t r o l l e r
generateMessage ( setpoints , controllerMsg ) ;
end loop ;
exception
when E r r o r : others =>
Ada . Text_IO . Put_Line ( " E r r o r i n T h r u s t e r W r i t e r " ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Exception_Name ( E r r o r ) ) ;
Ada . Text_IO . Put_Line ( Ada . E x c e p t i o n s . Excep tion _Message ( E r r o r ) ) ;
end T h r u s t e r W r i t e r _ t a s k ;
procedure g e n e r a t e M e s s a g e ( s t r u c t : i n DataTypes . A c t u a t i o n D a t a ;
msg : out DataTypes .MESSAGE) i s
pragma I n l i n e ( g e n e r a t e M e s s a g e ) ;
begin
Encoder . a c t u a t i o n T o M e s s a g e ( s t r u c t , msg ) ;
end g e n e r a t e M e s s a g e ;
end T h r u s t e r W r i t e r ;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− This package c o n t a i n s a l l t h e code n e c e s s a r y t o send and r e c e i v e UDP. I t −−
−− was d e v e l o p t o use w i t h two s o c k e t s : one t o send and o t h e r t o r e c e i v e −−
−− t h e messages , b o t h i n d i f f e r e n t t a s k s . −−
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
package UDP_Sockets i s
private
Anexo B -- Códigos Fonte da Arquitetura de Controle 143
−−# h i d e UDP_Sockets ;
type UDP_Socket i s
record
Address : GNAT. S o c k e t s . Sock_Addr_Type ;
Socket : GNAT. S o c k e t s . Socket_Type ;
DataBuffer : Ada . S t r e a m s . Stream_Element_Array ( 1 . . BUFFER_SIZE) ;
Last : Ada . S t r e a m s . Stream_Element_Offset ;
end record ;
end UDP_Sockets ;
−− A s s o c i a t e s t h e s o c k e t w i t h t h e r e c e p t i o n Address
Bind_Socket ( t h i s . S o c k e t , t h i s . A d d r e s s ) ;
end c r e a t e _ R e c e i v e r _ S o c k e t ;
−− Configure t h e d e s t i n a t i o n Address
t h i s . A d d r e s s . Addr := Inet_Addr (DESTINATION_IP) ;
t h i s . A d d r e s s . P o r t := GNAT. S o c k e t s . Port_Type (DESTINATION_PORT) ;
−− A s s o c i a t e s a d e f a u l t a d d r e s s t o which messages s h o u l d be s e n t
Connect_Socket ( t h i s . S o c k e t , t h i s . A d d r e s s ) ;
end c r e a t e _ S e n d e r _ S o c k e t ;
return R e s u l t ;
end To_String ;
begin
GNAT. S o c k e t s . I n i t i a l i z e ; −− r e q u i r e d by t h e library
end UDP_Sockets ;