• Nenhum resultado encontrado

Seguem os códigos fonte dos arquivos utilizados na implementação da Arqui- tetura de Controle desenvolvida para o ROV utilizado neste trabalho.

Código Fonte B.1: Arquivo DataTypes.ads

with Ada . Real_Time ; −−# i n h e r i t Ada . Real_Time ;

package DataTypes i s

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− −− DATA TYPE DECLARATIONS USED IN THE IMPLEMENTATION −− −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

type STATUS i s ( normal , a l e r t ) ;

m s g S i z e : constant I n t e g e r := 1 0 0 ; −− Maximum message s i z e a l l o w e d subtype Message_Index i s I n t e g e r range 1 . . m s g S i z e ;

subtype MESSAGE i s S t r i n g ( Message_Index ) ;

subtype COMPASS_TYPE i s F l o a t range 0 . 0 . . 3 6 0 . 0 ; subtype ALTIMETER_TYPE i s F l o a t range 0 . 0 . . 3 0 0 . 0 ; subtype SPEED_TYPE i s F l o a t range −1.0 . . 1 . 0 ; subtype TORQUE_TYPE i s F l o a t range −500.0 . . 5 0 0 . 0 ; subtype Sonar_Index i s I n t e g e r range 1 . . 4 ; subtype Sonar_Range i s F l o a t range 0 . 0 . . 1 . 0 ; type SONAR_TYPE i s array ( Sonar_Index ) o f Sonar_Range ; 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; depth : 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;

−− To c o n s t r a i n t h e t y p e S t r i n g , used t o decode t h e message −− and as an IP a d d r e s s

subtype Str_Number_Index i s I n t e g e r range 1 . . 2 0 ; subtype Str_Number i s S t r i n g ( Str_Number_Index ) ; subtype IP_Index i s I n t e g e r range 1 . . 1 5 ; subtype IP_Address i s S t r i n g ( IP_Index ) ; −−−−−−−−−−−−−−−−−−−−−−−−−−−− −− 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 := ControlData ’ ( 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 := SensorData ’ ( d i r e c t i o n => 0 . 0 , depth => 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 := ActuationData ’

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 ;

Código Fonte B.2: Arquivo Constants.ads

with Ada . Real_Time ; use type Ada . Real_Time . Time ; with System , DataTypes ;

−−# i n h e r i t System , −−# DataTypes , −−# Ada . Real_Time ; −− E n c a p s u l a t e t h e i n f o r m a t i o n s f o r c o n f i g u r a t i o n s used i n t h e p r o c e s s e s package C o n s t a n t s i s −−−−−−−−−−−−−−−−−−−−−−−− −− 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 ; −− S t a r t Time o f each p e r i o d i c Task o f t h e program

SENSOR_START: constant Ada . Real_Time . Time := START_TIME + Ada . Real_Time . M i l l i s e c o n d s ( 1 0 ) ; COMPASS_START: constant Ada . Real_Time . Time := START_TIME + Ada . Real_Time . M i l l i s e c o n d s ( 3 0 ) ; ALTIMETER_START: constant Ada . Real_Time . Time := START_TIME + Ada . Real_Time . M i l l i s e c o n d s

( 1 5 ) ;

SONAR_START: constant Ada . Real_Time . Time := START_TIME + Ada . Real_Time . M i l l i s e c o n d s ( 2 0 ) ; STOP_START: constant Ada . Real_Time . Time := START_TIME + Ada . Real_Time . M i l l i s e c o n d s ( 2 5 ) ; −− P e r i o d o f each p e r i o d i c Task o f t h e program

SENSOR_PERIOD : constant Ada . Real_Time . Time_Span := Ada . Real_Time . M i l l i s e c o n d s ( 1 0 0 ) ; COMPASS_PERIOD: constant Ada . Real_Time . Time_Span := Ada . Real_Time . M i l l i s e c o n d s ( 1 0 0 ) ; ALTIMETER_PERIOD: constant Ada . Real_Time . Time_Span := Ada . Real_Time . M i l l i s e c o n d s ( 1 0 0 ) ; SONAR_PERIOD: constant Ada . Real_Time . Time_Span := Ada . Real_Time . M i l l i s e c o n d s ( 1 0 0 ) ; STOP_PERIOD : constant Ada . Real_Time . Time_Span := Ada . Real_Time . M i l l i s e c o n d s ( 1 0 0 ) ; −−−−−−−−−−−−−−−−

−− 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 Information −− −−−−−−−−−−−−−−−−−−−−−−−−

BASEREADER_PORT: constant I n t e g e r := 1 4 0 0 1 ;

THRUSTERWRITER_IP: constant DataTypes . IP_Address := " 1 4 3 . 1 0 7 . 0 9 9 . 2 2 7 " ; THRUSTERWRITER_PORT: constant I n t e g e r := 1 4 0 0 2 ;

BASEWRITER_IP : constant DataTypes . IP_Address := " 1 4 3 . 1 0 7 . 0 9 9 . 2 2 7 " ; BASEWRITER_PORT: constant I n t e g e r := 1 4 0 0 0 ;

end C o n s t a n t s ;

Código Fonte B.3: Arquivo Main ROV Embedded.adb

−− E n a b l e s t h e Ravenscar P r o f i l e pragma P r o f i l e ( R a v e n s c a r ) ; with BaseReader , Remote , BlackBoard , Compass , A l t i m e t e r , Sonar , S e n s o r , BaseWr iter , S1 , S2 , Move , A v o i d C o l l i s i o n , A c t u a t o r , Stop , T h r u s t e r W r i t e r ; −−# i n h e r i t BaseReader , −−# Remote , −−# MsgChannel , −−# ControlDataChannel , −−# BlackBoard , −−# Compass , −−# A lt i me te r , −−# Sonar , −−# Sensor , −−# BaseWriter , −−# S1 , −−# S2 , −−# Move , −−# A v o i d C o l l i s i o n , −−# Actuator , −−# Stop , −−# ThrusterWriter , −−# ActuationDataChannel , −−# StatusChannel ,

Anexo B -- Códigos Fonte da Arquitetura de Controle 121

−−# Ada . Real_Time ; −−# main_program ;

−−# g l o b a l in Ada . Real_Time . ClockTime ;

−−# i n out ControlDataChannel . s1_par_input_d ; −−# i n out ControlDataChannel . s1_move_d ; −−# i n out ControlDataChannel . s1_move_s ; −−# i n out MsgChannel . baseReader_remote_s ; −−# i n out MsgChannel . baseReader_remote_d ; −−# i n out ControlDataChannel . remote_s1_s ; −−# i n out ControlDataChannel . move_s2_s ; −−# i n out ControlDataChannel . stop_s2_s ; −−# i n out ControlDataChannel . s2_actuator_s ; −−# i n out StatusChannel . avoid_move_s ;

−−# i n out ActuationDataChannel . a ctu at or _t hru st er _s ; −−# i n out ControlDataChannel . s2_actuator_d ;

−−# i n out StatusChannel . avoid_move_d ;

−−# i n out ActuationDataChannel . actuator_thruster_d ; −−# i n out ControlDataChannel . s2_par_input_d ; −−# i n out MsgChannel . sensor_baseWriter_s ; −−# i n out MsgChannel . sensor_baseWriter_d ; −−# i n out BlackBoard . blckBoard ;

−−# d e r i v e s ControlDataChannel . s1_par_input_d , −−# ControlDataChannel . s1_move_d , −−# ControlDataChannel . s1_move_s , −−# MsgChannel . baseReader_remote_s , −−# MsgChannel . baseReader_remote_d , −−# ControlDataChannel . remote_s1_s , −−# ControlDataChannel . move_s2_s , −−# ControlDataChannel . stop_s2_s , −−# ControlDataChannel . s2_actuator_s , −−# StatusChannel . avoid_move_s , −−# ActuationDataChannel . actuator_thruster_s , −−# ControlDataChannel . s2_actuator_d , −−# StatusChannel . avoid_move_d , −−# ActuationDataChannel . actuator_thruster_d ,

−−# ControlDataChannel . s2_par_input_d from ControlDataChannel . s1_par_input_d ,

−−# ControlDataChannel . s1_move_d , −−# ControlDataChannel . s1_move_s , −−# MsgChannel . baseReader_remote_s , −−# MsgChannel . baseReader_remote_d , −−# ControlDataChannel . remote_s1_s , −−# ControlDataChannel . move_s2_s , −−# ControlDataChannel . stop_s2_s , −−# ControlDataChannel . s2_actuator_s , −−# StatusChannel . avoid_move_s , −−# ActuationDataChannel . actuator_thruster_s , −−# ControlDataChannel . s2_actuator_d , −−# StatusChannel . avoid_move_d , −−# ActuationDataChannel . actuator_thruster_d ,

−−# ControlDataChannel . s2_par_input_d &

−−# MsgChannel . sensor_baseWriter_s ,

−−# MsgChannel . sensor_baseWriter_d from MsgChannel . sensor_baseWriter_s ,

−−# MsgChannel . sensor_baseWriter_d &

−−# BlackBoard . blckBoard from ControlDataChannel . s1_par_input_d ,

−−# ControlDataChannel . s1_move_d , −−# ControlDataChannel . s1_move_s , −−# MsgChannel . baseReader_remote_s , −−# MsgChannel . baseReader_remote_d , −−# ControlDataChannel . remote_s1_s , −−# ControlDataChannel . move_s2_s , −−# ControlDataChannel . stop_s2_s , −−# ControlDataChannel . s2_actuator_s , −−# StatusChannel . avoid_move_s , −−# ActuationDataChannel . actuator_thruster_s , −−# ControlDataChannel . s2_actuator_d , −−# StatusChannel . avoid_move_d , −−# ActuationDataChannel . actuator_thruster_d , −−# ControlDataChannel . s2_par_input_d ,

−−# Ada . Real_Time . ClockTime &

−−# n u l l from BlackBoard . blckBoard ; procedure Main_ROV_Embedded

−−# d e r i v e s ; i s

pragma P r i o r i t y ( 1 0 ) ; −− a p r i o r i t y i s mandatory and must appear here begin

n u l l; −− a l l t h e r e a l work i s done somewhere e l s e end Main_ROV_Embedded ;

Código Fonte B.4: Arquivo ActuationDataChannel.ads

with C o n s t a n t s , DataTypes ; −−# i n h e r i t Constants , −−# DataTypes ;

−− A c h a n n e l has two p r o t e c t e d o b j e c t s : Data and Sync . The Data p r o t e c t e d −− o b j e c t i s t h e data communicated through t h e channel . Sync i s a s y n c h r o n i z e r .

package A c t u a t i o n D a t a C h a n n e l

−−# own p r o t e c t e d actuator_thruster_d : Data ( p r i o r i t y => Constants .CHANNEL_PRIORITY,

−−# s u s p e n d a b l e ) ;

−−# p r o t e c t e d a ct ua to r_t hr us te r_s : Sync ( p r i o r i t y => Constants .CHANNEL_PRIORITY,

−−# s u s p e n d a b l e ) ;

i s

protected type Data i s

pragma P r i o r i t y ( C o n s t a n t s . CHANNEL_PRIORITY) ; entry g e t ( someData : out DataTypes . A c t u a t i o n D a t a ) ; −−# g l o b a l in out Data ;

−−# d e r i v e s Data ,

−−# someData from Data ;

procedure put ( someData : in DataTypes . A c t u a t i o n D a t a ) ; −−# g l o b a l in out Data ;

−−# d e r i v e s Data from ∗ ,

−−# someData ;

p r i v a t e

Anexo B -- Códigos Fonte da Arquitetura de Controle 122

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 ;

protected type Sync i s

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 in 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 in out Sync ; −−# d e r i v e s Sync from ∗ ; p r i v a t e 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 ;

Código Fonte B.5: Arquivo ActuationDataChannel.adb

package body A c t u a t i o n D a t a C h a n n e l i s protected body Data i s

entry g e t ( someData : out DataTypes . A c t u a t i o n D a t a ) when readyToRead −−# g l o b a l in chData ;

−−# out readyToRead ; −−# d e r i v e s readyToRead from & −−# someData from chData ;

i s begin −− Read t h e e n c a p s u l a t e d data someData := chData ; −− B l o c k 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 put ( someData : in DataTypes . A c t u a t i o n D a t a ) −−# g l o b a l out readyToRead ;

−−# out chData ;

−−# d e r i v e s readyToRead from & −−# chData from someData ;

i s begin −− Update t h e e n c a p s u l a t e d data chData := someData ; −− Permit f o r t h e n e x t w r i t i n g o p e r a t i o n readyToRead := True ; end put ; end Data ;

protected body Sync i s entry s t a y when hasRead −−# g l o b a l out hasRead ; −−# d e r i v e s hasRead from ; i s begin −− S t a y f o r t h e data t o be read hasRead := F a l s e ; end s t a y ; 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 ; i s begin −− D e c l a r e t h e completion 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 ;

Código Fonte B.6: Arquivo Actuator.ads

with C o n s t a n t s , DataTypes ; −−# i n h e r i t Constants , −−# DataTypes , −−# ControlDataChannel , −−# ActuationDataChannel ; package A c t u a t o r

−−# own t a s k actuatorTask : Actuator_task ; i s

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− −− 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 in out ControlDataChannel . s2_actuator_d ;

−−# out ActuationDataChannel . actuator_thruster_d ; −−# out ControlDataChannel . s2_actuator_s ;

−−# out ActuationDataChannel . act ua to r_ thr us te r_ s ; −−# d e r i v e s ActuationDataChannel . actuator_thruster_d , −−# ControlDataChannel . s2_actuator_s ,

−−# ControlDataChannel . s2_actuator_d ,

−−# ActuationDataChannel . a ctu at or _t hru st er _s from &

−−# n u l l from ControlDataChannel . s2_actuator_d ;

−−# d e c l a r e Suspends => ( ControlDataChannel . s2_actuator_d , ActuationDataChannel . a ct uat or _t hr ust er _s ) ;

Anexo B -- Códigos Fonte da Arquitetura de Controle 123 i s 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 : in 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 −− −−−−−−−−−−−−−−−−−−−−−−−− a c t u a t o r T a s k : A c t u a t o r _ t a s k ; end A c t u a t o r ;

Código Fonte B.7: Arquivo Actuator.adb

with ControlDataChannel , A c t u a t i o n D a t a C h a n n e l ; with Ada . Text_IO , Ada . E x c e p t i o n s ;

package body A c t u a t o r i s task body A c t u a t o r _ t a s k i s −− 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

−− r e c e i v e data from t h e i n p u t channel

C o n t r o l D a t a C h a n n e l . s2_actuator_d . g e t ( c t r l D a t a ) ; C o n t r o l D a t a C h a n n e l . s 2 _ a c t u a t o r _ s . p r o c e e d ; −− 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

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 , s e t p o i n t s ) ; −− send data through t h e o u t p u t channel

A c t u a t i o n D a t a C h a n n e l . a c t u a t o r _ t h r u s t e r _ d . put ( s e t p o i n t s ) ; A c t u a t i o n D a t a C h a n n e l . a c t u a t o r _ t h r u s t e r _ 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 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 . Exception_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 : in 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 ) i s 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 ;

Código Fonte B.8: Arquivo Altimeter.ads

with DataTypes , C o n s t a n t s ; −−# i n h e r i t DataTypes , −−# Constants , −−# BlackBoard ; 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 : Altimeter_task ; i s −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− −− 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 ;

i s 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 getDepth ( depth : out DataTypes .ALTIMETER_TYPE) ; −−# d e r i v e s depth from ;

procedure saveDepth ( depth : in DataTypes .ALTIMETER_TYPE) ; −−# g l o b a l out BlackBoard . blckBoard ;

−−# d e r i v e s BlackBoard . blckBoard from depth ; −−−−−−−−−−−−−−−−−−−−−−−−

−− Task i n s t a n t i a t i o n −− −−−−−−−−−−−−−−−−−−−−−−−−

Anexo B -- Códigos Fonte da Arquitetura de Controle 124

end A l t i m e t e r ;

Código Fonte B.9: Arquivo Altimeter.adb

with Ada . Real_Time ; use type Ada . Real_Time . Time ; with BlackBoard ;

with Ada . E x c e p t i o n s , Ada . Text_IO ; package body A l t i m e t e r i s

task body A l t i m e t e r _ t a s k i s

−− 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 depth : DataTypes .ALTIMETER_TYPE;

−− t i m e a t t i b u t e s ( o n l y f o r P e r i o d i c Processes )

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; −− t i m e method ( o n l y f o r P e r i o d i c Processes ) 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 depth from t h e a l t i m e t e r getDepth ( depth ) ; −− s a v e t h e depth i n t o t h e BlackBoard saveDepth ( depth ) ; g e t N e x t E x e c u t i o n ; 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 . Exception_Message ( E r r o r ) ) ; end A l t i m e t e r _ t a s k ;

procedure getDepth ( depth : out DataTypes .ALTIMETER_TYPE) i s pragma I n l i n e ( getDepth ) ;

begin

depth := 1 5 . 0 ; end getDepth ;

procedure saveDepth ( depth : in DataTypes .ALTIMETER_TYPE) i s pragma I n l i n e ( saveDepth ) ;

begin

BlackBoard . b l c k B o a r d . s e t D e p t h ( depth ) ; end saveDepth ;

end A l t i m e t e r ;

Código Fonte B.10: Arquivo AvoidCollision.ads

with DataTypes , C o n s t a n t s ; −−# i n h e r i t DataTypes , −−# Constants , −−# StatusChannel , −−# BlackBoard ; 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 : A v o i d C o l l i s i o n _ t a s k ; i s −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− −− 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 in 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 &

−−# n u l l from BlackBoard . blckBoard ; −−# d e c l a r e Suspends => StatusChannel . avoid_move_s ;

i s 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 in BlackBoard . blckBoard ;

−−# d e r i v e s sonars from BlackBoard . blckBoard ;

procedure g e n e r a t e A v o i d ( s o n a r s : in DataTypes .SONAR_TYPE; LIMIT : in DataTypes . Sonar_Range ; a v o i d D a t a : out DataTypes . STATUS) ; −−# d e r i v e s avoidData from sonars ,

−−# LIMIT ; −−−−−−−−−−−−−−−−−−−−−−−− −− Task i n s t a n t i a t i o n −− −−−−−−−−−−−−−−−−−−−−−−−− a v o i d C o l l i s i o n T a s k : 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 ;

Anexo B -- Códigos Fonte da Arquitetura de Controle 125

Código Fonte B.11: Arquivo AvoidCollision.adb

with Ada . Real_Time ; use type Ada . Real_Time . Time ; with S t a t u s C h a n n e l , BlackBoard ;

with Ada . E x c e p t i o n s , Ada . text_IO ; package body A v o i d C o l l i s i o n i s

task body A v o i d C o l l i s i o n _ t a s k i s

−− 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 presence o f o b s t a c l e s LIMIT : constant DataTypes . Sonar_Range := 0 . 8 ; −− t i m e a t t i b u t e s ( o n l y f o r P e r i o d i c Processes )

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; −− t i m e method ( o n l y f o r P e r i o d i c Processes ) 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 in t h e BlackBoard g e t S o n a r R e a d i n g s ( s o n a r s ) ; −− 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 ) ; −− send data through t h e o u t p u t channel

S t a t u s C h a n n e l . avoid_move_d . put ( a v o i d D a t a ) ; S t a t u s C h a n n e l . avoid_move_s . s t a y ; g e t N e x t E x e c u t i o n ; 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 . Exception_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 ;

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) i s pragma I n l i n e ( g e t S o n a r R e a d i n g s ) ;

begin

BlackBoard . b l c k B o a r d . g e t S o n a r ( s o n a r s ) ; end g e t S o n a r R e a d i n g s ;

procedure g e n e r a t e A v o i d ( s o n a r s : in DataTypes .SONAR_TYPE; LIMIT : in DataTypes . Sonar_Range ; a v o i d D a t a : out DataTypes . STATUS) i s pragma I n l i n e ( g e n e r a t e A v o i d ) ; begin f o r i in s o n a r s ’ range loop i f s o n a r s ( i ) >= LIMIT then a v o i d D a t a := DataTypes . a l e r t ; e l s e a v o i d D a t a := DataTypes . normal ; end i f; end loop; end g e n e r a t e A v o i d ; end A v o i d C o l l i s i o n ;

Código Fonte B.12: Arquivo BaseReader.ads

with DataTypes , C o n s t a n t s , UDP_Sockets ; −−# i n h e r i t DataTypes , −−# Constants , −−# MsgChannel , −−# UDP_Sockets , −−# BlackBoard , −−# Ada . Real_Time ; package BaseReader

−−# own t a s k baseReaderTask : BaseReader_task ; i s

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− −− Task t h a t do t h e r e a l j o b −− −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

task type BaseReader_task

−−# g l o b a l in 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 ;

i s pragma P r i o r i t y ( C o n s t a n t s . TASK_PRIORITY) ; end BaseReader_task ; −−−−−−−−−−−−−−−−−−−−−−−−−−−− −− Methods o f t h e package −− −−−−−−−−−−−−−−−−−−−−−−−−−−−−

procedure g e t M e s s a g e ( s o c k e t : in 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

−−# s o c k e t from ; −−# d e c l a r e d e l a y ;

procedure s a v e R e c e p t i o n T i m e ;

−−# g l o b a l in 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 −− −−−−−−−−−−−−−−−−−−−−−−−−

baseReaderTask : BaseReader_task ; end BaseReader ;

Código Fonte B.13: Arquivo BaseReader.adb

with MsgChannel , Ada . Real_Time , BlackBoard ; with Ada . Text_IO , Ada . E x c e p t i o n s ;

package body BaseReader i s task body BaseReader_task i s

−− message r e c e i v e d from t h e Base S t a t i o n

r e c e i v e d M s g : DataTypes .MESSAGE := DataTypes . d e f a u l t M e s s a g e ; −− receivedMsg : DataTypes .MESSAGE := "$x1 . 0 0 y0 . 5 0 z0 . 3 0 t −1.0$

∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗" ;

−− s o c k e t t o r e c e i v e messages , not i n t h e formal s p e c i f i c a t i o n mySocket : UDP_Sockets . UDP_Socket ;

begin

−− C r e a t e 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 base 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 s a v e R e c e p t i o n T i m e ;

−− send i t through 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 BaseReader " ) ;

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 . Exception_Message ( E r r o r ) ) ; end BaseReader_task ;

−− w a i t f o r a message from t h e network

procedure g e t M e s s a g e ( s o c k e t : in out UDP_Sockets . UDP_Socket ; r e c e i v e d M s g : out DataTypes .MESSAGE) i s pragma I n l i n e ( g e t M e s s a g e ) ; begin UDP_Sockets . Receive_Message ( s o c k e t , r e c e i v e d M s g ) ; end g e t M e s s a g e ; −− 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

BlackBoard . 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 ;

end BaseReader ;

Código Fonte B.14: Arquivo BaseWriter.ads

with DataTypes , C o n s t a n t s , UDP_Sockets ; −−# i n h e r i t DataTypes ,

−−# Constants , −−# MsgChannel , −−# UDP_Sockets ;

package B a s e W r i t e r

−−# own t a s k baseWriterTask : BaseWriter_task ; i s

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− −− 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 in 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 &

−−# n u l l from MsgChannel . sensor_baseWriter_d ; −−# d e c l a r e Suspends => MsgChannel . sensor_baseWriter_d ;

i s 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 : in out UDP_Sockets . UDP_Socket ; msg : in DataTypes .MESSAGE) ;

−−# d e r i v e s s o c k e t from ∗ ,

Anexo B -- Códigos Fonte da Arquitetura de Controle 127 −−−−−−−−−−−−−−−−−−−−−−−− −− Task i n s t a n t i a t i o n −− −−−−−−−−−−−−−−−−−−−−−−−− b a s e W r i t e r T a s k : 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 ;

Código Fonte B.15: Arquivo BaseWriter.adb

with MsgChannel , Ada . Text_IO , Ada . E x c e p t i o n s ; package body B a s e W r i t e r i s

task body B a s e W r i t e r _ t a s k i s

−− message r e c e i v e d from t h e Base S t a t i o n

msgToSend : DataTypes .MESSAGE := DataTypes . d e f a u l t M e s s a g e ; −− s o c k e t t o r e c e i v e messages , not i n t h e formal s p e c i f i c a t i o n

mySocket : UDP_Sockets . UDP_Socket ; begin

−− C r e a t e and I n i t i a l i z e t h e s o c k e t UDP_Sockets . Create_Sender_Socket ( mySocket ,

C o n s t a n t s . BASEWRITER_IP, C o n s t a n t s .BASEWRITER_PORT) ; loop

−− r e c e i v e data from t h e i n p u t channel

MsgChannel . s e n s o r _ b a s e W r i t e r _ d . g e t ( msgToSend ) ; MsgChannel . s e n s o r _ b a s e W r i t e r _ s . p r o c e e d ; −− send t h e message t o t h e Base S t a t i o n

s e n d M e s s a g e ( mySocket , msgToSend ) ; −− −− 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 . Exception_Message ( E r r o r ) ) ; end B a s e W r i t e r _ t a s k ;

−− send a message over t h e network

procedure s e n d M e s s a g e ( s o c k e t : in out UDP_Sockets . UDP_Socket ; msg : in DataTypes .MESSAGE) i s pragma I n l i n e ( s e n d M e s s a g e ) ; begin UDP_Sockets . Send_Message ( s o c k e t , msg ) ; end s e n d M e s s a g e ; end B a s e W r i t e r ;

Código Fonte B.16: Arquivo BlackBoard.ads

with DataTypes , C o n s t a n t s , Ada . Real_Time ; −−# i n h e r i t DataTypes ,

−−# Constants , −−# Ada . Real_Time ;

−− Package used as a common r e g i o n f o r s h a r i n g s e n s o r and time −− i n f o r m a t i o n between t h e p r o c e s s e s o f t h e system .

package BlackBoard

−−# own p r o t e c t e d blckBoard : The_BlackBoard ( p r i o r i t y => Constants .CHANNEL_PRIORITY) ; i s

protected type The_BlackBoard i s

pragma P r i o r i t y ( C o n s t a n t s . CHANNEL_PRIORITY) ;

procedure s e t D i r e c t i o n ( r e a d i n g : in DataTypes .COMPASS_TYPE) ; −−# g l o b a l out The_BlackBoard ;

−−# d e r i v e s The_BlackBoard from r e a d i n g ;

procedure s e t D e p t h ( r e a d i n g : in DataTypes .ALTIMETER_TYPE) ; −−# g l o b a l out The_BlackBoard ;

−−# d e r i v e s The_BlackBoard from r e a d i n g ;

procedure s e t S o n a r ( r e a d i n g : in DataTypes .SONAR_TYPE) ; −−# g l o b a l out The_BlackBoard ;

−−# d e r i v e s The_BlackBoard from r e a d i n g ;

procedure g e t S o n a r ( r e a d i n g : out DataTypes .SONAR_TYPE) ; −−# g l o b a l in The_BlackBoard ;

−−# d e r i v e s r e a d i n g from The_BlackBoard ;

procedure g e t S e n s o r R e a d i n g s ( a l l R e a d i n g s : out DataTypes . S e n s o r D a t a ) ; −−# g l o b a l in The_BlackBoard ;

−−# d e r i v e s a l l R e a d i n g s from The_BlackBoard ;

procedure g e t R e c e p t i o n T i m e ( theTime : out Ada . Real_Time . Time ) ; −−# g l o b a l in The_BlackBoard ;

−−# d e r i v e s theTime from The_BlackBoard ;

procedure s e t R e c e p t i o n T i m e ( theTime : in Ada . Real_Time . Time ) ; −−# g l o b a l out The_BlackBoard ;

−−# d e r i v e s The_BlackBoard from theTime ; p r i v a t e

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 BlackBoard ;

Código Fonte B.17: Arquivo BlackBoard.adb

package body BlackBoard i s

protected body The_BlackBoard i s

procedure s e t D i r e c t i o n ( r e a d i n g : in DataTypes .COMPASS_TYPE) −−# g l o b a l out sensorReadings . d i r e c t i o n ; −−# d e r i v e s sensorReadings . d i r e c t i o n from r e a d i n g ; i s pragma I n l i n e ( s e t D i r e c t i o n ) ; begin s e n s o r R e a d i n g s . d i r e c t i o n := r e a d i n g ; end s e t D i r e c t i o n ;

procedure s e t D e p t h ( r e a d i n g : in DataTypes .ALTIMETER_TYPE) −−# g l o b a l out sensorReadings . d i r e c t i o n ; −−# d e r i v e s sensorReadings . d i r e c t i o n from r e a d i n g ; i s pragma I n l i n e ( s e t D e p t h ) ; begin s e n s o r R e a d i n g s . depth := r e a d i n g ; end s e t D e p t h ;

procedure s e t S o n a r ( r e a d i n g : in DataTypes .SONAR_TYPE) −−# g l o b a l out sensorReadings . d i r e c t i o n ; −−# d e r i v e s sensorReadings . d i r e c t i o n from r e a d i n g ; i s pragma I n l i n e ( s e t S o n a r ) ; begin s e n s o r R e a d i n g s . s o n a r := r e a d i n g ; end s e t S o n a r ;

procedure g e t S o n a r ( r e a d i n g : out DataTypes .SONAR_TYPE) −−# g l o b a l in sensorReadings . sonar ;

−−# d e r i v e s r e a d i n g from sensorReadings . sonar ; i s

pragma I n l i n e ( g e t S o n a r ) ; begin

r e a d i n g := s e n s o r R e a d i n g s . s o n a r ; end g e t S o n a r ;

procedure g e t S e n s o r R e a d i n g s ( a l l R e a d i n g s : out DataTypes . S e n s o r D a t a ) −−# g l o b a l in sensorReadings ; −−# d e r i v e s a l l R e a d i n g s from sensorReadings ; i s pragma I n l i n e ( g e t S e n s o r R e a d i n g s ) ; begin a l l R e a d i n g s := s e n s o r R e a d i n g s ; end g e t S e n s o r R e a d i n g s ;

procedure g e t R e c e p t i o n T i m e ( theTime : out Ada . Real_Time . Time ) −−# g l o b a l in receptionTime ;

−−# d e r i v e s theTime from receptionTime ; i s

begin

theTime := r e c e p t i o n T i m e ; end g e t R e c e p t i o n T i m e ;

procedure s e t R e c e p t i o n T i m e ( theTime : in Ada . Real_Time . Time ) −−# g l o b a l out receptionTime ;

−−# d e r i v e s receptionTime from theTime ; i s begin r e c e p t i o n T i m e := theTime ; end s e t R e c e p t i o n T i m e ; end The_BlackBoard ; end BlackBoard ;

Código Fonte B.18: Arquivo Compass.ads

with DataTypes , C o n s t a n t s ; −−# i n h e r i t DataTypes , −−# Constants , −−# BlackBoard ;

package Compass

−−# own t a s k compassTask : Compass_task ; i s

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− −− 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 ;

i s 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 ;

procedure s a v e D i r e c t i o n ( d i r e c t i o n : in DataTypes .COMPASS_TYPE) ; −−# g l o b a l out BlackBoard . blckBoard ;

Anexo B -- Códigos Fonte da Arquitetura de Controle 129 −−−−−−−−−−−−−−−−−−−−−−−− −− Task i n s t a n t i a t i o n −− −−−−−−−−−−−−−−−−−−−−−−−− compassTask : Compass_task ; end Compass ;

Código Fonte B.19: Arquivo Compass.adb

with Ada . Real_Time ; use type Ada . Real_Time . Time ; with BlackBoard ;

with Ada . Text_IO , Ada . E x c e p t i o n s ; package body Compass i s

task body Compass_task i s −− 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;

−− t i m e a t t i b u t e s ( o n l y f o r P e r i o d i c Processes )

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; −− t i m e method ( o n l y f o r P e r i o d i c Processes ) 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 g e t D i r e c t i o n ( d i r e c t i o n ) ; −− 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 a v e D i r e c t i o n ( 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 ; 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 . Exception_Message ( E r r o r ) ) ; end Compass_task ;

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) i s pragma I n l i n e ( g e t D i r e c t i o n ) ;

begin

d i r e c t i o n := 1 0 . 0 ; end g e t D i r e c t i o n ;

procedure s a v e D i r e c t i o n ( d i r e c t i o n : in DataTypes .COMPASS_TYPE) i s pragma I n l i n e ( s a v e D i r e c t i o n ) ;

begin

BlackBoard . b l c k B o a r d . s e t D i r e c t i o n ( d i r e c t i o n ) ; end s a v e D i r e c t i o n ;

end Compass ;

Código Fonte B.20: Arquivo ControlDataChannel.ads

with C o n s t a n t s , DataTypes ; −−# i n h e r i t Constants , −−# DataTypes ;

−− A c h a n n e l has two p r o t e c t e d o b j e c t s : Data and Sync . The Data p r o t e c t e d −− o b j e c t i s t h e data communicated through t h e channel . Sync i s a s y n c h r o n i z e r .

package C o n t r o l D a t a C h a n n e l

−−# own p r o t e c t e d s1_par_input_d : Data ( p r i o r i t y => Constants .CHANNEL_PRIORITY, −−# s u s p e n d a b l e ) ;

−−# p r o t e c t e d remote_s1_s : Sync ( p r i o r i t y => Constants .CHANNEL_PRIORITY, −−# s u s p e n d a b l e ) ;

−−# p r o t e c t e d s1_move_d : Data ( p r i o r i t y => Constants .CHANNEL_PRIORITY, −−# s u s p e n d a b l e ) ;

−−# p r o t e c t e d s1_move_s : Sync ( p r i o r i t y => Constants .CHANNEL_PRIORITY, −−# s u s p e n d a b l e ) ;

−−# p r o t e c t e d move_s2_s : Sync ( p r i o r i t y => Constants .CHANNEL_PRIORITY, −−# s u s p e n d a b l e ) ;

−−# p r o t e c t e d s2_par_input_d : Data ( p r i o r i t y => Constants .CHANNEL_PRIORITY, −−# s u s p e n d a b l e ) ;

−−# p r o t e c t e d stop_s2_s : Sync ( p r i o r i t y => Constants .CHANNEL_PRIORITY, −−# s u s p e n d a b l e ) ;

−−# p r o t e c t e d s2_actuator_d : Data ( p r i o r i t y => Constants .CHANNEL_PRIORITY, −−# s u s p e n d a b l e ) ;

−−# p r o t e c t e d s2_actuator_s : Sync ( p r i o r i t y => Constants .CHANNEL_PRIORITY, −−# s u s p e n d a b l e ) ;

i s

protected type Data i s

pragma P r i o r i t y ( C o n s t a n t s . CHANNEL_PRIORITY) ; entry g e t ( someData : out DataTypes . C o n t r o l D a t a ) ; −−# g l o b a l in out Data ;

−−# d e r i v e s Data ,

−−# someData from Data ;

procedure put ( someData : in DataTypes . C o n t r o l D a t a ) ; −−# g l o b a l in out Data ;

Anexo B -- Códigos Fonte da Arquitetura de Controle 130

−−# someData ;

p r i v a t e

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 ;

protected type Sync i s

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 in 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 in out Sync ; −−# d e r i v e s Sync from ∗ ; p r i v a t e 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 channels ( p a r a l l e l ) remote_s1_s : Sync ;

s1_move_d : Data ; s1_move_s : Sync ;

s2_par_input_d : Data ; −− data t o move and s t o p channels ( p a r a l l e l ) move_s2_s : Sync ;

stop_s2_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 ;

Código Fonte B.21: Arquivo ControlDataChannel.adb

package body C o n t r o l D a t a C h a n n e l i s protected body Data i s

entry g e t ( someData : out DataTypes . C o n t r o l D a t a ) when readyToRead −−# g l o b a l in chData ;

−−# out readyToRead ; −−# d e r i v e s readyToRead from & −−# someData from chData ;

i s begin −− Read t h e e n c a p s u l a t e d data someData := chData ; −− B l o c k 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 put ( someData : in DataTypes . C o n t r o l D a t a ) −−# g l o b a l out readyToRead ;

−−# out chData ;

−−# d e r i v e s readyToRead from & −−# chData from someData ;

i s begin −− Update t h e e n c a p s u l a t e d data chData := someData ; −− Permit f o r t h e n e x t w r i t i n g o p e r a t i o n readyToRead := True ; end put ; end Data ;

protected body Sync i s entry s t a y when hasRead −−# g l o b a l out hasRead ; −−# d e r i v e s hasRead from ; i s begin −− S t a y f o r t h e data t o be read hasRead := F a l s e ; end s t a y ; 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 ; i s begin −− D e c l a r e t h e completion 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 ;

Código Fonte B.22: Arquivo Decoder.ads

with DataTypes ; −−# i n h e r i t Datatypes ;

−− Package used t o decode t h e messages r e c e i v e d from t h e Base S t a t i o n . package Decoder −−# own endValue , −−# endMsg , −−# sensorId , −−# f i r s t I n d e x , −−# l a s t I n d e x ; −−# i n i t i a l i z e s endValue , −−# endMsg ,

Anexo B -- Códigos Fonte da Arquitetura de Controle 131

−−# sensorId , −−# f i r s t I n d e x , −−# l a s t I n d e x ;

i s

procedure c o n v e r t T o S t r u c t u r e ( msg : in DataTypes .MESSAGE; s t r : out DataTypes . C o n t r o l D a t a ) ; −−# g l o b a l in out s e n s o r I d ; −−# in out f i r s t I n d e x ; −−# out endMsg ; −−# out l a s t I n d e x ; −−# d e r i v e s endMsg , −−# s e n s o r I d from & −−# f i r s t I n d e x from s e n s o r I d & −−# l a s t I n d e x from f i r s t I n d e x & −−# s t r from msg ; p r i v a t e −− V a r i a b l e s used during 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 ; procedure s a v e S e n s o r V a l u e ( msg : in DataTypes .MESSAGE;

s t r : out DataTypes . C o n t r o l D a t a ) ; −−# g l o b a l in s e n s o r I d ;

−−# d e r i v e s s t r from sensorId ,

−−# msg ;

procedure g e t S e n s o r V a l u e ( msg : in DataTypes .MESSAGE; v a l u e : out DataTypes .SPEED_TYPE) ; −−# g l o b a l in f i r s t I n d e x ; −−# in out l a s t I n d e x ; −−# out endValue ; −−# out endMsg ; −−# out s e n s o r I d ; −−# d e r i v e s endValue ,

−−# endMsg from & −−# sensorId ,

−−# l a s t I n d e x from l a s t I n d e x & −−# v a l u e from f i r s t I n d e x , −−# l a s t I n d e x ,

−−# msg ;

f u n c t i o n extractNumber ( Item : DataTypes .MESSAGE; S i n c e : DataTypes . Message_Index ; To : DataTypes . Message_Index ) return DataTypes .SPEED_TYPE; end Decoder ;

Código Fonte B.23: Arquivo Decoder.adb

with Ada . C h a r a c t e r s . H a n d l i n g ; package body Decoder i s

procedure c o n v e r t T o S t r u c t u r e ( msg : in DataTypes .MESSAGE; s t r : out DataTypes . C o n t r o l D a t a ) i s pragma I n l i n e ( c o n v e r t T o S t r u c t u r e ) ; begin i f msg ( 1 ) = ’ $ ’ then endMsg := F a l s e ; s e n s o r I d := 2 ; loop f i r s t I n d e x := s e n s o r I d + 1 ; l a s t I n d e x := f i r s t I n d e x + 1 ; s a v e S e n s o r V a l u e ( msg , s t r ) ; e x i t when endMsg ; end loop; end i f; end c o n v e r t T o S t r u c t u r e ;

procedure s a v e S e n s o r V a l u e ( msg : in DataTypes .MESSAGE; s t r : out DataTypes . C o n t r o l D a t a ) i s pragma I n l i n e ( s a v e S e n s o r V a l u e ) ; begin ca s e msg ( s e n s o r I d ) i s when ’ x ’ => g e t S e n s o r V a l u e ( msg , s t r . vx ) ; when ’ y ’ => g e t S e n s o r V a l u e ( msg , s t r . vy ) ; when ’ z ’ => g e t S e n s o r V a l u e ( msg , s t r . vz ) ; when ’ t ’ => g e t S e n s o r V a l u e ( msg , s t r . vTheta ) ;

when o t h e r s => endMsg := True ; −− s t o p t h e l o o p and d i s c a r d t h e message end c a s e;

end s a v e S e n s o r V a l u e ;

procedure g e t S e n s o r V a l u e ( msg : in DataTypes .MESSAGE; v a l u e : out DataTypes .SPEED_TYPE) i s pragma I n l i n e ( g e t S e n s o r V a l u e ) ;

begin

endValue := F a l s e ; loop

i f msg ( l a s t I n d e x ) = ’ $ ’ then −− found t h e end o f t h e message endValue := True ; endMsg := True ; e l s e i f Ada . C h a r a c t e r s . H a n d l i n g . I s _ D i g i t ( msg ( l a s t I n d e x ) ) or msg ( l a s t I n d e x ) = ’ . ’ or msg ( l a s t I n d e x ) = ’− ’ then l a s t I n d e x := l a s t I n d e x + 1 ; e l s e endValue := True ; end i f; end i f; e x i t when endValue ; end loop; s e n s o r I d := l a s t I n d e x ; −− c o n v e r t e a s t r i n g indo de f i r s t I n d e x a t é l a s t I n d e x para F l o a t .

Anexo B -- Códigos Fonte da Arquitetura de Controle 132

v a l u e := Decoder . extractNumber ( msg , f i r s t I n d e x , l a s t I n d e x −1) ; 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 f u n c t i o n extractNumber ( 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 ( extractNumber ) ; r e s u l t : DataTypes .SPEED_TYPE; begin d e c l a r e subtype Str_Number i s S t r i n g ( 1 . . To − S i n c e + 1 ) ; begin

r e s u l t := F l o a t ’ Value ( Str_Number ( Item ( S i n c e . . To ) ) ) ;

−− c h e c k t h e c o n s i s t e n c y ( i n case o f e r r o r s , s e t z e r o f o r s a f e t y ) i f r e s u l t < DataTypes .SPEED_TYPE’ F i r s t or r e s u l t > DataTypes .SPEED_TYPE’ L a s t then r e s u l t := 0 . 0 ; end i f; return r e s u l t ; end; end extractNumber ; end Decoder ;

Código Fonte B.24: Arquivo Encoder.ads

with DataTypes ; −−# i n h e r i t DataTypes ;

−− Package t h a t encodes t h e SensorData and ActuationData i n t o a MESSAGE t y p e package Encoder i s

−− 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 : in 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 : in 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 ;

Código Fonte B.25: Arquivo Encoder.adb

with Ada . S t r i n g s . Bounded ; with Ada . S t r i n g s . F i x e d ; package body Encoder i s

package Bounded_Message i s new Ada . S t r i n g s . Bounded . Generic_Bounded_Length ( DataTypes . m s g S i z e ) ;

procedure s e n s o r T o M e s s a g e ( s t r u c t : in 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 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 . depth ) , 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 : in 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 ( 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

temp := Bounded_Message . Append ( temp , ’ o ’ ) ;

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 7 ) , Ada . S t r i n g s . Both ) ) ;

temp := Bounded_Message . Append ( temp , ’ p ’ ) ;

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 8 ) , 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 a c t u a t i o n T o M e s s a g e ; end Encoder ;

Código Fonte B.26: Arquivo Move.ads

with DataTypes , C o n s t a n t s ; use type DataTypes . STATUS ; −−# i n h e r i t DataTypes , −−# Constants ,

−−# ControlDataChannel , −−# StatusChannel ;

package Move

−−# own t a s k moveTask : Move_task ; i s

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− −− 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 in out ControlDataChannel . s1_move_d ; −−# in 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 &

−−# n u l l 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) ; i s 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 ; speedData : in DataTypes . C o n t r o l D a t a ; a v o i d D a t a : in out DataTypes . C o n t r o l D a t a ;

Documentos relacionados