]> rtime.felk.cvut.cz Git - ert_linux_web.git/blob - can_bus/index.html
45a91a2b49b6e1ba784e87a7d820ba75bc7d5b15
[ert_linux_web.git] / can_bus / index.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2    "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5   <title>[[!meta title="Simulink Blocks for CAN bus Support under Linux."]]</title>
6   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7   <link><style type="text/css">
8     #main_content {max-width: 70em}
9   </style>
10 </head>
11 <body>
12
13 <div id="main_content" style="max-width: 60em;">
14
15 <p>
16 The toolbox provides basic blocks for sending and receiving
17 CAN messages for <a href="http://lintarget.sourceforge.net/">ERT Linux</a>
18 Simulink target when mainlined
19 <a href="http://elinux.org/CAN_Bus#SocketCAN_Supported_Controllers">socket based CAN bus</a>
20 support is used. The <b>cantransmit</b> and <b>canreceive</b> blocks
21 support directly encapsulation and conversion to the Simulink signals for basic
22 data types: <tt>uint8</tt>, <tt>uint16</tt> and <tt>uint32</tt>.
23 The standard Simulink defined <tt>CAN MESSAGE TYPE</tt> can be used
24 when more complex structure of CAN message sending and receiption
25 is required. The signal of <tt>CAN MESSAGE TYPE</tt> can be connected
26 to <b>CAN Pack</b> and <b>CAN Unpack</b> blocks which encode or retrieve multiple
27 signals to/from CAN message. The CAN Pack and CAN Unpack blocks
28 are provided by <tt>canmsglib</tt> which is part of standard Simulink
29 distribution.
30 </p>
31
32 <p>
33 The code generation requires to include <b>CAN Setup</b> into diagram
34 to work correctly. This block is used to setup baudrate for each CAN
35 channel in the embedded environment but this option is ignored
36 in the actual setup block implementation on Linux. The baudrate
37 can be selected by system administrator from commandline
38 <pre>
39 ip link set can0 down
40 ip link set can0 type can bitrate 1000000 
41 ip link set can0 down
42 </pre>
43 or on Debian based systems <tt>/etc/network/interfaces</tt>
44 configuration file can be used to setup CAN interface baudrate
45 at system startup
46 <pre>
47 allow-hotplug can0
48 iface can0 can static
49     bitrate 1000000
50 </pre>
51 The later setup works automatic even with CAN-USB converter hotplug.
52 </p>
53
54 <h2 id="included_files">Project Included Files</h2>
55 <p>
56 The projects includes blocks library <b>socketcan_lib.slx</b>, simple
57 example of provided blocks use <b>cantransmit_ert.slx</b> and more
58 complex model <b>canopen_2j_arm_ert.slx</b> which demonstrates
59 use of the block to send PDO messages to two stepper motors
60 controlled robotic arm. This simple CAN library does not
61 provide CANopen support yet so initial motors SDO parameters
62 setup is solved by <b>canopen_2j_arm_setup</b> shell
63 script which invokes <tt>cansend</tt> command.
64 The variant of the model (<b>canopen_2j_arm_rpi.slx</b>) with
65 build parameters preset for crosscompilation to Raspberry Pi
66 is provided as well.
67 The CAN-USB converter from 8devices has been used in this case. 
68 </p>
69
70 <h2 id="simulink_setup">Simulink Target Setup</h2>
71 <p>
72 Download/clone <a href="http://lintarget.sourceforge.net/">ERT Linux</a> target
73 and Linux CAN bus toolbox repositories. The example expects the toolbox
74 are placed into user local <tt>~/matlab/toolbox</tt> directory.
75 Setup Matlab path for thee projects. One option is to use <tt>~/matlab/startup.m</tt>
76 file for this purpose:
77 </p>
78 <pre>
79 function startup(AddRem)
80
81 disp 'Executing local setup stript ~/matlab/startup.m'
82
83 restoredefaultpath
84
85 [matlab_startup_dir, matlab_startup_filename, matlab_startup_dir_ext] = fileparts(mfilename('fullpath'));
86
87 addpath(fullfile(matlab_startup_dir, 'toolbox/ert_linux/ert_linux'));
88 addpath(fullfile(matlab_startup_dir, 'toolbox/socketcan-simulink/blocks'));
89 </pre>
90 <p>
91 Use example model as base for the project or open <b>Simulation</b> &rarr; <b>Model Configuration Parameters</b>
92 dialog and select <b>System target file</b> to <tt>ert_linux.tlc</tt> in <b>Code Genration</b> section.
93 Check <b>Make command</b>. It should be something like:
94 </p>
95 <pre>
96 make_rtw OPT_OPTS="-O2 -ggdb -Wall -D_BSD_SOURCE"
97 </pre>
98 <p>
99 Use proper <tt>CC</tt> variable definition  in case of cross compilation to some other target.
100 See next example for Raspberry Pi:
101 </p>
102 <pre>
103 make_rtw OPT_OPTS="-O2 -ggdb -Wall -D_BSD_SOURCE" CC=arm-rpi-linux-gnueabihf-gcc
104 </pre>
105
106 <h2 id="links">Links</h2>
107 <dl>
108   <dt>Linux CAN bus toolbox repository</dt>
109     <dd><a href="http://rtime.felk.cvut.cz/gitweb/socketcan-simulink.git" target="_blank">http://rtime.felk.cvut.cz/gitweb/socketcan-simulink.git</a>
110     <br><tt>git clone git://rtime.felk.cvut.cz/socketcan-simulink.git</tt> 
111     </dd>
112   <dt>Usable Simulink Embedded Coder Target for Linux</dt>
113     <dd>Michal Sojka, Pavel Pisa<br>
114     <a href="https://www.osadl.org/RTLWS-2014.rtlws-2014.0.html">16th Real-Time Linux Workshop</a>a>,
115     Düsseldorf, Germany, October 2014.
116     The <a href="http://rtime.felk.cvut.cz/publications/public/ert_linux.pdf">paper (PDF)</a>
117     and <a href="http://rtime.felk.cvut.cz/publications/public/ert_linux-rtlws2014.pdf">slides (PDF)</a>
118     are available from our
119     <a href="http://rtime.felk.cvut.cz/publications/">publications archive</a>.
120     </dd>
121 </dl>
122
123 </div>
124
125 </body>
126
127 </html>