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

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Josh Chen
Josh Chen il 9 Set 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);
end
end
where myPreSimFcn is defined as:
function myPreSimFcn(seed)
rng(seed)
end
This should allow you to generate different random number during batchsim.
Hope this helps,
Thanks,
Josh
  1 Commento
Jesús Jover
Jesús Jover il 12 Set 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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by