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

Shutdown explicitly while existing (backport #623) #679

Merged
merged 1 commit into from
Dec 24, 2024
Merged
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
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
Loading