ROS: runNode and stopNode within a Simulink node

2 次查看(过去 30 天)
Hi,
is it possible to start and stop another ROS node within my own Simulink node?

回答(1 个)

Cam Salzberger
Cam Salzberger 2020-7-14
编辑:Cam Salzberger 2020-7-14
Hey Markus,
Generally the best way is to have the stop condition built into the node you want to stop, and signal it from the Simulink node. You could use a publisher/subscriber pair to send a signal to the other node to stop itself. Or set a parameter that the other node checks to stop itself. Either of those would probably work better than a service call, since that requires a response from the node with the server.
If you are running in simulation (not codegen) mode, and the node you want to stopis a deployed Simulink node on other hardware, you could potentially use a MATLAB Function block to use rosdevice, to call stopNode. But that's a heck of a workaround. There are also a few workarounds to make system calls from Simulink, I believe, so you could potentially kill processes of non-MATLAB/Simulink nodes.
Starting nodes is probably similar - system calls for non-MATLAB nodes. I'm not sure if there is a way to start a Simulink model from another Simulink model - model reference wouldn't work since it is implemented as one node at the top level. There are probably options for starting another model/function without being blocking (e.g. using a single-shot timer from a MATLAB Function block), and simulation mode probably opens up more options than codegen mode.
Hope this gives you some ideas.
-Cam

类别

Help CenterFile Exchange 中查找有关 ROS 2 Network Connection and Exploration 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by