Select Node name created by ROS Toolbox on Simulink at master connection

3 views (last 30 days)
Hello everyone,
I'm using a Simulink model to connect with a ROS master and process data sent over topics. Moreover, I want to use batchsim, from MATLAB Parallel Computing Toolbox to run such models in a parallel and independent way. The problem is that, when I try to lauch different simulations on different batch jobs, the first worker running Simulink model creates a ROS node using <modelName>_<random#> name. But, next workers try to create a ROS node with the same name, causing an error. Seems that MATLAB Parallel Computing Toolbox stablish the random number generation at same seed for all created workers, causing that <random#> on name is the same for all worker.
The question is: there is a way to select the node name that Simulink with ROS Toolbox will use to create the node in the ROS master, in order to have each Simulink simulation using a unique node name?

Accepted Answer

Josh Chen
Josh Chen on 9 Sep 2022
Hello Jesús,
As you may've discovered, the name of ROS node created from a Simulink model is auto generated with the pattern as <modelName>_<random#>, this cannot be customized.
One workaround to avoid generating the same random number (used as part of node name) with batchsim could be to control the random number generator seed before running the model each time.
To do this, you can run rng with different seed in the PreSimFcn defined for Simulink.SimulationInput:
function in = createSimIn()
numSims = 10;
in(1:numSims) = Simulink.SimulationInput('vdp');
for i = 1: numSims
in(i).PreSimFcn = @(~) myPreSimFcn(i);
where myPreSimFcn is defined as:
function myPreSimFcn(seed)
This should allow you to generate different random number during batchsim.
Hope this helps,
  1 Comment
Jesús Jover
Jesús Jover on 12 Sep 2022
Thanks a lot!. I will use it. Anyway, 5 number random part in node name seems quite few in some applications, as probability to generate the same number for different simulations is high.

Sign in to comment.

More Answers (0)


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!