Calling C++ and/or Python Custom Libraries in Simulink

1 view (last 30 days)
Hello everyone,
I am currently working on a project with a UR10e (robotic arm) from the company Universal Robots. To control it, I would like to use Simulinks socket connection and the predefined TCP/IP interface of the robot called RTDE (for interested perople: ). While doing so, I found a working C++ library that also brings Python bindings (Project site: and Github: ) which seems to be working perfectly fine, since both the C++ examples and even a call from Matlab to the Python libraries (see: ) seems to be working (I noticed some issues when it comes to error handling, but let's neglect that for the moment).
Set Up:
I am working on a 64bit Windows 10 Pro system with Matlab 2021a and MingW 9.0.0
Related topics:
The C++/Python library I am trying to use has many intenal functions. Starting with sending initial files to the robot and also the whole TCP/IP communication, which is not well documented and still not completely understood by me. It is very easy to write a c++/python/matlab code for reading the data of the robot and sending back commands when using the libraries functionality, even for a person like me who is not that versatile in c or c++.
I would therefore like to have a Simulink project with a fixed, discrete step size solver that runs a program/function in each time step to read the data into Simulink such that I can work with it and later on send it back using another program/function. The program/function should call the Python/C++ library.
I understood, that Simulink can not simply generate C code when there is C++ or Python code in form of a Matlab-function block and that the usage of coder.extrinsic is at some point necessary, but I am still curious if there is some way of achieving what I would like to have.
I also read through the .mex file thread but have to admit that I don't completely understand their usage. For the topics of using Python or c++ libraries this might be true also, but I can not say that for sure, since all attempts with ry.[function] and coder.extrinsic('function') either failed in the code generation or binding process (especially when I tried to call a constructor in Python). I have not tried the C++ approaches since I didn't understand how to do that and I didn't find similar approaches.
Problems with the library might be, that the library includes a communication frequency, while simulink has it's own solver and the tcp/ip connection, that is somehow already implemented in Simulink but maybe in another way. (The library uses the boost library for this).
Is it possible to use either a whole Python or C++ library in Simulink or call programs that are written in these languages and which are calling these libraries and generate a simulink block that is being executed in each time step and that is still suitable for code generation? This also includes calling constructors in both languages.
I would have really liked to present you some code, but I after a few useless attempts I am now just trying to find out if what I am trying to do is even possible.
Thank you for reading this and also thank you in advance for any useful hint.
  1 Comment
Maximilian Becker
Maximilian Becker on 24 Jun 2021
Edited: Maximilian Becker on 24 Jun 2021
I discarded this approach and am now trying to implement the functionality of those libraries directly into Simulink.
This includes desktop real-time approaches for TCP/IP communication and message packaging. For further information:

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!