Raspberry Pi Simulink Coder target (RPIt)
- September 1 2016: RPIt is now on GitHub. See the latest news there.
- June 29th 2016: fix initial condition problem in socket block.
- June 23th 2016: new socket block.
- April 29th 2016: compatibility with Matlab R2015a and R2015b.
- April 29th 2015: new block for the Polaris 3D localization system. Compatibility with the RPI2.
- July 9th 2014: add a block for measuring CPU usage on the target.
- June 27th 2014: bugfix release.
- Add "setup_NXT.m" script to automate the Lego NXT flashing with RPIt driver.
- Add a workaround for 2012a char16_t bug.
- Add missing configuration for NXT USB user access in setup.
- Major rewrite of "setup.m" for more generic handling of various platforms.
- Some minor bugfixes.
- June 18th 2014: major update.
- Add compatibility with Mac OSX releases of Matlab/Simulink.
- Add compatibility with Linux releases of Matlab/Simulink.
- Add compatibility with generic Debian-based targets, not only the RPI (the target can be a Ubuntu PC, ARM or x86).
- New Lego NXT block. Multiple NXTs can be controlled through USB.
- June 6th 2014: minor update.
- Add support for the latest 2014a release.
RPIt stands for "Raspberry PI Simulink Coder target". It is an independent project that targets mainly (but not only) the Raspberry Pi (RPI) embedded platform from the Matlab/Simulink environment using Simulink's external mode feature. In the following "target" means a distant Debian-based computer (e.g. a RPI).
The Simulink block-diagram is automatically converted into C code, transferred to the target and compiled directly on the target (no cross-compilation). Then, the executable is launched on the target and a TCPIP connection is started between Simulink and the target. The executable running on the target uses standard Unix timing mechanisms. Thus it is soft real-time. Though the measured jitter is around 100 microseconds, which is pretty small. The communication between the target and Simulink is asynchronous. It allows for on-the-fly parameters tuning and measurements visualization thanks to live scopes.
The provided blockset includes an “EV3″ block for interfacing Simulink with the Lego EV3 brick running the standard firmware. The EV3 brick is connected to the target with USB. The dialog between the target and the EV3 uses bytecodes understandable by the virtual machine implemented in Lego’s original firmware. This block supports all EV3-compatible actuators and sensors. With the last version of RPIt, you can also control up to 4 Lego NXTs simultaneously within Simulink (for this you need of course a USB hub attached to your target). IMU devices, like the MPU9150, directly connected to the target with I2C, are also supported by this blockset. The source code of RPIt is totally open. It is independent from Mathworks’ Raspberry Pi target and thus does not interfere with it.
The RPIt blockset provides also a block for interfacing Simulink with multiple EV3s running a modified firmware called "EV3.14". This modified firmware allows for higher accuracy encoder counting (720 increments per turn instead of 360) and shorter response time (1ms instead of 5ms).
- The target is fully auto-configured with a single "setup.m" script. This script can safely by re-run without adverse side-effects.
- Generated code is optimized for the target. Compiler options have been tuned to maximize speed.
- The compilation is performed on the target. So the libraries are always up to date.
- The connection between Simulink and the target can be Wireless. A very convenient setup is to configure the target as a hotspot.
- When using the Raspberry Pi (RPI) as target in combination with the Lego EV3, the RPI can be powered by the EV3 USB port. It delivers enough current to stand full CPU charge, image acquisition and WiFi transmission. Thus, such a setup is fully autonomous and wireless and can for example be used for mobile robotics applications.
- Supported operating systems
- Windows XP, 7, 8, 10 32 or 64 bits
- Mac OSX (tested on Lion with Matlab 2014a and on El Capitan with Matlab 2016b)
- Linux (tested on Ubuntu 12.04 LTS 64 bits, Kubuntu 14.04 LTS 64 bits, Debian Wheezy 64 bits, Debian Jessie 64 bits with Matlab 2010b, 2012a, 2014a, 2016b)
- Supported Matlab releases
- 2010b, 2010b SP1, 2010b SP2
- 2012a (the last one with the old user interface)
- 2015a, 2015b
- 2016a, 2016b
- Required Matlab toolboxes
- Supported target platforms
- Raspberry Pi all models running Raspbian, Raspbian distribution
- Any Debian-based machine (Debian, Ubuntu, Mint, …) 32 or 64 bits, ARM or x86
These devices can be controlled in external mode. They are connected to the target through I2C (all the IMU boards) or USB (the NXT and EV3 bricks, Dynamixel and Xbox controller). The maximal achievable frequency varies from one device to another. It is specified in the help section of the SImulink block.
- Devices supported in Simulink library browser
- Lego EV3 brick with standard Lego firmware
- Lego EV3 brick with custom EV3.14 firmware
- Lego NXT brick with custom real-time firmware (NXTOSEK)
- Pololu MinIMU-9 v2 Gyro, Accelerometer, and Compass (L3GD20 and LSM303DLHC Carrier)
- Drotek IMU 9DOF - MPU9150 Invensense PCB (20€)
- Sparkfun 9 Degrees of Freedom - MPU-9150 Breakout (50$)
- Polaris 3D localization system by NDI.
- Dynamixel actuators from Robotis.
- Xbox-compatible controllers.
Note that when running the original Lego firmware, only one EV3 brick can be accessed from Simulink (the first in the USB enumeration) whereas up to 4 NXT bricks can be accessed simultaneously. But if you are running the EV3.14 firmware, multiple EV3 blocks can be accessed simultaneously.
Below, an example of wiring for the MinIMU-9 v2 (thanks to Mark's space dot com blog which was also for me a very useful source of inspiration for the coding of the MinIMU-9 v2 driver).
You will find here the source of the test programs used to communicate with these devices from the target.
Typical setup examples
- Communication with I2C devices (IMUs from Pololu, Drotek or SparkFun) runs at 400kHz. Approximately 1ms delay for reading all values. Internally the gyro and accelerometer acquisitions are refreshed at a higher frequency (400-800Hz).
- Communication with an EV3 with Lego's original firmware has a roundtrip latency of 5ms, one USB exchange per sampling time. Send control signal bytecodes and receive sensor values in 32 bits raw data. Whereas, this roundtrip latency is only 1ms when running the EV3.14 firmware.
- Communication with the NXT has a roundtrip below 2ms due to the use of a dedicated NXTOSEK real-time driver.
- Communication with the Dynamixel uses a USB2Dynamixel dongle. For 5 devices on a RS485 bus running at 3 Mbps the maximum achievable frequency is 300 Hz.
- Max sampling rate (with devices that stand it): 1kHz
This quick-start is focused to a Raspberry Pi target. But keep in mind that you could do the same with any Debian-based machine. You may even use as target the machine that is running Matlab if it is Debian-based. In this particular case simply give the IP address of the localhost as the target IP.
You should have an up-to-date Debian-based distribution with the build-essential package installed in order to be able to compile the embedded coder generated C code. To do that, issue this commandI:
sudo apt-get install build-essential
Probably the easiest and quickest way to start with RPIt is to watch this short screencast. For more verbose details, look at the following subsections.
Direct link: 
- Download the latest version of RPIt.
- Extract it somewhere (there is no need to have a path with no blanks).
- Start Matlab.
- In Matlab, change the current directory to the "rpit" folder, the root folder of the extracted package.
- In the command window, run "mex -setup" and choose a compiler compatible with your system. If none is installed by default (64bits systems) download a free and compatible one from Microsoft's website (check Matlab's website).
- Verify that your target is connected to the internet. Indeed during the setup, some required packages will be downloaded and installed. If these packages are already installed, you can run the setup without internet connection.
- Note the IP address of the target. It will be asked by the setup process.
- In Matlab's command window type "setup".
- The target will be accessed with a passwordless ssh connection. Private and public keys must be generated and the public key will be uploaded to the target. Follow the instructions displayed in the command window. Verify that you save the keys in the right directory, i.e. the "tools" directory inside your rpit root directory.
- Enter the target IP address and the password for the "pi" account. This password will be erased from workspace at the end of the setup procedure and the generated private key will be used instead.
- When this last step is over, everything should run without interaction.
- At the end of the setup, a test of the connection is made and the result is displayed.
Note that this script can safely be run as many times you want. Key generation, package download and installation, target configurations will only be made once.
- Go into the "demo" folder.
- Go into the "jitter" folder.
- In the menu "Simulation" select "Configuration parameters..."
- Select the item "Real-Time Workshop" (2010b) or "Code Generation" (starting from 2012a).
- Verify that the system target file is "ert_rpi.tlc". If not, browse and select it. This selection will auto-configure almost everything except the IP address of the RPI.
- Select the "Interface" item.
- In the "MEX-file arguments:" field type the IP address of the RPI with quotes around ('xxx.yyy.zzz.vvv').
- Hit the "Apply" button.
- Verify that the target IP address is reachable.
- Select the Simulink window for the "jitter" model.
- Hit [CRTL-B].
- Wait for the procedure to complete.
- At the end, the external mode should be running and the scope is displaying the difference between the theoretical time (Simulink time) and the real time measured by a high resolution timer on the target. If successful, this last step validates the installation.
RPIt is distributed under the GNU General Public License.
In addition, any publication (scientific, educational, hardcopy or digital) about a project using this software should contain a pointer to this web page (http://icube-avr.unistra.fr/en/index.php/RPIt) as reference, footnote or hyperlink.
External code used in RPIt
- The Windows setup procedure uses executables from the PuTTY project.
- The NXT flashing procedure uses John Hansen's nexttool utility.
- The NXT driver is based on NXTOSEK.
|Version number||Release date||Download link||Release notes||Author|
|4.12||June 29th 2016||RPIt-4.12.zip (23.8MB)||Fix initial condition issue in socket block.||J. Gangloff|
|4.11||June 23th 2016||RPIt-4.11.zip (23.8MB)||New socket block.||J. Gangloff|
|4.8||Apr. 29th 2016||RPIt-4.8.zip (23.8MB)||Compatibility with R2015a and R2015b.||J. Gangloff|
|4.6||Apr. 29th 2015||RPIt-4.6.zip (23.8MB)||New Polaris block. Compatibility with the Pi2.||J. Gangloff and X. Weber|
|3.25||Oct. 13th, 2014||RPIt-3.25.zip (23.8MB)||Change for a more compatible zip format.||Jacques Gangloff|
|3.24||July 9th, 2014||RPIt-3.24.zip (23.8MB)||Add a bloc to measure CPU usage on the target.||Jacques Gangloff|
|3.23||June 27th, 2014||RPIt-3.23.zip (23.8MB)||Add "setup_NXT.m" script to automate the Lego NXT flashing with RPIt driver.
Add a workaround for 2012a char16_t bug.
Add missing configuration for NXT USB user access in setup.
Major rewrite of "setup.m" for more generic handling of various platforms.
Some minor bugfixes.
|3.14||June 18th, 2014||RPIt-3.14.zip (14MB)||Add compatibility with Mac OSX releases of Matlab/Simulink.
Add compatibility with Linux releases of Matlab/Simulink.
Add compatibility with generic Debian-based targets, not only the RPI (the target can be a Ubuntu PC, ARM or x86).
New Lego NXT block. Multiple NXTs can be controlled through USB.
|2.22||June 6th, 2014||RPIt-2.22.zip (7MB)||Add 2014a support.
|2.21||Apr. 7th, 2014||RPIt-2.21.zip (7MB)||MPU9150: fix magnetometer axis.
MPU9150: fix gyro scale initialization.
Setup: add R2011a support.
|2.20||Feb. 4th, 2014||RPIt-2.20.zip (7.35MB)||Initial public release||Jacques Gangloff|
These codes are given as examples how to access the devices supported by RPIt. Note that bug fixes in RPIt are generally not ported back to these examples. So if you suspect a bug, please check first the RPIt implementations (in directory blocks, the files ending with _wrapper.c) for possible updates. For example, to check the latest code for the MPU9150, see the file rpi_sfun_mpu9150_wrapper.c.
- Bytecode USB communication between RPI and Lego EV3
- I2C communication between RPI and MinIMU-9 v2
- I2C communication between RPI and MPU9150
Related educational projects
One of the main goal of this package is education. Below an example of a 50 hours project by 2 last year students of Telecom Physique Strasbourg (engineering school).
Direct link: 
Related research projects
This software was used by Xavier Weber for his PhD thesis on active damping of cable-driven parallel manipulators. Below two short videos illustrating his work. This work will be presented at IROS 2014  and ICRA 2015 .
Direct link: 
Direct link: 
- Xavier Weber, Loic Cuvillon and Jacques Gangloff, Active vibration canceling of a cable-driven parallel robot using reaction wheels, in proceedings of the IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS 2014), Chicago, Illinois, Sept. 14–18, 2014.
- Xavier Weber, Loic Cuvillon and Jacques Gangloff, Active vibration canceling of a cable-driven parallel robot in modal space, in proceedings of the IEEE International Conference on Robotics and Automation (ICRA 2015), Seattle, Washington, May 26–31, 2015.
I'm currently the only developer of this package. You can copy and use it freely. If you find a bug or if you develop additional features for it, I would be glad to hear about it and even incorporate them in the latest release. But be warned that I have limited time to answer technical questions. They will not be ignored but put into a FIFO pipe and treated with a pretty low priority.
The development will continue since there are still important features that are missing;
- Support for the RPI camera module
- Support for newer releases of Matlab
If you like RPIt you can send me an email saying how fantastic you found this work (I'm kidding).
If you REALLY like RPIt, you may even consider to financially support it. The money collected will be invested to develop research and educational applications based on this project.
Professor at University of Strasbourg, France.