diff --git a/ros_gz_sim/CMakeLists.txt b/ros_gz_sim/CMakeLists.txt index e61622f9..dc8deb03 100644 --- a/ros_gz_sim/CMakeLists.txt +++ b/ros_gz_sim/CMakeLists.txt @@ -13,6 +13,7 @@ endif() find_package(ament_cmake REQUIRED) find_package(rclcpp REQUIRED) find_package(rclcpp_components REQUIRED) +find_package(rcpputils REQUIRED) find_package(std_msgs REQUIRED) find_package(gz_math_vendor REQUIRED) @@ -47,6 +48,7 @@ target_link_libraries(create gz-math::core gz-msgs::core gz-transport::core + rcpputils::rcpputils ) add_executable(remove src/remove.cpp) diff --git a/ros_gz_sim/package.xml b/ros_gz_sim/package.xml index d4247f7a..14be978f 100644 --- a/ros_gz_sim/package.xml +++ b/ros_gz_sim/package.xml @@ -23,6 +23,7 @@ libgflags-dev rclcpp rclcpp_components + rcpputils std_msgs gz_math_vendor diff --git a/ros_gz_sim/src/create.cpp b/ros_gz_sim/src/create.cpp index 83aca0af..a647e7d0 100644 --- a/ros_gz_sim/src/create.cpp +++ b/ros_gz_sim/src/create.cpp @@ -31,6 +31,7 @@ #include #include +#include #include // ROS interface for spawning entities into Gazebo. @@ -135,6 +136,9 @@ int main(int _argc, char ** _argv) ros2_node->declare_parameter("P", static_cast(0)); ros2_node->declare_parameter("Y", static_cast(0)); + auto always_shutdown = rcpputils::make_scope_exit( + []() {rclcpp::shutdown();}); + // World std::string world_name = ros2_node->get_parameter("world").as_string(); if (world_name.empty() && !FLAGS_world.empty()) {