Skip to content

Commit

Permalink
Shutdown explicitly while existing (#623)
Browse files Browse the repository at this point in the history
Signed-off-by: ChenYing Kuo <[email protected]>
(cherry picked from commit 550ef7b)
  • Loading branch information
evshary authored and mergify[bot] committed Dec 24, 2024
1 parent 0edc014 commit ece5898
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ros_gz_sim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions ros_gz_sim/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<depend>libgflags-dev</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>rcpputils</depend>
<depend>std_msgs</depend>

<depend>gz_math_vendor</depend>
Expand Down
4 changes: 4 additions & 0 deletions ros_gz_sim/src/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <gz/transport/Node.hh>

#include <rclcpp/rclcpp.hpp>
#include <rcpputils/scope_exit.hpp>
#include <std_msgs/msg/string.hpp>

// ROS interface for spawning entities into Gazebo.
Expand Down Expand Up @@ -135,6 +136,9 @@ int main(int _argc, char ** _argv)
ros2_node->declare_parameter("P", static_cast<double>(0));
ros2_node->declare_parameter("Y", static_cast<double>(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()) {
Expand Down

0 comments on commit ece5898

Please sign in to comment.