Enable ROS 2 Time Model Stepping for Deployed Nodes
You can enable a deployed ROS 2 node to execute based on the time published on the
/clock topic on a ROS 2 network. To deploy a ROS 2 node from
Simulink®, see Generate a Standalone ROS 2 Node from Simulink.
When you enable ROS 2 time model stepping, the deployed node executes when the published ROS 2 time is a multiple of the base rate of the model. To enable model stepping based on ROS 2 time:
On the Apps tab, under Control Systems, click Robot Operating System 2 (ROS 2).
In the Robot Operating System 2 (ROS 2) dialog box that opens up, select
Robot Operating System 2 (ROS 2)from the ROS Network drop-down. This opens up the ROS tab in the toolstrip which shows the specified ROS Network in the Connect section.
In the Prepare section under ROS tab, click Hardware Settings to open the model configuration parameters dialog box. Under Target Hardware resources > ROS 2 time, select Enable ROS 2 time model stepping.
To specify a topic to publish a notification when the model executes, check the
Enable notification after step check box, and use the
Notification topic (default is
Subscribe to the
topic to get a message every time the ROS 2 time is published. The ROS 2 node publishes a
std_msgs/String message type with a string containing a
'-' and the model name
+ros2time_test, for example). A
'+' indicates the
model was stepped. A
'-' indicates the published ROS 2 time was not a
multiple of the base rate of the model.
After enabling model stepping and setting a notification topic, you can re-build and deploy your model. When starting the ROS 2 node, the model waits for the ROS 2 time to be published.