Ask Your Question

Pete B's profile - activity

2020-05-21 08:49:06 -0500 received badge  Famous Question (source)
2019-08-26 06:25:48 -0500 received badge  Famous Question (source)
2019-08-22 11:48:19 -0500 received badge  Notable Question (source)
2019-08-22 10:01:07 -0500 commented answer can `ros2 topic list` poll periodically?

It seems I was mis-remembering how the --spinp-time option worked. When I looked at this a few months ago, I must have

2019-08-21 13:19:05 -0500 received badge  Popular Question (source)
2019-08-16 15:37:30 -0500 asked a question can `ros2 topic list` poll periodically?

can `ros2 topic list` poll periodically? Maybe I imagined this - but was there once a way to run ros2 topic list and not

2019-07-18 10:44:39 -0500 received badge  Nice Question (source)
2019-07-18 10:44:36 -0500 received badge  Favorite Question (source)
2019-07-16 11:26:44 -0500 received badge  Student (source)
2019-05-26 22:45:59 -0500 received badge  Famous Question (source)
2019-03-28 13:21:36 -0500 received badge  Notable Question (source)
2019-02-07 23:52:14 -0500 received badge  Popular Question (source)
2019-02-07 15:45:11 -0500 received badge  Enthusiast
2019-02-06 18:01:06 -0500 marked best answer Any way to see IO sooner with OnProcessIO event in ROS2 Launch Description?

Background

Starting with a counter node that looks something like this:

import rclpy
import time

if __name__ == "__main__":
    rclpy.init()
    node = rclpy.create_node("counter_node")
    for n in range(10):
        print(n)
        time.sleep(1.0)

If I launch the node using ros2 run my_package counter_node I'll see it output 0, 1, 2, 3, 4, etc. . . about once per second before exiting.

If I launch the same node using ros2 launch like this:

launch_description = LaunchDescription([
    Node(package="my_package", node_executable="counter_node"),
    RegisterEventHandler(
        OnProcessIO(on_stdout=lambda info: print(info.text))
    )
])

launch_service = LaunchService()
launch_service.include_launch_description(launch_description)
launch_service.run()

Then the standard out is a little different. I see nothing for 10 seconds, and when my process ends I see all the numbers 0, 1, 2, 3, 4, etc. . . all printed at once. It looks like all the stdout is getting buffered up and printed once the node exits.

If I change my counter node to do

for n in range(10):
    print(n)
    sys.stdout.flush()  # <-- Added this
    time.sleep(1.0)

and then run it with launch_service.run(), I get the once-per-second output again

My Question

Is there a way to get the ros2 run my_package counter_node behavior with launch_service.run without modifying the counter node? I'm I overlooking something way simpler?

ros2 run is pretty easy to understand. It's using popen to launch my node, and then polling it with communicate. ros2 launch's plumbing is a bit harder for me to follow. Is there a way to reach down inside and have it poll the counter_node's IO a little more often so I can see the standard-out a little closer to when it happens without having to modify the node I'm launching? The examples above are deliberately simplified. In my actual application, it's not feasible to add sys.stdout.flush() everywhere

2019-02-06 16:04:41 -0500 marked best answer ros2 optionally launch node with no arguments

I have a node that takes zero or one argument. I want to use ros2 launch arguments to pass either zero or one argument to the the launch file which will then get passed down to the node. I'm having a bit of trouble with the 'zero' argument case.

LaunchDescription([
    launch.actions.DeclareLaunchArgument(
        "my_param",
        default_value=[""],  # default_value=[], has the same problem
        description="optional parameter"
    ),
    launch_ros.actions.Node(
        package="my_package",
        node_executable="my_node",
        arguments=[launch.substitutions.LaunchConfiguration("my_param")]
    ),
])

When I do this, I can run my launch file with my_param:=foo and foo will get passed down to my node. No problem

When I run my launch file without any arguments, my_node still behaves like it got a positional argument - a single empty string. This is not how I intended to launch the node.

What do I need to do to make my_node behave like it got no arguments when I don't pass any arguments to launch?

The current behavior makes sense - the LaunchConfiguration substitution is getting resolved to an empty string and is getting put into the node's arguments array. What I need is a way to substitute the whole 'arguments' list passed to the node instead of substituting a single element in the list, but the Node object really wants a list of substitutions

2019-02-06 16:04:41 -0500 received badge  Scholar (source)
2019-02-06 16:02:51 -0500 edited question ros2 optionally launch node with no arguments

ros2 optionally launch node with no arguments I have a node that takes zero or one argument. I want to use ros2 launch

2019-02-06 15:48:31 -0500 edited question ros2 optionally launch node with no arguments

ros2 optionally launch node with no arguments I have a node that takes zero or one argument. I want to use ros2 launch

2019-02-06 15:42:04 -0500 edited question ros2 optionally launch node with no arguments

ros2 optionally launch node with no arguments I have a node that takes zero or one argument. I want to use ros2 launch

2019-02-06 15:30:04 -0500 edited question ros2 optionally launch node with no arguments

ros2 optionally launch node with no arguments I have a node that takes zero or one argument. I want to use ros2 launch

2019-02-06 15:30:04 -0500 received badge  Editor (source)
2019-02-06 15:28:45 -0500 asked a question ros2 optionally launch node with no arguments

ros2 optionally launch node with no arguments I have a node that takes zero or one argument. I want to use ros2 launch

2019-02-06 15:25:19 -0500 asked a question ros2 LaunchArgument pass zero (default) or one arguments

ros2 LaunchArgument pass zero (default) or one arguments I have a node that takes zero or one argument. I want to use r

2019-01-16 10:27:33 -0500 commented answer Any way to see IO sooner with OnProcessIO event in ROS2 Launch Description?

@William We're using python 3.5.2

2019-01-15 18:13:59 -0500 received badge  Notable Question (source)
2019-01-15 16:58:51 -0500 commented answer Any way to see IO sooner with OnProcessIO event in ROS2 Launch Description?

Maybe we have an old asyncio implementation. . .

2019-01-15 16:35:19 -0500 commented answer Any way to see IO sooner with OnProcessIO event in ROS2 Launch Description?

@William Things blow up down in osrf_pycommon: . . . File ".../osrf_pycommon/process_utils/async_execute_process_asyn

2019-01-15 15:27:12 -0500 received badge  Self-Learner (source)
2019-01-15 15:27:12 -0500 received badge  Teacher (source)
2019-01-15 15:07:37 -0500 edited answer Any way to see IO sooner with OnProcessIO event in ROS2 Launch Description?

This seems like a bit of a hack, but I can modify my launch file a little like this: def generate_launch_description():

2019-01-15 12:51:43 -0500 answered a question Any way to see IO sooner with OnProcessIO event in ROS2 Launch Description?

This seems like a bit of a hack, but I can modify my launch file a little like this: def generate_launch_description():

2019-01-15 12:31:39 -0500 received badge  Popular Question (source)
2019-01-15 11:13:06 -0500 received badge  Supporter (source)
2019-01-15 11:10:45 -0500 commented answer Any way to see IO sooner with OnProcessIO event in ROS2 Launch Description?

Thanks Tully - I want to try to do this without modifying the counter_node so that we can make this work for all nodes.

2019-01-14 23:29:25 -0500 asked a question Any way to see IO sooner with OnProcessIO event in ROS2 Launch Description?

Any way to see IO sooner with OnProcessIO event Background Starting with a counter node that looks something like this: