Simulink and ROS2 - How to dynamically adjust the number of simulated systems to the number of robots
4 次查看(过去 30 天)
显示 更早的评论
Hello,
In ROS2, I have a dynamic number of robots which I would like to connect to the controllers that are running in Simulink. While it is possible to create a static Simulink model with the needed number of systems, I would like to have a MATLAB script that dynamically adjusts the number of systems in the model.
Another option would be to run the same system with parameters in parallel in the following way:
model = 'model_name';
load_system(model);
simIn(1:num_robots-1) = Simulink.SimulationInput(model);
for idx = 1:num_robots-1
simIn(idx) = simIn(idx).setVariable('var',var);
... % do for every variable needed
simIn(idx) = simIn(idx).setBlockParameter([model '/subscriber/Subscribe'],'Topic',['/robot' num2str(idx) '/topicName']);
...% do for every publisher/subscriber block
end
simOut = parsim(simIn);
However, if there are errors in one of the models, every other model keeps running and it is more difficult to get everything working right now. This could also caused because of some compatibility issues between the current ROS2 version of MATLAB and ROS2-Foxy, which I am using right now. Also, if there are errors, the "matlabprefs.mat" file gets corrupted and needs to be deleted before running the script again.
So, another idea would be to create a temporary model and use the 'Reference Model' or 'Model' block to add them, after which you would have to set the parameters for the variables and subscribers/publishers like in the previous method. However, I don't think it is actually possible to change the subscriber and publisher blocks this way, as the Topic parameter does not show up in the Parameters list when inspecting the subsystem.
My question would be: Is there some way to change the subsriber/publisher topic value in a "Model" block or do I have to use the parallel computing method to dynamically adjust the number of simulated systems?
0 个评论
回答(1 个)
Alvaro
2022-11-28
If you have already set up your system using parsim, then you could set StopOnError to 'on' which should stop the simulations if an error is encountered.
Alternatively, you could set a mask on a reference subsystem to promote certain block parameters. See the example here:
https://www.mathworks.com/help/simulink/ug/parameter-promotion.html
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Publishers and Subscribers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!