1 [[!meta title="Linux Target for Simulink® Embedded Coder®"]]
3 [[!img ert_linux_snapshot1.png size="300x" align=right alt="Screenshot or ert_linux"]]
5 Linux ERT target for [MathWorks]' [Simulink]® Embedded Coder® allows
6 to compile a model of designed control system to the C-code and
7 combine it with target specific support functions. The resulting
8 executable/controller can be run in real-time on the target Linux
9 system. The running dynamic system can be augmented via tunable block
10 parameters in the Simulink model and data can be acquired and
11 visualized with Simulink scopes.
13 Linux ERT target uses heavily real-time capabilities of
14 [real-time variant of the Linux kernel](https://rt.wiki.kernel.org/index.php/CONFIG_PREEMPT_RT_Patch)
15 that provides bounded maximal latencies. The resulting control system
16 supports sampling frequencies **up to 20 kHz**. Matlab/Simulink GUI
17 running on the same GNU/Linux desktop system as the generated
18 real-time application is supported.
20 More information about initial version developed by Michal Sojka at [Department of Control Engineering](https://control.fel.cvut.cz/) [FEE](http://www.fel.cvut.cz/)
21 [CTU](https://www.cvut.cz/) can be found in
22 [Michal Sojka's blog post](http://rtime.felk.cvut.cz/~sojka/blog/on-generating-linux-applications-from-simulink/).
24 [MathWorks]: http://www.mathworks.com/
25 [Simulink]: http://en.wikipedia.org/wiki/Simulink
33 - The real time control of DC and BDLC motors from plain C and Matlab/Simulink with
34 ert_linux target hands-on session is planned at 29th February 2020 at 15:00–16:55
35 at place of the project origin ([DCE](https://control.fel.cvut.cz/) labs) in the frame
36 of [InstallFest 2020](https://installfest.cz/if20/) conference.
37 See [details](https://pretalx.installfest.cz/installfest-2020/talk/HSNJCM/).
39 [Usable Simulink Embedded Coder Target for Linux](https://www.osadl.org/?id=2018)
40 and RPi motor control has been presented at
41 [16th Real Time Linux Workshop](https://www.osadl.org/RTLWS-2014.rtlws-2014.0.html)
42 taking place on 12 and 13 October 2014 in Dusseldorf Germany. The
43 [Paper](http://rtime.felk.cvut.cz/publications/public/ert_linux.pdf)
45 [slides](http://rtime.felk.cvut.cz/publications/public/ert_linux-rtlws2014.pdf)
46 are available from our
47 [publications archive](http://rtime.felk.cvut.cz/publications/).
48 - The ert_linux project has been presented at
49 [Amper exhibition](http://www.amper.cz/en/online-catalog/list-of-exhibitors.html/e9595_0-fakulta-elektrotechnicka-cvut-v-praze)
50 from 18th to 21st March 2014 in Brno, Czech Republic.
51 - Linux ERT at Embedded World exhibition – 25 until 27 February 2014 - Visit
52 [DCE CTU](http://www.ask-embedded-world.de/index.php5?id=342793&Action=showCompany)
53 developers and researchers at the OSADL booth (hall 5 booth 276).
55 I/O and communication interface support
58 - [Humusoft MF624 data acquisition card](https://www.humusoft.com/datacq/mf624/).
60 <abbr title="User Space I/O">UIO</abbr> driver and Simulink blockset
61 has been developed. The UIO driver is already
62 [included in the mainline Linux kernel](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=06849faab58fc7ff9f4eae2532380c2a746a6f47).
63 Simulink blockset is available from a
64 [separate repository](https://rtime.felk.cvut.cz/gitweb/mf624-simulink.git).
65 More documentation about the UIO driver can be found on
66 [DCE HW Wiki page](http://rtime.felk.cvut.cz/hw/index.php/Humusoft_MF6xx).
68 - The Bhanderi's [ComediToolbox](http://www.mathworks.com/matlabcentral/fileexchange/15792-comedi-toolbox-v1-0-for-linux-based-rtw-targets) suitable for most Linux [Comedi](http://www.comedi.org/)
69 driver supported analog and digital inputs/output cards has been
70 successfully tested with <b>ert_linux target</b>. The little updated
71 version with target configuration example is available in
73 [download area](https://sourceforge.net/projects/lintarget/files/).
75 - The basic blocks for [CAN bus communication](can_bus/index.html)
76 under Linux are implemented.
78 RT-Capable Platform and Kernel
81 Standard distribution Linux kernel does not guarantee bounded
82 latencies for many operations. The use of
83 [real-time variant](http://rt.wiki.kernel.org/) of
84 [Linux](http://en.wikipedia.org/wiki/Linux) kernel is required to
85 guarantee bounded latencies. This kernel variants minimizes regions
86 where switch to the highest priority (e.g. Linux ERT generated) task
87 is blocked by kernel when servicing system calls for other tasks.
89 Selection of the right version of the kernel is not enough for
90 non-disruptive operation. Computer system hardware selection is
91 critical as well. The system has to provide enough computational power
92 for compiled in blocks data evaluation evaluation and Linux kernel
93 services processing. Other critical disturbance sources are hardware
94 caused latencies and lags in a program processing by CPU. The source
95 can be bus systems load by other subsystems (i.e. graphic processor
96 memory access, peripheral DMA - SSD, SD-card, Flash controller etc.).
97 The other critical source of latencies in x86 based systems is
98 [SMI](http://en.wikipedia.org/wiki/System_Management_Mode) processing.
99 The SMI enable and processing is under BIOS and motherboard vendor
100 control and this problem cannot be resolved by the operating system.
101 This means that proper hardware selection is critical.
103 A long period evaluation data of different combinations of Linux
104 kernel version running on many CPU architectures and boards from many
105 vendors is [OSADL](http://www.osadl.org/)
106 [Quality Assurance Farm](http://www.osadl.org/Quality-assurance-at-the-OSADL-QA-Farm.osadl-services-qa.0.html).
107 According to these track records carefully selected x86 or embedded
108 GNU/Linux system can run real-time tasks with sampling frequencies up
109 to 20 kHz with no losing sample per months.
111 Source Code and Download
114 - [Download area at Sourceforge](https://sourceforge.net/projects/lintarget/files/)
115 contains released versions of the Linux target and CANopen based
117 - Linux ERT source code repository [GitHub DCE](https://github.com/aa4cc/ert_linux)
118 (the lastest version for now, with examples for native, ARM and AArch64/ARM64 builds),
119 [GitHub IIG](https://github.com/CTU-IIG/ert_linux),
120 [Original RTIME Repo](http://rtime.felk.cvut.cz/gitweb/ert_linux.git).
121 - [Humusoft MF624 card support blockset](http://rtime.felk.cvut.cz/gitweb/mf624-simulink.git)
122 <br>Initial version of blockset supporting analog and digital
123 input/output, IRC, PWM and PWM measurement for MF624 cards.
129 The Linux ERT has been initially developed at
130 [DCE of CTU](https://control.fel.cvut.cz/en) in order to create a dynamic
131 environment model for hardware (airplane) in the loop testing of a
132 fly-by-wire system at [AERO Vodochody a.s.](http://www.aero.cz/en).
133 Simulink has been run on Windows host computer initially and code
134 generated for GNU/Linux embedded target system was compiled under
135 [MinGW/MSYS](http://en.wikipedia.org/wiki/Mingw) environment and then
136 uploaded to PowerPC based
137 [BOA5200](http://rtime.felk.cvut.cz/hw/index.php/Boa5200) computer.
138 The target computer was equipped with two CAN interfaces.
139 [CANopen](http://en.wikipedia.org/wiki/Canopen) blockset based on
140 [CANfestival](http://canfestival.org/) project was used to control
141 distributed servosystem used to simulate fly-by-wire system load.
142 Simulink CANopen blockset integrates a
143 [SocketCAN](http://en.wikipedia.org/wiki/Socketcan) driver
144 configuration and CAN messages processing support to the generated
145 code and enables the user to develop distributed embedded control
146 applications with CANopen communication.</p>
148 [[!img LinTarget.JPG size=300x alt="Original code generation workflow"]]
149 [[!img CANopenExample.JPG size=300x alt="Model including node controlled over CANopen"]]
151 Lukáš Hamáček, “*RTW target for Linux with CANopen support*”, Master Thesis, Prague 2009. ([Pdf](dp_2009_hamacek_lukas.pdf))
153 Systems Controlled Linux Target for Embedded Coder
156 Some more information about concrete examples of controlled systems/setups:
159 <dt><b>Moving Slide</b> parallel kinematic/robot control</dt>
160 <dd>The Linux ERT target is used at Adaptive Systems Department (Academy of Sciences
161 of Czech Republic, UTIA institute) to realize control system for parallel kinematics
162 control research projects. See <a href="moving-slide/index.html">respective page for more
163 information about project</a>.
165 <dt><b>Raspberry Pi</b> minimal components DC motor servo control</dt>
166 <dd><a href="http://en.wikipedia.org/wiki/Raspberry_Pi">Raspberry Pi</a> is low cost
167 hardware which does not implement any usual motor control peripherals in hardware.
168 Yet fully preemptive variant of Linux kernel latencies are so low that fast signals
169 processing in software allows to implement precise DC motor feedback control
170 for incremental encoder inputs changing up to 15 kHz.
171 See <a href="rpi-motor-control/index.html"> respective page for more information
174 <dt><b>Permanent magnet synchronous motor control (PMSM) with SPI connected peripherals and power stage</b></dt>
175 <dd>The experiment is primarily focused on school labs. The experiment utilizes
176 two extension boards. One is fully galvanically isolated 3/phases power stage
177 with HAL effect based current sensing and differential IRC signals receiver.
178 The other board provides peripherals (IRC processing and counting,
179 PWM generation, current ADC results collection) required
180 for vector PMSM motor control. This board is connected to
181 <a href="http://en.wikipedia.org/wiki/Raspberry_Pi">Raspberry Pi</a> simple board
182 computer by SPI port. The control algorithm generated by the ERT target
183 runs under fully preemptive Linux kernel at sampling rate 5 kHz.
184 See <a href="rpi-pmsm-control/index.html"> respective page for more
185 information about project</a>.
187 <dt><b>The Xilinx Zynq DC motor and PMSM Motor Control</b></dt>
188 <dd>The <a href="https://en.wikipedia.org/wiki/Field-programmable_gate_array">FPGA</a>
189 based solutions provide flexibility unmatch by other hardware. This set of applications
190 cobines <a href="https://en.wikipedia.org/wiki/Xilinx">Xilinx</a>
191 <a href="https://en.wikipedia.org/wiki/Xilinx#Zynq">Zynq</a> SoCs, Linux RT kernel,
192 custom PMSM driver hardware and ert_linux Matlab/Simulink coder.
193 The linux 4.19 kernel with RT preempt patches and with MathWork's FPGA IP drivers (mwipcore)
194 applied can be found in branch
195 <a href="https://github.com/ppisa/linux-kernel/tree/linux-4.19.y-mwcore">linux-4.19.y-mwcore</a>
196 of the Pavel Pisa'a <a href="https://github.com/ppisa/linux-kernel">Linux kernel</a>
197 repository on GitHub. The mwipcore drivers are not required for this ert_linux solution,
198 but RT patch is fundamental. The <a href="https://cw.fel.cvut.cz/wiki/courses/b35apo/documentation/mz_apo/start">MZ_APO</a>
199 education kits (use <a href="http://zedboard.org/product/microzed">MicroZed</a> SBC)
200 developed at <a href="http://www.pikron.com/">PiKRON</a> company to support teaching
201 of <a href="https://cw.fel.cvut.cz/wiki/courses/b35apo/start">Computer Architectures</a>
202 course at <a href="https://control.fel.cvut.cz/">Department of Control Engineering</a>
203 are connected with the PMSM driver power stage developed initially for Altera DE2 kits
204 with option to be SPI connected to Raspberry Pi are used with MZ_APO.
205 The presentation <a href="https://installfest.cz/if17/slides/so_t2_pisa_realtime.pdf">GNU/Linux
206 and FPGA in Real-time Control Applications</a> presents the hardware.
207 The Simulink model <a href="https://raw.githubusercontent.com/ppisa/rpi-rt-control/master/simulink/zynq_pmsm_motor_control.slx">zynq_pmsm_motor_control.slx</a>
208 of PMSM controller is included along the Raspberry Pi example in repository
209 <a href="https://github.com/ppisa/rpi-rt-control">https://github.com/ppisa/rpi-rt-control</a>.
210 The FPGA design can be found in branch <a href="https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top/tree/microzed-mc-1">microzed-mc-1</a> of the repository
211 <a href="https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top">https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top</a>. The MZ_APO education kit mechanical and electronics designs are available from <a href="https://gitlab.com/pikron/projects/mz_apo/microzed_apo">https://gitlab.com/pikron/projects/mz_apo/microzed_apo</a>.
213 <dt><b>Usable Simulink Embedded Coder Target for Linux</b></dt>
214 <dd>Michal Sojka, Pavel Pisa<br>
215 <a href="https://www.osadl.org/RTLWS-2014.rtlws-2014.0.html">16th Real-Time Linux Workshop</a>,
216 Düsseldorf, Germany, October 2014.
217 The <a href="http://rtime.felk.cvut.cz/publications/public/ert_linux.pdf">paper (PDF)</a>
218 and <a href="http://rtime.felk.cvut.cz/publications/public/ert_linux-rtlws2014.pdf">slides (PDF)</a>
219 are available from our
220 <a href="http://rtime.felk.cvut.cz/publications/">publications archive</a>.
228 <dt>Michal Sojka</dt>
229 <dd><a href="mailto:sojkam1@fel.cvut.cz">sojkam1@fel.cvut.cz</a> ,
230 homepage <a href="http://rtime.felk.cvut.cz/~sojka/">http://rtime.felk.cvut.cz/~sojka/</a>
231 <br>teacher, researcher and developer at DCE CTU.
234 <dd><a href="mailto:pisa@cmp.felk.cvut.cz">pisa@cmp.felk.cvut.cz</a> ,
235 homepage <a href="http://cmp.felk.cvut.cz/~pisa/">http://cmp.felk.cvut.cz/~pisa/</a>
236 <br>teacher, researcher and developer at DCE CTU.
238 <dt>Rostislav Lisový</dt>
239 <dd><a href="mailto:lisovros@fel.cvut.cz">lisovros@fel.cvut.cz</a>
240 <br>former CTU master study programme student, Linux related projects developer at DCE now.
242 <dt>Libor Waszniowski</dt>
243 <dd><a href="mailto:xwasznio@fel.cvut.cz">xwasznio@fel.cvut.cz</a>
244 <br>former DCE CTU researcher responsible for the project with AERO Vodochody.
246 <dt>Lukáš Hamáček</dt>
248 former CTU master student.
253 [Department of Control Engineering](http://dce.fel.cvut.cz/) –
254 [Czech Technical University in Prague](http://www.cvut.cz/en),
255 [Faculty of Electrical Engineering](http://www.fel.cvut.cz/en)
260 This work was supported by Ministry of Industry and Trade of the Czech Republic under Project
261 FT—TA3/044 during period of 2006 to 2009 years.