Why does the Simulink Time not match ROS time in co-simulation?

10 views (last 30 days)
I need a way to match Simulink time to ROS time for my co-simulation. The joystick commands I send via Simulink match ROS time in real-time exactly, but the Simulink clock time is of course important for all kinds of timing in the model. I don’t think the model is too large or complex to be slowing everything down since when I run it using a Simulink plant model, everything is super fast. Now I wish to simulate a few things that need precise time matching.
Could you please help me to figure out why the ROS model is slow? And perhaps how to solve this issue?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Dec 2021
In the first step, it can be useful to make a Simulink Profile Analysis. In this case, a large amount of time is used to publish the message to "/waypoint_array" topic. Since the message type "sensor_msgs/MarkerArray" associated with this topic is always a large message, it is expected to be slow compared with publish blocks publishing simple messages (e.g. std_msgs/Float64). 
Based on the description, you are trying to co-simulate your Simulink model with Gazebo world (co-simulate in a sense of matching Simulink simulation time with Gazebo time). If that's the case, consider using Gazebo Pacer block. This block will synchronize the simulation times between Gazebo and Simulink. An example can be found here. Note that this block requires Robotics System Toolbox.
Besides, you mentioned real-time in your description. If that is a concern, then you can have a look into the deployment workflow. With "ROS Time Model Stepping" enabled, the generated code from the Simulink model shares the same time as ROS time. 
You can also check if you try to send messages too frequently. Using a pulse generator block connected to an enabled subsystem enables to pace message publishing to be more efficient.

More Answers (0)


No tags entered yet.


Community Treasure Hunt

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

Start Hunting!