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

1 次查看(过去 30 天)
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?

采纳的回答

Josh Chen
Josh Chen 2022-9-9
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 个评论
Jesús Jover
Jesús Jover 2022-9-12
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specialized Messages 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by