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

Node stuck at launching when launch with use_sim_time

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

sdu568 gravatar image

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

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

```

edit retag flag offensive close merge delete

Comments

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 -0600 )edit

1 Answer

Sort by » oldest newest most voted
1

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

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: https://design.ros2.org/articles/cloc...

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

edit flag offensive delete link more

Comments

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 -0600 )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 -0600 )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, https://github.com/ros2/rclcpp/issues.... 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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 100 times

Last updated: Dec 27 '22