@@ -137,6 +137,7 @@ DriverNode::DriverNode(const rclcpp::NodeOptions & node_options)
137137 this ->declare_parameter (" user_config_path" , " path_default" );
138138 this ->declare_parameter (" cmdline_input_bd_code" , " 000000000000001" );
139139 this ->declare_parameter (" lvx_file_path" , " /home/livox/livox_test.lvx" );
140+ this ->declare_parameter (" connect_timeout_s" , 10.0 );
140141
141142 this ->get_parameter (" xfer_format" , xfer_format);
142143 this ->get_parameter (" multi_topic" , multi_topic);
@@ -174,6 +175,40 @@ DriverNode::DriverNode(const rclcpp::NodeOptions & node_options)
174175
175176 if ((read_lidar->InitLdsLidar (user_config_path))) {
176177 DRIVER_INFO (*this , " Init lds lidar success!" );
178+
179+ // Watchdog: if no lidar contacts us within connect_timeout_s, the
180+ // hardware is unreachable. Shut down so the node can be respawned.
181+ double connect_timeout_s;
182+ this ->get_parameter (" connect_timeout_s" , connect_timeout_s);
183+ Lds* lds = lddc_ptr_->lds_ ;
184+ watchdog_timer_ = this ->create_wall_timer (
185+ std::chrono::duration<double >(connect_timeout_s),
186+ [this , lds, connect_timeout_s]() {
187+ watchdog_timer_->cancel (); // one-shot
188+ bool any_connected = false ;
189+ for (uint32_t i = 0 ; i < kMaxSourceLidar ; i++) {
190+ if (lds->lidars_ [i].lidar_type != 0 &&
191+ lds->lidars_ [i].connect_state .load (std::memory_order_acquire)
192+ != kConnectStateOff ) {
193+ any_connected = true ;
194+ break ;
195+ }
196+ }
197+ if (!any_connected) {
198+ RCLCPP_FATAL (this ->get_logger (),
199+ " No lidar connected within %.1f s — hardware unreachable or "
200+ " not responding on the network. Shutting down for respawn." ,
201+ connect_timeout_s);
202+ // Escalating shutdown in a detached thread so the timer callback
203+ // returns immediately: SIGTERM first (gives rclcpp a chance to
204+ // clean up), then SIGKILL after 5 s to guarantee the process exits.
205+ std::thread ([]() {
206+ raise (SIGTERM );
207+ std::this_thread::sleep_for (std::chrono::seconds (5 ));
208+ raise (SIGKILL );
209+ }).detach ();
210+ }
211+ });
177212 } else {
178213 DRIVER_ERROR (*this , " Init lds lidar fail!" );
179214 }
0 commit comments