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;