尝试修复相机报错
This commit is contained in:
@@ -9,3 +9,4 @@
|
|||||||
offsetY: 0
|
offsetY: 0
|
||||||
camera_name: "hik"
|
camera_name: "hik"
|
||||||
recording: false #是否录制
|
recording: false #是否录制
|
||||||
|
open_delay_ms: 2000 # Camera open delay after previous instance closed (ms)
|
||||||
|
|||||||
@@ -98,8 +98,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Watch dog timer (also handles initial open)
|
// Watch dog timer (also handles initial open)
|
||||||
|
// Add initial delay to allow previous camera instance to fully release resources
|
||||||
|
int open_delay_ms = this->declare_parameter("open_delay_ms", 1000);
|
||||||
timer_ = this->create_wall_timer(
|
timer_ = this->create_wall_timer(
|
||||||
std::chrono::milliseconds(1000), std::bind(&HikCameraNode::timerCallback, this));
|
std::chrono::milliseconds(open_delay_ms), std::bind(&HikCameraNode::timerCallback, this));
|
||||||
|
|
||||||
// Start capture thread
|
// Start capture thread
|
||||||
capture_thread_ = std::thread([this]() { this->captureLoop(); });
|
capture_thread_ = std::thread([this]() { this->captureLoop(); });
|
||||||
@@ -208,20 +210,29 @@ private:
|
|||||||
|
|
||||||
void timerCallback()
|
void timerCallback()
|
||||||
{
|
{
|
||||||
// Open camera
|
// Open camera with retry delay
|
||||||
while (!is_open_ && rclcpp::ok()) {
|
if (!is_open_) {
|
||||||
|
static int retry_count = 0;
|
||||||
if (!open()) {
|
if (!open()) {
|
||||||
FYT_ERROR("camera_driver", "open() failed");
|
retry_count++;
|
||||||
|
if (retry_count >= 3) {
|
||||||
|
FYT_ERROR("camera_driver", "open() failed {} times, will keep retrying", retry_count);
|
||||||
|
}
|
||||||
close();
|
close();
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
retry_count = 0;
|
||||||
|
is_open_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watchdog: no frames for too long => reconnect
|
// Watchdog: no frames for too long => reconnect
|
||||||
double dt = (this->now() - latest_frame_stamp_).seconds();
|
double dt = (this->now() - latest_frame_stamp_).seconds();
|
||||||
if (dt > 5.0) {
|
if (dt > 5.0) {
|
||||||
FYT_WARN("camera_driver", "Camera is not alive! lost frame for {:.2f} seconds", dt);
|
FYT_WARN("camera_driver", "Camera is not alive! lost frame for {:.2f} seconds, reconnecting...", dt);
|
||||||
close();
|
close();
|
||||||
|
is_open_ = false;
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user