Select Node name created by ROS Toolbox on Simulink at master connection
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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?
Some resources I previously checked: ROS Simulink Interaction - MATLAB & Simulink - MathWorks España
0 Commenti
Risposta accettata
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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Specialized Messages in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!