Node stuck at launching when launch with use_sim_time
Publisher Node
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class MinimalPublisher(Node):
def __init__(self):
super().__init__('minimal_publisher')
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()
msg.data = 'Hello World: %d' % self.i
self.publisher_.publish(msg)
self.get_logger().info('Publishing: "%s"' % msg.data)
# t = self._clock.now()
# self.get_logger().info('The current time is "%s"' % t.to_msg() )
self.i += 1
def main(args=None):
rclpy.init(args=args)
minimal_publisher = MinimalPublisher()
rclpy.spin(minimal_publisher)
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
minimal_publisher.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
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([
launch_ros.actions.Node(
package='py_pubsub',
executable='talker',
name='talker',
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 my_script_launch.py
[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
ROS_VERSION=2
ROS_PYTHON_VERSION=3
ROS_LOCALHOST_ONLY=0
ROS_DISTRO=galactic
```
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