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 example of PackageMap and an ament resource #269

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion drake_ros_examples/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
py_test(
load("@ros2//:ros_py.bzl", "ros_py_test")

ros_py_test(
name = "drake_ros_py_import_test",
srcs = ["test/drake_ros_py_import_test.py"],
main = "test/drake_ros_py_import_test.py",
Expand All @@ -17,3 +19,13 @@ py_library(
"@rules_python//python/runfiles",
],
)

ros_py_test(
name = "parse_ros_model_test",
srcs = ["test/parse_ros_model_test.py"],
main = "test/parse_ros_model_test.py",
# TODO(eric.cousineau): Use a non-test resource and enable this test.
tags = ["manual"],
data = ["@ros2//:rviz_default_plugins_share"],
deps = ["@drake//bindings/pydrake"],
)
13 changes: 13 additions & 0 deletions drake_ros_examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ add_subdirectory(examples/rs_flip_flop)
if(BUILD_TESTING)
find_package(ament_cmake_clang_format REQUIRED)
find_package(ament_cmake_cpplint REQUIRED)
find_package(ament_cmake_test REQUIRED)
find_package(Python3 COMPONENTS Interpreter)

macro(add_python_test test_name test_file)
ament_add_test("${test_name}"
COMMAND
"${Python3_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/${test_file}"
"--junit-xml=${AMENT_TEST_RESULTS_DIR}/drake_ros_examples/${test_name}.xml"
"--junit-prefix=drake_ros_examples")
endmacro()

add_python_test(parse_ros_model_test test/parse_ros_model_test.py)

ament_clang_format(CONFIG_FILE .clang-format)
ament_cpplint()
Expand Down
1 change: 1 addition & 0 deletions drake_ros_examples/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ROS_PACKAGES = DRAKE_ROS_REQUIRED_PACKAGES + [
"rclcpp",
"rclpy",
"ros2cli_common_extensions",
"rviz_default_plugins",
"rviz2",
"tf2_ros",
"tf2_ros_py",
Expand Down
30 changes: 30 additions & 0 deletions drake_ros_examples/test/parse_ros_model_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Shows how to locate and parse a simple model from the ROS 2 ament index.

For more details on the ament index, please see:
https://github.com/ament/ament_cmake/blob/master/ament_cmake_core/doc/resource_index.md
""" # noqa

import sys

import pytest

from pydrake.multibody.parsing import Parser
from pydrake.multibody.plant import MultibodyPlant


def test_parse_model():
plant = MultibodyPlant(time_step=0.0)
parser = Parser(plant)
# TODO(eric.cousineau): Incorporate `AMENT_PREFIX_PATH` into
# PackageMap::PopulateFromRosPackagePath().
parser.package_map().PopulateFromEnvironment("AMENT_PREFIX_PATH")
# TODO(eric.cousineau): Use a non-test resource.
parser.AddModelsFromUrl(
"package://rviz_default_plugins/test_meshes/test.urdf"
)
plant.Finalize()


if __name__ == '__main__':
sys.exit(pytest.main(sys.argv))