How can I specify publish and subscribe rate for ros topics using Simulink?

I have 2 robots exchanging position data. I am using ROS and SIMULINK subscriber and publisher blocks for each robot to receive and send position information, The subscriber keeps reading the same position over data and over again. How can I gt the publish and subscribe rates perfectly synced.

 Akzeptierte Antwort

Sebastian Castro
Sebastian Castro am 28 Mai 2015
You can use an Enabled Subsystem which is controlled via the "IsNew" output of the subscriber block. Basically, the code inside this enabled subsystem (including any publishing you may want to do) will execute only if "IsNew" is true at that particular time step.
The following example in the documentation shows you how to do this:
- Sebastian

3 Kommentare

Thank you for your response. I am using enabled subsystem, This is the example that helped me get started with my project. I want to be able to control how often the IsNew output is true or atleast get the messages to come at a constant rate. Sometimes it takes upto 20s of the simulation time before a new position is published.
Ultimately I want to compare position values the robots exchange to those generated from a state space model of a system
I see... so what you want is for your model to not run as fast as possible, but rather to be closer to real time. You can (almost) sync up the Simulink model's execution to real-time using the block below:
Does this come closer to what you were looking for?
- Sebastian
Thank you very much, it totally worked!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by