Raspberry Pi Simulink Coder target (RPIt)

(Redirected from RPIt)
Jump to: navigation, search

News

  • July 9th 2014: add a bloc 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.

Brief presentation

Big picture


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.

The Simulink block-diagram is automatically converted into C code, transferred to the RPI and compiled directly on the RPI (no cross-compilation). Then, the executable is launched on the RPI and a TCPIP connection is started between Simulink and the RPI. The executable running on the RPI 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 RPI 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. The EV3 brick is connected to the RPI with USB. The dialog between the RPI 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 RPI). IMU devices, like the MPU9150, directly connected to the RPI 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.

Features

  • 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.

Requirements

  • Supported operating systems
    • Windows XP, 7, 8, 32 or 64 bits
    • Mac OSX (tested on Lion with Matlab 2014a)
    • Linux (tested on Ubuntu 12.04 LTS 64 bits, Kubuntu 14.04 LTS 64 bits and Debian Wheezy 64 bits with Matlab 2010b, 2012a and 2014a)
  • Supported Matlab releases
    • 2010b, 2010b SP1, 2010b SP2
    • 2011a
    • 2012a (the last one with the old user interface)
    • 2014a
  • Required Matlab toolboxes
  • Supported target platforms
    • Raspberry Pi model B 512 MB, Raspbian distribution
    • Any Debian-based machine (Debian, Ubuntu, Mint, …) 32 or 64 bits, ARM or x86

Devices compatibility

EV3 brick by Lego
NXT brick by Lego
MinIMU-9 v2 by Pololu
MPU9150 by Drotek
MPU9150 by SparkFun

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). The maximal achievable frequency varies from one device to another. It is specified in the help section of the SImulink block.

Note that currently 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.

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).

Wiring of the MinIMU-9 v2 (click to expand)

You will find here the source of the test programs used to communicate with these devices from the target.


Typical setup examples

EV3 connected to an Ubuntu PC running Matlab 2014a. In this setup host and target are equal. The IP address of the target is 127.0.0.1. (click to expand)
NXT connected to an Ubuntu PC running Matlab 2014a. In this setup host and target are equal. The IP address of the target is 127.0.0.1. (click to expand)
EV3 connected to a Raspberry Pi. The RPI is powered by the EV3. The host is a Windows 7 PC running Matlab 2012a. Communication between PC (host) and RPI (target) by WiFi. This setup is fully wireless. (click to expand)


Performances

  • 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 EV3 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.
  • Communication with the NXT has a roundtrip below 2ms due to the use of a dedicated NXTOSEK real-time driver.
  • Max sampling rate (with devices that stand it): 1kHz

Quick start

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.

Prerequisite

You should have an up-to-date Raspbian installation with the build-essential package installed in order to be able to compile the embedded coder generated C code. To do that, issue this command on the RPI:

sudo apt-get install build-essential


Screencast

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: [1]

Installation

  1. Download the latest version of RPIt.
  2. Extract it somewhere (there is no need to have a path with no blanks).
  3. Start Matlab. On some versions combinations of Matlab/Windows, you must run Matlab in administrator mode (right-click, run as administrator).
  4. In Matlab, change the current directory to the "rpit" folder, the root folder of the extracted package.
  5. 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).
  6. Verify that your RPI 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.
  7. Note the IP address of the RPI. It will be asked by the setup process.
  8. In Matlab's command window type "setup".
  9. The RPI will be accessed with a passwordless ssh connection. Private and public keys must be generated and the public key will be uploaded to the RPI. 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.
  10. Enter the RPI 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.
  11. When this last step is over, everything should run without interaction.
  12. 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, RPI configurations will only be made once.

Test

  1. Go into the "demo" folder.
  2. Go into the "jitter" folder.
  3. In the menu "Simulation" select "Configuration parameters..."
  4. Select the item "Real-Time Workshop" (2010b) or "Code Generation" (starting from 2012a).
  5. 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.
  6. Select the "Interface" item.
  7. In the "MEX-file arguments:" field type the IP address of the RPI with quotes around ('xxx.yyy.zzz.vvv').
  8. Hit the "Apply" button.
  9. Verify that the RPI IP address is reachable.
  10. Select the Simulink window for the "jitter" model.
  11. Hit [CRTL-B].
  12. Wait for the procedure to complete.
  13. 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 RPI. If successful, this last step validates the installation.

Downloads

License

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

Releases

Version number Release date Download link Release notes Author
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.
Jacques Gangloff
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.
Jacques Gangloff
2.22 June 6th, 2014 RPIt-2.22.zip (7MB) Add 2014a support.
Minor bugfixes.
Jacques Gangloff
2.21 Apr. 7th, 2014 RPIt-2.21.zip (7MB) MPU9150: fix magnetometer axis.
MPU9150: fix gyro scale initialization.
Setup: add R2011a support.
Jacques Gangloff
2.20 Feb. 4th, 2014 RPIt-2.20.zip (7.35MB) Initial public release Jacques Gangloff

Additional code

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.

Applications

Related educational projects

One of the main goal of this package is education. We are currently developing cheap lab experiments using RPIt for our undergraduate students.

Related research projects

This software was used by Xavier Weber for his PhD thesis on active damping of cable-driven parallel manipulators. Below a short video illustrating his work. This work will be presented at IROS 2014 [1].

Direct link: [2]

  1. 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.

Support

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.

Support RPIt



Jacques GANGLOFF

Professor at University of Strasbourg, France.

Control, Vision and Robotics Lab

Views
Actions
Research
Education
Join us
People
Personal tools