Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple ROS Launch support. #287

Closed
wants to merge 3 commits into from

Conversation

tervay-bdai
Copy link

@tervay-bdai tervay-bdai commented Jul 10, 2023

Addresses #214, as it's important for us.

This is a simple implementation of ROS launch support. It creates an executable Python script that parses the given launch file and calls LaunchService().run() with it.

This does not support Python-based launch files, only XML and YAML, because I am not familiar enough with Python launch files to support that. (But would be happy to learn if pointed in the right direction.)

I am relatively new to custom Bazel rules/macros so there may be a better way you already had planned, and I'm happy to use that method if desired.


This change is Reviewable

Copy link
Collaborator

@adityapande-1995 adityapande-1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're running a sample launch file, it'd be nice to add some nontrivial nodes and check that everything is working. Lets include a talker and listener demo if possible ?

I'd like to make sure all the environment variables are inherited and work together.

bazel_ros2_rules/ros2/ros_launch.bzl Outdated Show resolved Hide resolved
@tervay-bdai tervay-bdai marked this pull request as draft July 12, 2023 14:59
@tervay-bdai
Copy link
Author

tervay-bdai commented Jul 12, 2023

Thanks for the tip; this uncovered issues I didn't catch with the previous log launches. It seems like there are some environment issues that I am not sure how to solve, since I don't thoroughly understand how the rules here work.

11:01 | ~/workspace/drake-ros/ros2_example_bazel_installed | $ bazel run //ros2_example_apps:example_launch_yaml
DEBUG: Rule 'ros2' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "7bd08a17ad5846c9b890c43f051ce61b6b353e4a2d444c62be8c533ddcd4b6aa"
DEBUG: Repository ros2 instantiated at:
  /home/jtervay/workspace/drake-ros/ros2_example_bazel_installed/WORKSPACE:78:13: in <toplevel>
Repository rule ros2_archive defined at:
  /home/jtervay/.cache/bazel/_bazel_jtervay/d46afbf710ac2d6d6949df3dfa5228cb/external/bazel_ros2_rules/ros2/defs.bzl:317:31: in <toplevel>
INFO: Analyzed target //ros2_example_apps:example_launch_yaml (44 packages loaded, 706 targets configured).
INFO: Found 1 target...
Target //ros2_example_apps:example_launch_yaml up-to-date:
  bazel-bin/ros2_example_apps/_example_launch_yaml_shim.py
  bazel-bin/ros2_example_apps/example_launch_yaml
INFO: Elapsed time: 55.473s, Critical Path: 0.01s
INFO: 2 processes: 1 internal, 1 linux-sandbox.
INFO: Build completed successfully, 2 total actions
INFO: Running command line: bazel-bin/ros2_example_apps/example_launch_yaml
Traceback (most recent call last):
  File "/home/jtervay/.cache/bazel/_bazel_jtervay/d46afbf710ac2d6d6949df3dfa5228cb/execroot/ros2_example_bazel_installed/bazel-out/k8-opt/bin/ros2_example_apps/example_launch_yaml.runfiles/ros2_example_bazel_installed/ros2_example_apps/example_launch_yaml_launch_script.py", line 9, in <module>
    ld = parser.parse_description(re)
  File "/home/jtervay/.cache/bazel/_bazel_jtervay/d46afbf710ac2d6d6949df3dfa5228cb/execroot/ros2_example_bazel_installed/bazel-out/k8-opt/bin/ros2_example_apps/example_launch_yaml.runfiles/ros2/archive/launch/lib/python3.10/site-packages/launch/frontend/parser.py", line 133, in parse_description
    actions = [self.parse_action(child) for child in entity.children]
  File "/home/jtervay/.cache/bazel/_bazel_jtervay/d46afbf710ac2d6d6949df3dfa5228cb/execroot/ros2_example_bazel_installed/bazel-out/k8-opt/bin/ros2_example_apps/example_launch_yaml.runfiles/ros2/archive/launch/lib/python3.10/site-packages/launch/frontend/parser.py", line 133, in <listcomp>
    actions = [self.parse_action(child) for child in entity.children]
  File "/home/jtervay/.cache/bazel/_bazel_jtervay/d46afbf710ac2d6d6949df3dfa5228cb/execroot/ros2_example_bazel_installed/bazel-out/k8-opt/bin/ros2_example_apps/example_launch_yaml.runfiles/ros2/archive/launch/lib/python3.10/site-packages/launch/frontend/parser.py", line 110, in parse_action
    return instantiate_action(entity, self)
  File "/home/jtervay/.cache/bazel/_bazel_jtervay/d46afbf710ac2d6d6949df3dfa5228cb/execroot/ros2_example_bazel_installed/bazel-out/k8-opt/bin/ros2_example_apps/example_launch_yaml.runfiles/ros2/archive/launch/lib/python3.10/site-packages/launch/frontend/expose.py", line 38, in instantiate_action
    raise RuntimeError('Unrecognized entity of the type: {}'.format(entity.type_name))
RuntimeError: Unrecognized entity of the type: node

If I run source /opt/ros/humble/setup.bash on a local ROS installation, it works, although I have no idea why:

11:02 | ~/workspace/drake-ros/ros2_example_bazel_installed | $ source /opt/ros/humble/setup.bash
11:04 | ~/workspace/drake-ros/ros2_example_bazel_installed | $ bazel run //ros2_example_apps:example_launch_yaml
INFO: Analyzed target //ros2_example_apps:example_launch_yaml (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //ros2_example_apps:example_launch_yaml up-to-date:
  bazel-bin/ros2_example_apps/_example_launch_yaml_shim.py
  bazel-bin/ros2_example_apps/example_launch_yaml
INFO: Elapsed time: 0.061s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/ros2_example_apps/example_launch_yaml
[INFO] [launch]: All log files can be found below /home/jtervay/.ros/log/2023-07-12-11-04-30-531282-jtervay-LT-768482
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [talker-1]: process started with pid [768745]
[INFO] [listener-2]: process started with pid [768747]
[talker-1] [INFO] [1689174271.563178985] [talker]: Publishing: 'Hello World: 1'
[listener-2] [INFO] [1689174271.564104305] [listener]: I heard: [Hello World: 1]

Guidance would be appreciated here.

Although, now that I think about it, this is probably an issue with the python script we are running to run the launch files, not with any of the rules themselves.

@adityapande-1995
Copy link
Collaborator

@tervay-bdai are you seeing the same error for both yaml and xml launch files ?

@tervay-bdai
Copy link
Author

Yes

@adityapande-1995
Copy link
Collaborator

Another point to note is that the yaml and xml "frontends" to ros launch internally use the python launch style, so ideally if you support yaml/xml ros launch, the python style should work as well.

@adityapande-1995
Copy link
Collaborator

Looks like we are missing python dependencies. I'm discussing how to add ros launch in a simpler way here : #214. Fixing the PYTHONPATH in the shim for ros2 command would solve most of our problems.

@tervay-bdai
Copy link
Author

Closing since it seems like upstream is working on this and doing it better than I would.

@tervay-bdai tervay-bdai closed this Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants