hii, in ROS toolbox can I use single ROS Publish block to connect multiple ROS Subscribe blocks??

2 views (last 30 days)
Screenshot (20).png

Accepted Answer

Cam Salzberger
Cam Salzberger on 4 Mar 2019
Yes, ROS works by publishing a message on a topic, and all subscribers to that topic will receive the message. So using one publish block to get a single message out to multiple subscribe blocks should work fine.
However, you cannot use one publish block to send two different messages at the same timestep. Each publish block expects a message input of a particular format, and you cannot combine multiple messages of the same type together and give that to the publish block. If you need to get two messages published in the same timestep, you can add a second publish block.
Note though that a single message sent on a topic goes to all of the subscribers on that topic. So if you give message1 to publisherA on /my_topic, and message2 to publisherB also on /my_topic, then any and all subscribers to /my_topic will receive both message1 and message2.
However, Simulink uses discrete timesteps. At any given timestep, the output of a subscribe block will be the latest message that has been received by the subscriber. So if two messages come in to the subscriber with no timestep between them, then only the most recent message will be output.
Also, there will be some delay between the publishing of a message and the receiving and processing of the message. So a message definitely won't be received in the same timestep as it was sent, and it may not be received for a short time after that (dependent on clock time, not simulation time). I'm sure you were just using that model for demonstrative purposes, but bear in mind that communication within a single model is much more easily achieved by connecting the ports than by using ROS.
-Cam

More Answers (0)

Categories

Find more on Publishers and Subscribers in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!