MATLAB Answers

ROS: runNode and stopNode within a Simulink node

6 views (last 30 days)
Markus Krovinovitsch
Markus Krovinovitsch on 14 Jul 2020
Edited: Cam Salzberger on 14 Jul 2020
Hi,
is it possible to start and stop another ROS node within my own Simulink node?

  0 Comments

Sign in to comment.

Answers (1)

Cam Salzberger
Cam Salzberger on 14 Jul 2020
Edited: Cam Salzberger on 14 Jul 2020
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

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!