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