diff --git a/.gitignore b/.gitignore index 3405a278..ae088307 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ bazel-* +**/__pycache__/ # User-specified configuration /bazel_ros2_rules/user.bazelrc diff --git a/drake_ros_examples/examples/hydroelastic/CMakeLists.txt b/drake_ros_examples/examples/hydroelastic/CMakeLists.txt index 7aa4b0a6..db27452e 100644 --- a/drake_ros_examples/examples/hydroelastic/CMakeLists.txt +++ b/drake_ros_examples/examples/hydroelastic/CMakeLists.txt @@ -16,3 +16,9 @@ install(FILES hydroelastic.rviz DESTINATION share/${PROJECT_NAME}/hydroelastic/ ) + +install( + DIRECTORY launch + DESTINATION share/${PROJECT_NAME} + FILES_MATCHING PATTERN "*_launch.py" +) diff --git a/drake_ros_examples/examples/hydroelastic/README.md b/drake_ros_examples/examples/hydroelastic/README.md index 7e07fb0b..5122d46d 100644 --- a/drake_ros_examples/examples/hydroelastic/README.md +++ b/drake_ros_examples/examples/hydroelastic/README.md @@ -32,8 +32,13 @@ bazel run @ros2//:rviz2 -- -d `pwd`/examples/hydroelastic/hydroelastic.rviz # Using Colcon/CMake rviz2 -d `ros2 pkg prefix --share drake_ros_examples`/hydroelastic/hydroelastic.rviz ``` +Or use ROS 2 Launch: +```sh +# Using ROS 2 Launch (C++) +ros2 launch drake_ros_examples hydroelastic_cc_launch.py +``` -You can optionall enable visualizng the simulation with Meshcat. +You can optionally enable visualizng the simulation with Meshcat. ```bash # Using bazel diff --git a/drake_ros_examples/examples/hydroelastic/launch/hydroelastic_cc_launch.py b/drake_ros_examples/examples/hydroelastic/launch/hydroelastic_cc_launch.py new file mode 100644 index 00000000..a8a3be89 --- /dev/null +++ b/drake_ros_examples/examples/hydroelastic/launch/hydroelastic_cc_launch.py @@ -0,0 +1,23 @@ +import os + +from ament_index_python.packages import get_package_prefix +from ament_index_python.packages import get_package_share_directory +from launch import LaunchDescription +from launch.actions import ExecuteProcess + + +def generate_launch_description(): + rviz_config_file = os.path.join(get_package_share_directory('drake_ros_examples'), 'hydroelastic/hydroelastic.rviz') + + rviz_node = ExecuteProcess( + cmd=['rviz2', '-d', rviz_config_file], + output='screen' + ) + + hydroelastic_cpp_node = ExecuteProcess( + cmd=[os.path.join(get_package_prefix('drake_ros_examples'), 'lib', 'drake_ros_examples', 'hydroelastic')], + ) + return LaunchDescription([ + rviz_node, + hydroelastic_cpp_node, + ]) diff --git a/drake_ros_examples/examples/iiwa_manipulator/CMakeLists.txt b/drake_ros_examples/examples/iiwa_manipulator/CMakeLists.txt index 27ae8d96..4a9de9db 100644 --- a/drake_ros_examples/examples/iiwa_manipulator/CMakeLists.txt +++ b/drake_ros_examples/examples/iiwa_manipulator/CMakeLists.txt @@ -21,3 +21,9 @@ install( FILES iiwa_manipulator.rviz DESTINATION share/${PROJECT_NAME} ) + +install( + DIRECTORY launch + DESTINATION share/${PROJECT_NAME} + FILES_MATCHING PATTERN "*_launch.py" +) diff --git a/drake_ros_examples/examples/iiwa_manipulator/README.md b/drake_ros_examples/examples/iiwa_manipulator/README.md index ad8920c6..1e44ffc0 100644 --- a/drake_ros_examples/examples/iiwa_manipulator/README.md +++ b/drake_ros_examples/examples/iiwa_manipulator/README.md @@ -35,7 +35,13 @@ bazel run //examples/iiwa_manipulator:iiwa_manipulator # Python bazel run //examples/iiwa_manipulator:iiwa_manipulator_py ``` - +Or +```sh +# Using ROS 2 Launch (C++) +ros2 launch drake_ros_examples iiwa_manipulator_cc_launch.py +# or (Python) +ros2 launch drake_ros_examples iiwa_manipulator_py_launch.py +``` You should see the manipulation station with simple sinusoidal motion. **Note***: If you restart the simulation but not RViz, you should click RViz's diff --git a/drake_ros_examples/examples/iiwa_manipulator/launch/iiwa_manipulator_cc_launch.py b/drake_ros_examples/examples/iiwa_manipulator/launch/iiwa_manipulator_cc_launch.py new file mode 100644 index 00000000..6dedc738 --- /dev/null +++ b/drake_ros_examples/examples/iiwa_manipulator/launch/iiwa_manipulator_cc_launch.py @@ -0,0 +1,23 @@ +import os + +from ament_index_python.packages import get_package_prefix +from ament_index_python.packages import get_package_share_directory +from launch import LaunchDescription +from launch.actions import ExecuteProcess + + +def generate_launch_description(): + rviz_config_file = os.path.join(get_package_share_directory('drake_ros_examples'), 'iiwa_manipulator.rviz') + + rviz_node = ExecuteProcess( + cmd=['rviz2', '-d', rviz_config_file], + output='screen' + ) + + iiwa_manipulator_cpp_node = ExecuteProcess( + cmd=[os.path.join(get_package_prefix('drake_ros_examples'), 'lib', 'drake_ros_examples', 'iiwa_manipulator')], + ) + return LaunchDescription([ + rviz_node, + iiwa_manipulator_cpp_node, + ]) diff --git a/drake_ros_examples/examples/iiwa_manipulator/launch/iiwa_manipulator_py_launch.py b/drake_ros_examples/examples/iiwa_manipulator/launch/iiwa_manipulator_py_launch.py new file mode 100644 index 00000000..83c8cb98 --- /dev/null +++ b/drake_ros_examples/examples/iiwa_manipulator/launch/iiwa_manipulator_py_launch.py @@ -0,0 +1,23 @@ +import os + +from ament_index_python.packages import get_package_prefix +from ament_index_python.packages import get_package_share_directory +from launch import LaunchDescription +from launch.actions import ExecuteProcess + + +def generate_launch_description(): + rviz_config_file = os.path.join(get_package_share_directory('drake_ros_examples'), 'iiwa_manipulator.rviz') + + rviz_node = ExecuteProcess( + cmd=['rviz2', '-d', rviz_config_file], + output='screen' + ) + + iiwa_manipulator_py_node = ExecuteProcess( + cmd=[os.path.join(get_package_prefix('drake_ros_examples'), 'lib', 'drake_ros_examples', 'iiwa_manipulator.py')], + ) + return LaunchDescription([ + rviz_node, + iiwa_manipulator_py_node, + ]) diff --git a/drake_ros_examples/examples/multirobot/CMakeLists.txt b/drake_ros_examples/examples/multirobot/CMakeLists.txt index b0cf7b61..988efe9d 100644 --- a/drake_ros_examples/examples/multirobot/CMakeLists.txt +++ b/drake_ros_examples/examples/multirobot/CMakeLists.txt @@ -21,3 +21,9 @@ install( FILES multirobot.rviz DESTINATION share/${PROJECT_NAME} ) + +install( + DIRECTORY launch + DESTINATION share/${PROJECT_NAME} + FILES_MATCHING PATTERN "*_launch.py" +) diff --git a/drake_ros_examples/examples/multirobot/README.md b/drake_ros_examples/examples/multirobot/README.md index ae9211f4..63064683 100644 --- a/drake_ros_examples/examples/multirobot/README.md +++ b/drake_ros_examples/examples/multirobot/README.md @@ -39,6 +39,13 @@ bazel run //examples/multirobot:multirobot # Python bazel run //examples/multirobot:multirobot_py ``` +Or use ROS 2 Launch: +```sh +# Using ROS 2 Launch (C++) +ros2 launch drake_ros_examples multirobot_cc_launch.py +# or (Python) +ros2 launch drake_ros_examples multirobot_py_launch.py +``` You should observe a 5 x 5 array of manipulators flopping about under the influence of gravity. diff --git a/drake_ros_examples/examples/multirobot/launch/multirobot_cc_launch.py b/drake_ros_examples/examples/multirobot/launch/multirobot_cc_launch.py new file mode 100644 index 00000000..172ecb75 --- /dev/null +++ b/drake_ros_examples/examples/multirobot/launch/multirobot_cc_launch.py @@ -0,0 +1,24 @@ +import os + +from ament_index_python.packages import get_package_prefix +from ament_index_python.packages import get_package_share_directory +from launch import LaunchDescription +from launch.actions import ExecuteProcess + + +def generate_launch_description(): + rviz_config_file = os.path.join(get_package_share_directory('drake_ros_examples'), 'multirobot.rviz') + + rviz_node = ExecuteProcess( + cmd=['rviz2', '-d', rviz_config_file], + output='screen' + ) + + multirobot_cpp_node = ExecuteProcess( + cmd=[os.path.join(get_package_prefix('drake_ros_examples'), 'lib', 'drake_ros_examples', 'multirobot')], + ) + + return LaunchDescription([ + rviz_node, + multirobot_cpp_node, + ]) diff --git a/drake_ros_examples/examples/multirobot/launch/multirobot_py_launch.py b/drake_ros_examples/examples/multirobot/launch/multirobot_py_launch.py new file mode 100644 index 00000000..1df77c18 --- /dev/null +++ b/drake_ros_examples/examples/multirobot/launch/multirobot_py_launch.py @@ -0,0 +1,24 @@ +import os + +from ament_index_python.packages import get_package_prefix +from ament_index_python.packages import get_package_share_directory +from launch import LaunchDescription +from launch.actions import ExecuteProcess + + +def generate_launch_description(): + rviz_config_file = os.path.join(get_package_share_directory('drake_ros_examples'), 'multirobot.rviz') + + rviz_node = ExecuteProcess( + cmd=['rviz2', '-d', rviz_config_file], + output='screen' + ) + + multirobot_py_node = ExecuteProcess( + cmd=[os.path.join(get_package_prefix('drake_ros_examples'), 'lib', 'drake_ros_examples', 'multirobot.py')], + ) + + return LaunchDescription([ + rviz_node, + multirobot_py_node, + ])