From 99c0a953387f8d2c5dc2ed4ef3c9e6f858ae3e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ellensohn?= Date: Fri, 18 Aug 2023 09:36:33 +0200 Subject: [PATCH] update --- src/rmp220_middleware.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/rmp220_middleware.cpp b/src/rmp220_middleware.cpp index 3d889cf..5b5d52c 100644 --- a/src/rmp220_middleware.cpp +++ b/src/rmp220_middleware.cpp @@ -105,9 +105,21 @@ private: } }; +std::shared_ptr node; // Declare the node as a global variable + +void signal_handler(int signum) { + (void)signum; + RCLCPP_INFO(node->get_logger(), "Received Ctrl+C. Shutting down..."); + rclcpp::shutdown(); +} + int main(int argc, char * argv[]) { rclcpp::init(argc, argv); auto node = std::make_shared(); + + // Register the Ctrl+C signal handler + signal(SIGINT, signal_handler); + rclcpp::spin(node); rclcpp::shutdown(); return 0;