terminal outputs appear after KeyboardInterrupt
Hello, I am trying to complete a basic task. I starting a node with parameter file via launch file. When I run the node without launch file, it works fine and output can be seen on terminal. However when I run it via launch file, no output appears until I stop it with Ctrl + C.
My node:
#/usr/bin/env python3
import rclpy
def main():
rclpy.init()
hello_world = rclpy.create_node("hello_world")
hello_world.declare_parameter("freq", 1.0)
hello_world.declare_parameter("text", "Hello Param")
counter = 1
while rclpy.ok():
try:
rclpy.spin_once(
hello_world, timeout_sec=hello_world.get_parameter("freq").value)
except KeyboardInterrupt:
break
print(hello_world.get_parameter("text").value)
print(f"{counter}\n")
counter += 1
hello_world.destroy_node()
rclpy.shutdown()
if __name__ == "__main__":
main()
the launch file
#!/usr/bin/env python3
import os
from ament_index_python import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
dir_hello_world = get_package_share_directory("hello_world")
return LaunchDescription([
Node(
package="hello_world",
node_executable="hello_world",
node_name="text_counter",
parameters=[os.path.join(dir_hello_world, "hello_world.yaml")],
output="screen"
)
])