How to define ROS Publisher and Subscriber Rate in Simulink

Hi
I'm using Simulink to interact with ROS. I used publisher and subscriber in simulink model, but I can't specify its publishing rate and subscribing rate. I created a signal with 100Hz. The published topic only has 60 Hz rate.Also, there is a topic with 100Hz, while the received message only has 1Hz. I want to sync published topic with input signal. And also sync subscribed data with topic rate.
Any advice appreciated.

 Accepted Answer

You can use MATLAB timers to create "soft" real-time periodic behavior, which uses your CPU clock to handle timing. I'd look at this example:
EDIT: Sorry, the above is for MATLAB -- didn't notice your Simulink tag. You can download this block which slows down your model to the same "soft" (CPU clock) real-time.
- Sebastian

3 Comments

Thanks for reply. I didn't want to slow down simulink model simulation rate. Instead, I want to speed up ROS publish rate. The discrete signal in model is 50Hz. After it published as topics, it update in 8 Hz. I want it publish at 50Hz. I tried "Real-time Pacer". It can't change publish rate.
So, is the problem that the model runs slower than you want to? In that case, you can take advantage of code generation to get some speedup.
First, you can try changing the simulation mode of the model to Accelerator mode. [ See doc link ]
If that doesn't give you sufficient speedup, and you have access to Embedded Coder, you could try generating a standalone C++ ROS node from the model. [ See doc link ]
If this is still not fast enough, you may want to look at your model to see what the performance bottlenecks are.
- Sebastian
Hello Sebastian,
I encountered same porblem in ROS-Simulink interaction, where I have three Subsriber-Publisher pairs in my simulink program. I noticed each Subsriber-Publiser pair took around at least 5 ms processing time, which requries at least 15 ms for proicessing just the subscribing and publishing tasks with three pairs. This make my Simulink imposible to run at 100 Hz. Is there is a way to work around this?

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!