ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Node stuck at launching when launch with use_sim_time

asked 2022-12-27 14:39:38 -0500

sdu568 gravatar image

updated 2022-12-27 14:46:11 -0500

Publisher Node

import rclpy
from rclpy.node import Node

from std_msgs.msg import String

class MinimalPublisher(Node):

    def __init__(self):
    self.publisher_ = self.create_publisher(String, 'topic', 10)
    timer_period = 0.5  # seconds
    self.timer = self.create_timer(timer_period, self.timer_callback)
    self.i = 0

    def timer_callback(self):
    msg = String() = 'Hello World: %d' % self.i
    self.get_logger().info('Publishing: "%s"' %
    # t  =

    # self.get_logger().info('The current time is "%s"' % t.to_msg() )
    self.i += 1

def main(args=None):

    minimal_publisher = MinimalPublisher()


    # Destroy the node explicitly
    # (optional - otherwise it will be done automatically
    # when the garbage collector destroys the node object)

if __name__ == '__main__':

Launch File

import launch
import launch_ros.actions
from launch.substitutions import LaunchConfiguration
def generate_launch_description():

    use_sim_time = LaunchConfiguration('use_sim_time', default='true')
    return launch.LaunchDescription([
        parameters=[{'use_sim_time': use_sim_time}],),

Platform Ubuntu 20, Galactic

Problem Something I find strange. In my launch file, my talker node works as expected when I don't set 'use_sim_time'. However, once I add the 'use_sim_time' into the launch file. My talker seems stuck during the initalizing stage of launching.

Thus, I am wondering what could cause it go wrong?

Below is what I see in my console when I turn on the console when launching with use_sim_time

shouyu@shouyu-Nitro-AN515-55:~/ros2_ws$ . install/setup.bash 
shouyu@shouyu-Nitro-AN515-55:~/ros2_ws$ ros2 launch py_launch_example
[INFO] [launch]: All log files can be found below /home/shouyu/.ros/log/2022-12-27-15-38-19-846893-shouyu-Nitro-AN515-55-93514
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [talker-1]: process started with pid [93516]

Global variable

shouyu@shouyu-Nitro-AN515-55:~/ros2_ws$ env | grep ROS



edit retag flag offensive close merge delete


By the way, below is my global variable

shouyu@shouyu-Nitro-AN515-55:~/ros2_ws$ env | grep ROS ROS_VERSION=2 ROS_PYTHON_VERSION=3 ROS_LOCALHOST_ONLY=0 ROS_DISTRO=galactic

sdu568 gravatar image sdu568  ( 2022-12-27 14:41:58 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2022-12-27 23:02:53 -0500

tfoote gravatar image

You do not mention any other part of your system. The most likely cause is that there is no source of a clock message. And without a clock message time is not advancing as as such your timer callback will never be invoked.

You can read about the design of simulated time here:

The most common sources of simulated time are a simulator like Gazebo or rosbag when playing back data.

edit flag offensive delete link more


I see. I thought that by default, /clock will be published by ROS.

My problem is solved when I launch a Gazebo simulation. Thank you very much!

sdu568 gravatar image sdu568  ( 2022-12-28 07:37:23 -0500 )edit

Just one more question. Is it always a bad idea if I put 'use_sim_time'=true for all my node in ROS2?

sdu568 gravatar image sdu568  ( 2022-12-28 10:19:36 -0500 )edit

Just one more question. In the document

”If the time on the clock jumps backwards, a callback handler will be invoked and be required to complete before any calls to the ROS time abstraction report the new time. Calls that come in before that must block. The developer has the opportunity to register callbacks with the handler to clear any state from their system if necessary before time will be in the past“”

After looking at this issue, Can I assume that the callback handler has already been implemented in rclcpp and rcpy? Thank you once again!

sdu568 gravatar image sdu568  ( 2022-12-28 12:49:36 -0500 )edit

Question Tools

1 follower


Asked: 2022-12-27 14:39:38 -0500

Seen: 37 times

Last updated: Dec 27 '22