• Nenhum resultado encontrado

Como dito na seção anterior, apesar dos resultados satisfatórios obtidos, há espaço para melhorias na plataforma HIL desenvolvida. A primeira melhoria, já comentada tam-bém na seção anterior, é implementar a simulação do modelo em tempo real. Esse tipo de simulação garante que tanto o modelo quanto o algoritmo de controle são executados no mesmo instante de tempo, tornando a simulação ainda mais precisa. Isso também diminui atrasos e questões de temporização que não permitem a simulação de sistemas com di-nâmicas extremamente rápidas, cuja simulação HIL, em seu estado atual, não produziria resultados satisfatórios.

A simulação em tempo real para o modelo pode ser implementada utilizando-se a toolbox Simulink Desktop Real-Time ou a toolbox Simulink Real-Time. A primeira utiliza

somente um computador para realizar a simulação em tempo real, enquanto a segunda toolbox implementa o modelo em tempo real utilizando dois computadores: um computa-dor host que cria um executável a partir do modelo no Simulink e um computadortarget, que recebe esse executável e executa o modelo em tempo real. A intenção era implementar essas metodologias ainda neste trabalho, mas devido a problemas de configuração e com-patibilidade dos sistemas de aquisição de dados utilizados, não foi possível implementar essa funcionalidade a tempo.

A implementação do algoritmo de controle em tempo real também não foi im-plementada neste trabalho, apesar de ser a intenção. A BeagleBone Black possui PRUs, que são processadores dedicados à execução em tempo real. Entretanto, eles são bastante complexos de serem utilizados, de forma que não foi possível implementar essa funciona-lidade antes do prazo final de entrega deste trabalho. A biblioteca libpruio auxilia nesse processo, fazendo com o tempo de execução do algoritmo de controle naBeagleBone Black não varie muito, mas como esse tempo não é fixo e preciso, não é possível considerar que a mesma esteja funcionando em tempo real.

A utilização de um módulo separado de RTC (sigla para Real Time Clock) pode ser uma boa alternativa para ser implementada no futuro, já que existem exemplos dis-poníveis de sua utilização não só para a BeagleBone Black. Além disso, é uma estratégia facilmente utilizável com outros microprocessadores/microcontroladores como Raspberry Pi e Arduino.

Outra funcionalidade que pode ser implementada no futuro é a utilização de con-versores A/D para converter saídas analógicas dos modelos a serem simulados em saídas digitais. Isso é interessante porque nem todos os microprocessadores possuem entradas analógicas como a BeagleBone Black, mas a grande maioria possui muitos GPIOs que podem ser usados como entradas ou saídas digitais. Isso traria ainda mais flexibilidade para a plataforma, pois poderiam ser utilizados ainda mais modelos de microprocessado-res como opções de hardwarepara embarcar algoritmos de controle, como a Raspberry Pi, por exemplo, que não possui pinos próprios para funcionarem como entradas analógicas.

Melhorias na interface da plataforma HIL com o usuário também podem ser im-plementadas. Neste trabalho, a interface se deu através de templates, que são o primeiro passo para a implementação de opções mais amigáveis para o usuário, como menus in-terativos, botões e outros recursos que tornem mais fácil a realização das simulações na plataforma.

Todas essas funcionalidades, se implementadas, possibilitarão não somente a si-mulação de mais modelos, de áreas de aplicação diversas, mas uma plataforma HIL ainda mais completa e capaz de produzir resultados ainda melhores. Isso não significa que a pla-taforma atual não apresente uma boa performance, mas com essas melhorias pode evoluir e tornar-se um projeto ainda mais completo.

Referências

AGHARKAKLI, A.; SABET, G. S.; BAROUZ, A. Simulation and analysis of passive and active suspension system using quarter car model for different road profile. International Journal of Engineering Trends and Technology, v. 3, n. 5, p. 636–644, 2012. Citado na página 72.

ALTER, D. M. Using PWM output as a digital-to-analog converter on a TMS320F280X digital signal controller. Texas Instruments, Dallas, TX, Application Report SPAA88, 2006. Citado 3 vezes nas páginas 15,58 e59.

ALTERA. Hardware in the Loop from the MATLAB/Simulink Environment. 2013.

<https://www.altera.com/en_US/pdfs/literature/wp/wp-01208-hardware-in-the-loop.

pdf>. Acesso em 24 de maio de 2015. Citado na página 27.

ANDERSON, O. A Design Tool (Research and Development) Simulator Survey Report.

[S.l.], 1962. Citado na página 33.

ANG, K. H.; CHONG, G.; LI, Y. PID control system analysis, design, and technology.

IEEE transactions on control systems technology, IEEE, v. 13, n. 4, p. 559–576, 2005.

Citado na página 69.

BADARUDDIN, K. S.; HERNANDEZ, J. C.; BROWN, J. M. The importance of Hardware-in-the-Loop testing to the cassini mission to saturn. In: IEEE. Aerospace Conference. [S.l.], 2007. p. 1–9. Citado 3 vezes nas páginas 34, 35e 38.

BEAGLEBOARD.ORG. BeagleBone Black. 2016. <https://beagleboard.org/black>.

Acesso em 12 de maio de 2016. Citado 2 vezes nas páginas 15 e52.

COMPUTING, M. PCI-DAS6013 and PCI-DAS6014 User’s Guide. 2009. Citado na página 49.

DROSDOL, J.; KADING, W.; PANIK, F. The Daimler-Benz driving simulator. Vehicle System Dynamics, Taylor & Francis, v. 14, n. 1-3, p. 86–90, 1985. Citado na página 33.

DSPACE. Application Fields. 2015. <http://www.dspace.com/en/inc/home/

applicationfields/stories.cfm#filterterms=term-133>. Acesso em 24 de março de 2015.

Citado 2 vezes nas páginas 29 e38.

FAHAMI, S. M. H.; ZAMZURI, H.; MAZLAN, S. A. Development of Estimation Force Feedback Torque Control Algorithm for Driver Steering Feel in Vehicle Steer by Wire System: Hardware in the Loop. International Journal of Vehicular Technology, Hindawi Publishing Corporation, v. 2015, 2015. Citado 2 vezes nas páginas 16e 75.

FREEBASIC. Libpruio: Features. 2016. <http://users.freebasic-portal.de/tjf/Projekte/

libpruio/doc/html/_cha_features.html>. Acesso em 02 de maio de 2016. Citado na página 53.

HANSELMANN, H. Hardware-in-the Loop simulation as a standard approach for development, customization, and production test of ECU’s. [S.l.], 1993. Citado na página 34.

96 Referências

HOSSEINPOUR, F.; HAJIHOSSEINI, H. Importance of simulation in manufacturing.

World Academy of Science, Engineering and Technology, v. 51, p. 285–288, 2009. Citado na página 27.

HUBER, W.; JONNER, W.-D.; DEMEL, H. Simulation, performance and quality evaluation of ABS and ASR. [S.l.], 1988. Citado na página 34.

INSTRUMENTS, N.Explicando a teoria PID. 2013.<http://www.ni.com/white-paper/

3782/pt/>. Acesso em 22 de maio de 2016. Citado 2 vezes nas páginas 16e 69.

ISERMANN, R.; SCHAFFNIT, J.; SINSEL, S. Hardware-in-the-Loop simulation for the design and testing of engine-control systems.Control Engineering Practice, Elsevier, v. 7, n. 5, p. 643–653, 1999. Citado 9 vezes nas páginas 15, 28,29, 33, 34,35, 36, 42e 43.

LOCKHART, R. W. What You Really Need to Know About Sample Rate.

2016. <http://www.dataq.com/data-acquisition/general-education-tutorials/

what-you-really-need-to-know-about-sample-rate.html/>. Acesso em 12 de maio de 2016. Citado 2 vezes nas páginas42 e70.

LU, B. et al. A low-cost real-time Hardware-in-the-Loop testing approach of power electronics controls. IEEE Transactions on Industrial Electronics, IEEE, v. 54, n. 2, p.

919–931, 2007. Citado 3 vezes nas páginas27, 28e 34.

MOLLOY, D. Exploring BeagleBone: Tools and Techniques for Building with Embedded Linux. [S.l.]: John Wiley & Sons, 2014. Citado na página 53.

NI. Projeto e teste de ECUs com os produtos da National Instruments. 2012.

<http://www.ni.com/white-paper/3312/pt/>. Acesso em 07 de junho de 2015. Citado 3 vezes nas páginas15,27 e28.

OGATA, K.; MAYA, P. Á.; LEONARDI, F.Engenharia de controle moderno. [S.l.]: 4a edição, Pearson Prentice Hall, 2003. Citado 2 vezes nas páginas16 e73.

OHRI, J. et al. GA tuned LQR and PID controller for aircraft pitch control. In: IEEE.

2014 IEEE 6th India International Conference on Power Electronics (IICPE). [S.l.], 2014. p. 1–6. Citado na página74.

PALLADINO, A.; FIENGO, G.; LANZO, D. A portable Hardware-in-the-Loop (HIL) device for automotive diagnostic control systems. ISA transactions, Elsevier, v. 51, n. 1, p. 229–236, 2012. Citado 3 vezes nas páginas 15, 34 e37.

PIZETTA, I. H. et al. Uma plataforma hardware-in-the-loop para vants de asas rotativas.

In:Anais do XIX Congresso Brasileiro de Automática, SBA, Campina Grande, PB. [S.l.:

s.n.], 2012. p. 3565–3570. Citado 2 vezes nas páginas15 e 41.

SANTOS, S. R. B. d.; OLIVEIRA, N. M. F. D. Longitudinal autopilot controllers test platform Hardware in the Loop. In: IEEE. Systems Conference (SysCon), 2011 IEEE International. [S.l.], 2011. p. 379–386. Citado 3 vezes nas páginas 15, 39e 40.

SILVA, H. M. d. Simulação com Hardware in the Loop aplicada a veículos submarinos semi-autônomos. Tese (Doutorado) — Universidade de São Paulo, 2008. Citado 3 vezes nas páginas15, 36e 40.

SOUSA, D. F.; ÁVILA, S. Suspensão ativa utilizando controle PID em um modelo de 1/4 de veículo. In: ECT. VII Encontro de Ciência e Tecnologia do Campus UnB Gama.

[S.l.], 2015. Citado 2 vezes nas páginas 19e 75.

THOREN, M.; STEWARD, C. Accurate, Fast Settling Analog Voltages from Digital PWM Signals. [S.l.], 2015. Citado na página58.

WALTER, S. Technical Proposal v1.0 for Universidade de Brasilia (UnB) - Generic SCALEXIO HIL System. [S.l.], 2014. Citado 2 vezes nas páginas 15 e38.

ANEXO A – Hil setup.m

1 %% h i l _ s e t u p .m

2

3 % Author : Alceu B e r n a r d e s C a s t a n h e i r a de F a r i a s

4

5 % This f i l e has t h e main o b j e c t i v e o f a d a p t i n g t h e model_template . s l x f i l e

6 % t o t h e c h a r a c t e r i s t i c s o f t h e model t o be s i m u l a t e d . J u s t w r i t e t h e needed

7 % i n f o r m a t i o n and e x e c u t e t h i s s c r i p t b e f o r e s i m u l a t i n g .

8

9 c l c ; c l e a r a l l

10 %% System O p e r a t i o n Ranges

11

12 % Mininum v a l u e f o r a l l system i n p u t s . I f you wish t o u s e a d i f f e r e n t r a n g e

13 % f o r each i n p u t , change in_min f o r in_x_min on model_template . s l x , where x

14 % c o r r e s p o n d s t o t h e d e s i r e d i n p u t .

15 in_min = 0 . 0 0 ;

16

17 % Max v a l u e f o r a l l system i n p u t s . I f you wish t o u s e a d i f f e r e n t r a n g e

18 % f o r each i n p u t , change in_max f o r in_x_max on model_template . s l x , where x

19 % c o r r e s p o n d s t o t h e d e s i r e d i n p u t .

20 in_max = 0 . 0 0 ;

21

22 % I n p u t 1 minimum and max v a l u e s

23 in_1_min = 0 . 0 0 ;

24 in_1_max = 2 . 0 0 ;

25

26 % Mininum v a l u e f o r a l l system o u t p u t s . I f you wish t o u s e a d i f f e r e n t r a n g e

27 % f o r each i n p u t , change out_min f o r out_x_min on model_template . s l x , where x

102 ANEXO A. Hil setup.m

28 % c o r r e s p o n d s t o t h e d e s i r e d o u t p u t .

29 out_min = 0 . 0 0 ;

30

31 % Max v a l u e f o r a l l system i n p u t s . I f you wish t o u s e a d i f f e r e n t r a n g e

32 % f o r each i n p u t , change out_max f o r out_x_max on model_template . s l x , where x

33 % c o r r e s p o n d s t o t h e d e s i r e d o u t p u t .

34 out_max = 0 . 0 0 ;

35

36 % Output 1 minimum and max v a l u e s

37 out_1_min = 0 . 0 0 ;

38 out_1_max = 2 . 0 0 ;

39

40 % Output 2 minimum and max v a l u e s

41 out_2_min = 0 . 0 0 ;

42 out_2_max = 2 . 0 0 ;

43

44 % Output 3 minimum and max v a l u e s

45 out_3_min = 0 . 0 0 ;

46 out_3_max = 1 0 . 0 0 ;

47

48 % Output 4 minimum and max v a l u e s

49 out_4_min = 0 . 0 0 ;

50 out_4_max = 2 0 . 0 0 ;

51

52 %% System P a r a m e t e r s

53

54 % V a r i a b l e s needed f o r s i m u l a t i n g t h e d e s i r e d model

55

56 % System Data

57 m1 = 2 6 ;

58 m2 = 2 0 3 ;

59 k1 = 2 0 0 0 0 0 ;

60 k2 = 2 0 0 0 0 ;

61 c = 1 5 0 0 ;

62

63 % Sampling time

64 Ts = 0 . 0 1 ;

65

66 % Number o f b i t s f o r r e p r e s e n t i n g t h e c o n t r o l v a r i a b l e

67 r e s = 9 ;

68

69 % System model : c o n t i n u o u s

70 A=[0 0 1 0 ; 0 0 0 1 ; −k2 /m2 k2 /m2 −c /m2 c /m2 ; k2 /m1 (−k2

−k1 ) /m1 c /m1 −c /m1 ] ;

71 B = [ 0 ; 0 ; 0 ; k1 /m1 ] ;

72 C=e y e( 4 ) ;

73 D=z e r o s( 4 , 1 ) ;

74

75 % System d i s c r e t i z a t i o n

76 s i s t _ c=s s (A, B, C,D) ;

77 s i s t _ d=c2d ( s i s t _ c , Ts ) ;

78 Ad=s i s t _ d . a ; Bd=s i s t _ d . b ; Cd=s i s t _ d . c ; Dd=s i s t _ d . d ;

79

80 % D i s c r e t e LQR g a i n c a l c u l a t i o n

81 Q=d i a g( [ 1 0 0 1 1 1 ] ) ; % S t a t e s Weightning

82 R=1; % Command Weightning

83 klqr_d=d l q r (Ad , Bd , Q, R) ; % Gain c a l c u l a t i o n

ANEXO B – Control template.c

1 /* Template f o r d e v e l o p i n g c o n t r o l a l g o r i t h m s

2 i n C f o r BeagleBone Black /*

3

4 Author : Alceu B e r n a r d e s C a s t a n h e i r a de F a r i a s

5

6 This t e m p l a t e u s e s l i b p r u i o l i b r a r y , from FREEBASIC :

7

8 L i c e n c e : GPLv3

9 C o p y r i g h t 2014 by Thomas{ dOt ] F r e i h e r r [ At ] gmx [ DoT } n e t

10

11 For more i n f o r m a t i o n on l i b p r u i o , a c e s s t h e p r o j e c t w e b s i t e :

12 h t t p : / / u s e r s . f r e e b a s i c−p o r t a l . de / t j f / P r o j e k t e / l i b p r u i o / doc / html /

13 i n d e x . html

14

15 Compile t h e problem u s i n g : g c c −Wall −o executable_name

16 c o n t r o l _ t e m p l a t e . c −l p r u i o .

17 */

18

19 // I n c l u d e l i b r a r i e s . DO NOT DELETE ANY LIBRARY FROM THIS SECTION . You may i n c l u d e a d d i t i o n a l o n e s .

20 #i n c l u d e " s t d i o . h "

21 #i n c l u d e " s t d l i b . h "

22 #i n c l u d e " math . h "

23 #i n c l u d e " s t r i n g . h "

24 #i n c l u d e " tim e . h "

25 #i n c l u d e " s y s / ti me . h "

26 #i n c l u d e " . . / c_wrapper / p r u i o . h " // i n c l u d e h e a d e r

27 #i n c l u d e <t e r m i o s . h>

28 #i n c l u d e <u n i s t d . h>

29 #i n c l u d e <e r r n o . h>

30 #i n c l u d e " . . / c_wrapper / p r u i o _ p i n s . h "

31 #i n c l u d e " f p 2 b i n . h "

32

33 /* System o p e r a t i o n r a n g e s d e f i n i t i o n . */

34

106 ANEXO B. Control template.c

35 // Modify them t o be c o m p a t i b l e with t h e same o p e r a t i o n r a n g e s d e f i n e d on S i m u l i n k .

36 #d e f i n e IN_1_MIN 0

37 #d e f i n e IN_1_MAX 2000

38 #d e f i n e IN_2_MIN 0

39 #d e f i n e IN_2_MAX 2000

40 #d e f i n e IN_3_MIN 0

41 #d e f i n e IN_3_MAX 10000

42 #d e f i n e IN_4_MIN 0

43 #d e f i n e IN_4_MAX 20000

44 #d e f i n e OUT_1_MIN 0

45 #d e f i n e OUT_1_MAX 2 . 0

46

47 /* VARIABLE DECLARATION */

48

49 // DO NOT ALTER THE VARIABLES BELOW

50

51 // P o i n t e r f o r w r i t i n g on BeagleBone Black f i l e s t h a t c o r r e s p o n d t o i t s GPIOs .

52 FILE *f p ;

53

54 // S t r i n g t h a t s t o r e s t h e c o n t r o l v a r i a b l e i n b i n a r y .

55 c h a r b i n S t r i n g [ 9 ] ;

56

57 // V a r i a b l e s t h a t s t o r e e ach b i t from t h e c o n t r o l v a r i a b l e i n b i n a r y .

58 c h a r bit_8 ;

59 c h a r bit_7 ;

60 c h a r bit_6 ;

61 c h a r bit_5 ;

62 c h a r bit_4 ;

63 c h a r bit_3 ;

64 c h a r bit_2 ;

65 c h a r bit_1 ;

66 c h a r bit_0 ;

67

68 // V a r i a b l e s t h a t s t o r e t h e v a l u e t o be w r i t t e n on t h e c o r r e s p o n d e n t GPIOs .

69 i n t gpio_11 ;

70 i n t gpio_12 ;

71 i n t gpio_7 ;

72 i n t gpio_8 ;

73 i n t gpio_9 ;

74 i n t gpio_10 ;

75 i n t gpio_15 ;

76 i n t gpio_16 ;

77 i n t gpio_17 ;

78

79 // V a r i a b l e s f o r r e a d i n g BeagleBone Black . a n a l o g c h a n n e l s

80 i n t a0 , a1 , a2 , a3 ;

81

82 // V a r i a b l e s f o r s t o r i n g v a l u e s r e a d from BeagleBone Black a n a l o g c h a n n e l s i n f l o a r f o r m a t .

83 f l o a t a 0 f , a 1 f , a 2 f , a 3 f ;

84

85 // Enable f o r r e a d i n g c o n t r o l v a r i a b l e on S i m u l i n k .

86 i n t e n a b l e ;

87

88 // C o n t r o l v a r i a b l e .

89 d o u b l e u = 0 ;

90

91 // V a r i a b l e t h a t s t o r e t h e c o n t r o l v a r i a b l e v a l u e i n d i g i t a l form .

92 i n t u_out = 0 ;

93

94 /* Add h e r e t h e v a r i a b l e s needed f o r your c o n t r o l a l g o r i t h m .

95 DO NOT ALTER THE VARIABLES ABOVE, u n l e s s you want t o change t h e number o r t h e GPIOs used .*/

96

97 /* FUNCTIONS*/

98

99 // DO NOT ALTER THE FUNCTIONS BELOW.

100

101 // F u n c t i o n t o c o n v e r t one r a n g e o f o p e r a t i o n i n t o a n o t h e r .

102 i n t mapRange (i n t x , i n t in_min , i n t in_max , i n t out_min , i n t out_max ) {

103 r e t u r n ( x − in_min )*( out_max − out_min ) / ( in_max − in_min ) + out_min ;

108 ANEXO B. Control template.c

104 }

105

106 // F u n c t i o n t o t r a n s f o r m an a n a l o g v a l u e i n t o a d i g i t a l one .

107 i n t adc (f l o a t x , f l o a t in_min , f l o a t in_max , i n t out_min , i n t out_max ) {

108 r e t u r n ( x − in_min )*( out_max − out_min ) / ( in_max − in_min ) + out_min ;

109 }

110

111 // F u n c t i o n t o c o n v e r t an i n t v a r i a b l e i n t o a b i n a r y s t r i n g .

112 v o i d i n t 2 b i n (i n t a , c h a r *b i n S t r i n g ) {

113

114 i n t i = 1 ;

115 i n t b i n a r y I n t = 0 ;

116

117 w h i l e( a >0)

118 {

119 b i n a r y I n t = b i n a r y I n t + a % 2 * i ;

120 i = i * 1 0 ;

121 a = a / 2 ;

122 }

123

124 s p r i n t f ( b i n S t r i n g , " %09d " , b i n a r y I n t ) ;

125 }

126

127 /* Add h e r e your c o n t r o l a l g o r i t h m f u n c t i o n s . DO ALTER THE ONES ABOVE. */

128

129 /* MAIN FUNCTION */

130 i n t main (i n t a r g c , c h a r **a r g v )

131 {

132

133 // D r i v e r s t r u c t u r e c o n s t r u c t i o n f o r u s i n g l i b p r u i o . DO NOT ALTER.

134 p r u I o *i o = pruio_new (PRUIO_DEF_ACTIVE, 0 x98 , 0 , 1 ) ;

135 i f ( p r u i o _ c o n f i g ( i o , 1 , 0x1FE , 0 , 4 ) ) {

136 p r i n t f (" c o n f i g f a i l e d (% s ) \n " , i o−>E r r r ) ; }

137 e l s e {

138

139 w h i l e( 1 ) {

140

141 // R e s e t c o n t r o l v a r i a b l e r e a d i n g e n a b l e . DO NOT ALTER.

142 e n a b l e = 0 ;

143

144 // W r i t i n g e n a b l e i n t o t h e c o r r e s p o n d i n g GPIO . DO NOT ALTER.

145 f p = f o p e n (" / s y s / c l a s s / g p i o / g p i o 6 5 / v a l u e ", "w") ;

146 f p r i n t f ( fp , "%d " , e n a b l e ) ;

147 f c l o s e ( f p ) ;

148

149 // Read a n a l o g i n p u t s from BeagleBone Black . A l r e a d y c o n f i g u r e d t o c o n v e r t t h e vaue r e a d i n t o t h e

o p e r a t i o n r a n g e s d e f i n e d on t h e system o p e r a t i o n r a n g e s s e c t i o n . I n p u t s may be i n c l u d e d o r removed , a s l o n g a s t h e s t r u c t u r e below i s m a i n t a i n e d .

150

151 // Read AIN0 and c o n v e r t i t t o t h e i n p u t o p e r a t i o n r a n g e .

152 a0 = i o−>Adc−>Value [ 1 ] ;

153 a0 = mapRange ( a0 , 0 , 6 5 5 2 0 , 0 , 1 8 0 0 ) ;

154 a0 = mapRange ( a0 , 0 , 1 8 0 0 , IN_1_MIN , IN_1_MAX) ;

155 a 0 f = (f l o a t) a0 / 1 0 0 0 . 0 0 ;

156 p r i n t f ("%f \n ", a 0 f ) ;

157

158 // Read AIN1 and c o n v e r t i t t o t h e i n p u t o p e r a t i o n r a n g e .

159 a1 = i o−>Adc−>Value [ 2 ] ;

160 a1 = mapRange ( a1 , 0 , 6 5 5 2 0 , 0 , 1 8 0 0 ) ;

161 a1 = mapRange ( a1 , 0 , 1 8 0 0 , IN_2_MIN , IN_2_MAX) ;

162 a 1 f = (f l o a t) a1 / 1 0 0 0 . 0 0 ;

163

164 // Read AIN2 and c o n v e r t i t t o t h e i n p u t o p e r a t i o n r a n g e .

165 a2 = i o−>Adc−>Value [ 3 ] ;

166 a2 = mapRange ( a2 , 0 , 6 5 5 2 0 , 0 , 1 8 0 0 ) ;

167 a2 = mapRange ( a2 , 0 , 1 8 0 0 , IN_3_MIN , IN_3_MAX) ;

168 a 2 f = (f l o a t) a2 / 1 0 0 0 . 0 0 ;

169

110 ANEXO B. Control template.c

170 // Read AIN3 and c o n v e r t i t t o t h e i n p u t o p e r a t i o n r a n g e .

171 a3 = i o−>Adc−>Value [ 4 ] ;

172 a3 = mapRange ( a3 , 0 , 6 5 5 2 0 , 0 , 1 8 0 0 ) ;

173 a3 = mapRange ( a3 , 0 , 1 8 0 0 , IN_4_MIN , IN_4_MAX) ;

174 a 3 f = (f l o a t) a3 / 1 0 0 0 . 0 0 ;

175

176 /* I n s e r t your c o n t r o l e q u a t i o n h e r e . Name your c o n t r o l v a r i a b l e u . */

177

178 // Convert c o n t r o l v a r i a b l e i n t o a d i g i t a l v a l u e . A l t e r o n l y i f you wish t o change t h e number o f b i t s t o be used .

179 u_out = adc ( u , OUT_1_MIN, OUT_1_MAX, 0 , 5 1 1 ) ;

180

181 // Trasform c o n t r o l v a r i a b l e i n t o b i n a r y . DO NOT ALTER.

182 i n t 2 b i n ( u_out , b i n S t r i n g ) ;

183

184 /* A s s o c i a t e e ach b i t from t h e b i n a r y c o n t r o l v a r i a b l e t o a GPIO .

185 Only a l t e r i f a d i f f e r e n t number o f b i t s w i l l be used o r i f you

186 wish t o a s s i g n d i f f e r e n t GPIOS . Check BeagleBone Black h e a d e r

187 i n o r d e r t o g e t t h e c o r r e c t number f o r t h e d e s i r e d GPIOs . */

188

189 // A s s o c i a t e e ach b i t wit h a c h a r v a r i a b l e*/

190 bit_8 = b i n S t r i n g [ 0 ] ;

191 bit_7 = b i n S t r i n g [ 1 ] ;

192 bit_6 = b i n S t r i n g [ 2 ] ;

193 bit_5 = b i n S t r i n g [ 3 ] ;

194 bit_4 = b i n S t r i n g [ 4 ] ;

195 bit_3 = b i n S t r i n g [ 5 ] ;

196 bit_2 = b i n S t r i n g [ 6 ] ;

197 bit_1 = b i n S t r i n g [ 7 ] ;

198 bit_0 = b i n S t r i n g [ 8 ] ;

199

200 // Turn each c h a r v a r i a b l e i n t o i n t */

201 gpio_11 = bit_8 − ’ 0 ’;

202 gpio_12 = bit_7 − ’ 0 ’;

203 gpio_7 = bit_6 − ’ 0 ’;

204 gpio_8 = bit_5 − ’ 0 ’;

205 gpio_9 = bit_4 − ’ 0 ’;

206 gpio_10 = bit_3 −’ 0 ’;

207 gpio_15 = bit_2 − ’ 0 ’;

208 gpio_16 = bit_1 − ’ 0 ’;

209 gpio_17 = bit_0 − ’ 0 ’;

210

211 // Write e ach i n t v a r i a b l e t o i t s c o r r e s p o n d e n t GPIO .

212 f p = f o p e n (" / s y s / c l a s s / g p i o / g p i o 2 7 / v a l u e ", "w") ;

213 f p r i n t f ( fp , "%d " , gpio_17 ) ;

214 f c l o s e ( f p ) ;

215

216 f p = f o p e n (" / s y s / c l a s s / g p i o / g p i o 4 6 / v a l u e ", "w") ;

217 f p r i n t f ( fp , "%d " , gpio_16 ) ;

218 f c l o s e ( f p ) ;

219

220 f p = f o p e n (" / s y s / c l a s s / g p i o / g p i o 4 7 / v a l u e ", "w") ;

221 f p r i n t f ( fp , "%d " , gpio_15 ) ;

222 f c l o s e ( f p ) ;

223

224 f p = f o p e n (" / s y s / c l a s s / g p i o / g p i o 6 8 / v a l u e ", "w") ;

225 f p r i n t f ( fp , "%d " , gpio_10 ) ;

226 f c l o s e ( f p ) ;

227

228 f p = f o p e n (" / s y s / c l a s s / g p i o / g p i o 6 9 / v a l u e ", "w") ;

229 f p r i n t f ( fp , "%d " , gpio_9 ) ;

230 f c l o s e ( f p ) ;

231

232 f p = f o p e n (" / s y s / c l a s s / g p i o / g p i o 6 7 / v a l u e ", "w") ;

233 f p r i n t f ( fp , "%d " , gpio_8 ) ;

234 f c l o s e ( f p ) ;

235

236 f p = f o p e n (" / s y s / c l a s s / g p i o / g p i o 6 6 / v a l u e ", "w") ;

237 f p r i n t f ( fp , "%d " , gpio_7 ) ;

238 f c l o s e ( f p ) ;

239

Documentos relacionados