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

3 views (last 30 days)
Hello everyone,
Background:
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: https://www.universal-robots.com/articles/ur/interface-communication/real-time-data-exchange-rtde-guide/ ). While doing so, I found a working C++ library that also brings Python bindings (Project site: https://sdurobotics.gitlab.io/ur_rtde/introduction/introduction.html and Github: https://gitlab.com/sdurobotics/ur_rtde ) which seems to be working perfectly fine, since both the C++ examples and even a call from Matlab to the Python libraries (see: https://sdurobotics.gitlab.io/ur_rtde/guides/guides.html ) 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:
Problem:
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).
Question:
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.
Note:
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:
https://de.mathworks.com/matlabcentral/answers/864025-simulink-for-real-time-control-of-a-robot-via-tcp-ip?s_tid=prof_contriblnk

Sign in to comment.

Answers (0)

Categories

Find more on Publishers and Subscribers in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!