Not able to run multiple node scripts at once

3 views (last 30 days)
Hello all,
Recently, I discovered the ROS toolbox of Matlab. I like the working principle of ROS so it was very interesting for me to combine this with matlab scripts.
However, I face problems when trying to run multiple scripts as separate nodes ont he same host. If ROS is directly used in Ubuntu from the terminal. Then infinite nodes can be ran by opening new terminals and run rosrun. But in matlab there is only one terminal. So if I execute a first node then I am not able anymore to execute another script as a node. I tried to put them all into one script but when executing this script, the second program waits for the first to finish. The only thing I want here is multiple matlab scripts which can run in parallel as nodes under one host while publishing and subscribing. To provide an example, I want a Monte Carlo localization script and a collision avoidance script to run seperatly on a remote robot.
Is there anyone who can help me with this?
Regards,
Matthias
  1 Comment
Matthias De Ryck
Matthias De Ryck on 5 Mar 2019
Just found out that it is possible to just open multiple Matlab windows, initialize to the same rosmaster and run the scripts. Everything works fine then. However this is not a very clean solution. A roslaunch file in matlab would be nice. A possibility to put matlab files into a catkin package, and run the nodes from a .launch file would also be nice. Anyone who has experience with this?
I did it with Python and C++ but not yet with matlab.

Sign in to comment.

Accepted Answer

Cam Salzberger
Cam Salzberger on 6 Mar 2019
Hello Matthias,
I am a little confused about exactly what it is you are trying to do. In general, ROS nodes (and publishers and subscribers) in MATLAB are non-blocking. So unlike rosrun, which will make your terminal unusable until you Ctrl+C to end the executible, you can allow nodes, publishers, and subscribers to operate in the background of a single MATLAB session simultaneously.
There are a couple of workflows you could be doing that are blocking, though other workflows can take their place. If you are using the receive function with a subscriber to extract the messages, that will block until a new message is received. Instead, you can assign a callback to the subscriber to operate on received messages in the background. You may also be using a pattern where you publish messages in a loop. This is fine if the only program you are looking to run is using that same loop, but like any other MATLAB program, will block you from running anything else until that program completes. If you are looking for a way to periodically publish messages and still have something else run, I would suggest using a timer to publish in the background.
I'm sure you have found it, but I just wanted to make sure you saw that you can create multiple nodes individually, and don't need to depend on the global node created when you use rosinit. Just make use of the "Core" object to create a master if needed, and the "Node" object to create the node.
Hope that helps clarify some things.
-Cam
  1 Comment
Matthias De Ryck
Matthias De Ryck on 9 Mar 2019
Hello,
Thank you for the answer. I think it was just a kind of misunderstanding from my side about the functionalities of this toolbox. But I think I get it now. Thanks for the help.
Kind regards,
Matthias

Sign in to comment.

More 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!