5
661 Proceedings of the 26 th Chinese Control Conference July 26-31, 2007, Zhangjiajie, Hunan, China MATLAB CAN * 150001 E-mail: [email protected] [email protected] MATLAB CAN Simulation Technique of In-vehicle CAN Network Based on MATLAB Xu Xiaojuan, Liu Zhiyuan Harbin Institute of Technology, Harbin 150001, P. R. China E-mail: [email protected] E-mail: [email protected] Abstract: Network simulation system is a development platform for the design and evaluation of the In-vehicle network. In this paper, the requirement of network simulation system is proposed and a technique for CAN network simulation system based on MATLAB is presented. This technique not only can effectively implement the function and performance simulation of each network node, but also can simulate various network topologies and messages of vehicles. Experiment results are given to verify that the simulation technique proposed in this paper is feasible and effective. Key Words: CAN, Simulation system of in-vehicle network, Real-Time Workshop 1 (Introduction) 1 B CAN ; CAN MOST A LIN CAN * , GB05A101-1 2 (Structure of In-vehicle Network Simulation System) SAE ABC 1 CANLIN MOST CAN 1

[IEEE 2007 Chinese Control Conference - Zhangjiajie, China (2007.07.26-2007.06.31)] 2007 Chinese Control Conference - Simulation Technique of In-vehicle CAN Network Based on MATLAB

  • Upload
    liu

  • View
    212

  • Download
    0

Embed Size (px)

Citation preview

661

Proceedings of the 26th Chinese Control ConferenceJuly 26-31, 2007, Zhangjiajie, Hunan, China

�� MATLAB ��� CAN ����*

�������

����������� ����� 150001E-mail: [email protected]

[email protected]

� ����������������������� !�"#$%&'(���������)+,-./0�

12.3456 MATLAB � CAN �������789:%;9:�<=>?��@A�B�C�����D<EFGHIJ�KL�M�NA�OPQRS�T��UVC��WX���%7YUZ[\�&']2�9:�O

-�<=�%

����^_`�����������7a�� !b�

Simulation Technique of In-vehicle CAN NetworkBased on MATLAB

Xu Xiaojuan, Liu ZhiyuanHarbin Institute of Technology, Harbin 150001, P. R. China

E-mail: [email protected]: [email protected]

Abstract: Network simulation system is a development platform for the design and evaluation of the In-vehicle network. Inthis paper, the requirement of network simulation system is proposed and a technique for CAN network simulation systembased on MATLAB is presented. This technique not only can effectively implement the function and performance simulationof each network node, but also can simulate various network topologies and messages of vehicles. Experiment results aregiven to verify that the simulation technique proposed in this paper is feasible and effective.KeyWords: CAN, Simulation system of in-vehicle network, Real-Time Workshop

1 � (Introduction)1

�����R���������������� ����K�R�1��Sa���������������CO����Y%���

�� ��C !���(����,-�������� !��) !%��������"�#KL������,-�5$��%�&����� ��C !���1'�()����B��������������#���"*��������1' !�"#$%

���������+),-.��C�K���CWX/0��123�4/56�&7-.����K���, B8�V6�9:; CAN<=78;WX/0��, CAN>MOST��56%#?@6&�9:���7��AB A 8���CD LIN ��%EF���������7G�1 CAN ��#HI�CPQ� WXJK)+�C�()7L� JKN��������#$%

,6�������UV�@AWXJK)+��TMN�EF������L�KLRS�T��UVC��WXJK���)+%&'��%"�56O4)+P ��;������QR�789

:�PQ���ST�T�������)+�U�

* FV�%WXYZ[\�A�Q]N�^V�_`,V�a���GB05A101-1%

KL��T� !������������1�34�9:%

2 �� ������� (Structure ofIn-vehicle Network Simulation System)

�������UV�����T ���<�

3���%��V�9��78�B�����)�

SAE������� A�B�C����� !��"#78��WX$%�&'%�()�����

�����V�N*O+,�� 1�����UV%�����)� CANCLIN � MOST��78%���T���UV !���O-CAN ���6����%

� 1 ���� ��

662

��������L;./7����N���

�,-� 1����UV�����L78��B�:� �����-a��4��WX

� ������WX� �

� ��7���O�28�����

� �������������!�

� ����O�28���%

56��)+���������UV�� 2��[1]%�����������/�6�����

��-� !�"#$!�%����W)+�W

X��� dSPACE7a&'��� ()����T78��(*��7a�+*,.-.7����W

X; �������6����������WX���.���!��"�0/��01��7�

�2-�V���@A#�; ��$3���6����O�28��4�����$3C%&45�

651�4 !; �'�678RS�9���78��WX:;�<=%

� 2 � �������

@A���������78�1)2>��7

8��?@�B�����L�787���O�2

8��������@A78CAB1 !���%

'[2]C���&'�� OPENET 78��@A�&'��DEF CAN @A�L�G�T� MAC G, �T78 CAN @A��%(49:78HI�KL��M�JKR�787���@A�����%

Sa��T�7���L�MNO�O&'UZP:

.-7���� !%'[3]O�IQ�)�R VE

.O,-*@AGH��������+9:78�

&,�JS)-.T�@A� G?@/-.@AW

X� 78��@A����a��� !���

�� !����L�� %

�<=>?��@A�B�C�����78�

��0��&'(56MATLAB�����@A��9:,-.��%/0.56MATLAB78��@A���O-��789�%&'��@(�9:

,-.����%

3 ��MATLAB�CAN������(CANNetwork Node Simulation Technique Basedon MATLAB)

56 MATLAB � CAN @A�����5&��� !"+#MATLAB /Simulinkb$%EF��N����&:',-('�SaU�)*+�1V

GH�W , CAN �W�'-)*+� G./0U��(L�@A1�2D RTW(Real-Time workshop)X Simulink �T13�O#)*+�4�1V%5-�67�82D93Y8�-O:-67%��1

V;1�X478��@A���%,���� 3��%

� 3 CAN���������

56 MATLAB � CAN @A������4� �� RTW ��� �GH� !�

Simulinkb�����N���&:�78%�6 �GH�D�� MCU ����&'� Freescale �HC12 �� MCU ����� �GH� !9:�Sa��@AWX����N���&:�78%

3.1 RTW �!"#$%&�'()* (Develop-

ment of Custom Target in RTW)

�MATLAB� Simulink !�[�O�"#5<G< HC12��$=%�&/ �GH�',2G6( 7�WR)F�*< CAN 2G6(�W%+,�56MATLAB78 HC12 CAN@A���-)�.�� MATLAB �8/ CAN 2G6( 7�W�012# Simulink� HC12� !3>0�%�456�78� MATLAB�/9 HC12�2G6( 7�W�9:%

RTW ��.� �� 4 �����6� 7��� )���� 4 ����� sfunc.c(�9S ��6:'�)��9����� TLC '�sfunc.tlc�������� sfun.dll'����%

663

� 4 RTW+,-.

3.1.1 � S ��������� (Writing De-

vice Driver C-MEX S-Function Files)

�9S��'��678S��API��;��� C MEX S��6:��;��� Simulink���a���6:��R�(��4�b ����!"

`,-#�$�%%6�66� 7��� S��&'78()�$��+,*78+ ,(-.%

�;$�/?:� 3:0 SimStruct UV����121234����<a56�78

� 78���+ �=MATLAB�@������L�WX���� � ���

��WX7�

� ���9Y�����(���1���

��

� � �!12�"#:$%&'(�

� E� mdlRTW)�' model.rtw>*�+%

� 5 �/ S0123�456.

�!� S)�6,�?-� �- 5.�[4]�/

+�T�B�RS�01�E�- 5��23)��!78�L�B��4O5+6)7�+�L�B�

)�78�L�B�%

3.1.2 TLC ����� (Writing TLC Inlining Files)TLC '8�678 S )� API �.6)��7

a6,�9):��;<=@��3�7A��:6

,�(48,->A%�!� TLC '8O ?�!3��@A 79�#�T3��B�6,�%TLC'8�56>B?-�;C�<-;DEFA&�=

�?-%

���!� TLC '89)�G4CT��!)��E��?-3:H�)��3�O?-6,;

D�)���[ 1.�%

7 1 TLC�801

BlockTypeSetup(block�system)3:H)�

BlockInstanceSetup (block�system)BlockInstanceData(block�system)

Enable(block�system)Disable(block�system)

Start(block�system)InitializeConditions(block�system)

Outputs(block�system)Update(block�system)

Derivatives(block�system)

3�O?-6,;

D�)�

Terminate(block�system)

B�?-3:H�)��� BlockTypeSetup(block, system) 9)�CI)��\��������#include�%��O�- ,��)��� Start(block, system)�6�� C ,����� � ,�Outputs(block, system)�6��B��� ,%

S�����RS���N����� ,��

+���)���E� L�)���%Sa!.�

�"#�� ,UV$O�%�+B�)�%

3.1.3 DLL9:�,; (Function of DLL files)

DLL'8���C MEX S)�'8���MEX'8%MATLAB� mex7� ��6��;&8�'())�!J

� ����*�Simulink E�;)��Simulink4&+

� � ,��, ��� MEX '8�-�mdlRTW)�� ,��^(',-�-./0�123'8 model.rtw�%

4���56'8��K>�/ sfun.cCsfun.dllCsfun.tlc -Z�S375*�8>�,9: S )��������?2%�+;<C(=�����@��

>4!,��1?36 Simulink b@*�9@�;A�A�������3�@� �����

�����3 Simulink���[��E�%�� transmitCreceiveCremote requestCremote

responseCbus off�2� CAN���B������HC12 7��NA�����, �� �� CAN� !��"1�3 Simulink � HC12 ����[��#4�� HC12 7�GH�� CAN !���� RTWE�%

664

3.2 Simulink <=>�� ��?@A��(Message Simulation under Simulink)

$����� CAN !��� K%)�@A�T�O�78&L�@AWX'��B�%�*

()L( CAN )*�+,��-WX'C.8�!WX'�B '�78%

3.2.1 �����(Periodic Message)�-/�'� CAN ���2801�34/�

'%; 6� Simulink78/�'!BM2�3N;%/�43N��� Simulink �T), RTW 5�

,�),6=^6=CM��*�37�����B

5]� ID �/�'�'!B�-C/�'!B����O),GH��7/�H878%'!BM2�

��O����DCC01��EN%

� 6 1BA(CDE��

3.2.2 F:G(?@A(Event-triggered Message)

.8�!WX'�������9:��&'7

8�.8�!WX';7<�=->V���@A

&���4R�7O%

3.2.3 ���(Remote Message)���)W, ��@A�?<a%),-&L

�WXD+!B�E3@A@�!�� �+���

�@A�L�(L�@A���+ K�!�(

L����,-L��+@A��L ����

.3�� ���+�!�� %� ��+@AD

A78�� 7��%

� 7 H.AIJ����

3.3 � KLMNOP��Q*(Algorithm of Transmission

Random Latency)

ECU �����b��RS�O��6��WX��� !"#$%%4#$BF������

&'(��R��)��%!*�������a(

��+�#$a,�.-.�F/%0F/�+�#

$a,1����!"#$82�(/0#$(��

���F�1)�%

� 8�0 Simulinkb�*3K�#$4:�O0F/�+�#$a,1!"� #$�WX�!�%

��78� 8���4:a�5�������� b�� ������a��T�

� �b����� 32�� 9���R�PQ���A��MATLAB�����

�� �2�%�a�LEF :�789����

S���� Simulink ��B���%

� 8 Simulink<=>RS�OPQ*

4 �� MATLAB � CAN �����TUUV (Experimental Test of the Network NodeSimulation Based on MATLAB)

MATLAB �T!���"#$ Freescale HC12��� MC9S12DP256B %G"� Philips � 82C250CAN&!'GV��CANWX�(&@A�)��� CAN�*� !���D CANoe%��@A�78� +, 9��%

� 9 ����TW6.

� Simulinkb�!-� 3.1@�.� CAN �/@0��12, 6 ��346.2 HC12 �!��

665

T�G� Transmit���5��H� ID� 64H��677!9��!�@A%Sa-�, 8���#$ :8��7!��57!9:�� 500ms� �#$a�EF� 10ms%!�;"E"<�8� RTW��7a� C���! CodeWarrior�=C(<�!�#�"#�783=!�@A%

� CANoe>�$: CAN�*���2%>��C/UZ+, 10��%

� 10 CANoeXYZ9?@

( CANoe :Z��*�2�%?a�A,-&4��"#!�@'�!"#aa�+, 11��%

Time/s

Ran

dom

dela

y/s

� 11 Z9�MNOP

7YUZ[\�;@A9'��)+78.9:

WXA�/a!�� �!"#$a�(6 10 ms�PQ��)+%)��;9:�D<=78��@A

��%

B27C����@A�RSNA�� Simulink�/:6.RS� :D��RS*+�E,78R

S@A����F=@A;��3��������

2F CAN ���������F�����-� %

5 �[(Conclusions)

&'���56MATLAB /Simulink /RTW78����������������������

��Y���UV�������O-�����%

�� Simulink78F4�����:��� ;"!Y�:�"#��$%.E"&�a�; �� RTW 0'()*)+,6-'.G�/�0*�1-.

0 a�; Sa�+Z2)345�@A�����.34@AWXa�62)� Simulink�T�789�EF�1H'()*:O%���<=>?��@

A�B�C�����78 ;<=/�EFGH

IJ��KLRS�T��UVC��WX���)

+%

\]9^(References)

[1] <01, 2I>, 2?3. 56=7@T�J7A;"�������������78: 45BCDE8F�G'?, 2006.

[2] 6KE, 78, L�H, M. 56OPNET�9�0PN0� CAN���;"[J]. :I���@, 45(5): 689-692.

[3] J;K, =L3, ���, �. CAN ������, �

� ���, 1998, 19(3):59-61.[4] ��, M�, ��, �. ��7a�� !b��L�

[M]. �������2��, 2002.