Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds a new /reboot service to allow restarting the ZED camera on failure, with support for both USB and GMSL inputs.
- Registers the reboot service in
initServices - Implements camera restart logic (
restartCamera,threadFunc_zedRestart) and synchronization helpers (guardDataThread,releaseDataThread) - Updates grab and sensor threads to pause during camera reboot
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| zed_camera_component_main.cpp | Added reboot service, restart logic, synchronization, and callback |
| zed_camera_component.hpp | Declared new methods, members, and service pointer for reboot |
| sl_types.hpp | Added rebootSrvPtr typedef |
Comments suppressed due to low confidence (3)
zed_components/src/zed_camera/include/zed_camera_component.hpp:1017
- [nitpick] The name
mSrvReboot(service name) is ambiguous next tomRebootSrv(service pointer). Rename it tomSrvRebootNamefor consistency with other service name members.
const std::string mSrvReboot = "reboot";
zed_components/src/zed_camera/include/zed_camera_component.hpp:44
- [nitpick] New methods (
guardDataThread,releaseDataThread,restartCamera,threadFunc_zedRestart,callback_reboot) lack comments. Please add Doxygen or inline documentation explaining their purpose and usage.
void guardDataThread();
zed_components/src/zed_camera/src/zed_camera_component_main.cpp:294
- The new
/rebootservice andrestartCameralogic are not covered by existing tests. Consider adding unit or integration tests for both successful and failure reboot scenarios.
srv_name = srv_prefix + mSrvReboot;
| // Wait until camera has been closed by reboot service call | ||
| mRebootCondVar.wait(lock, [&]() { return !mCameraRebooting; }); | ||
|
|
||
| if (mRestartThread.joinable()) { |
There was a problem hiding this comment.
Joining the restart thread while holding mRebootMutex can lead to deadlocks or block other camera threads. Consider moving the join() call outside the locked section or unlocking before joining.
| if (mRestartThread.joinable()) { | |
| bool shouldJoin = mRestartThread.joinable(); | |
| lock.unlock(); | |
| if (shouldJoin) { |
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment otherwise it will be automatically closed in 5 days |
|
Keep alive |
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment otherwise it will be automatically closed in 5 days |
|
To be merged... |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| RCLCPP_INFO(get_logger(), "=== RESTARTING CAMERA ==="); | ||
|
|
||
| // Wait longer for GMSL camera connection | ||
| int camera_timeout_sec = sl_tools::isZEDX(mCamRealModel) ? 15: mCamTimeoutSec; |
There was a problem hiding this comment.
The magic number 15 should be defined as a named constant (e.g., ZEDX_CAMERA_TIMEOUT_SEC) to improve code maintainability and make the special timeout value for ZEDX cameras more explicit.
| mConnStatus = mZed->open(mInitParams); | ||
|
|
||
| if (mConnStatus == sl::ERROR_CODE::SUCCESS) { | ||
| DEBUG_STREAM_COMM("Opening successfull"); |
There was a problem hiding this comment.
There's a typo in the debug message: 'successfull' should be 'successful'.
| DEBUG_STREAM_COMM("Opening successfull"); | |
| DEBUG_STREAM_COMM("Opening successful"); |
| int camera_timeout_sec = sl_tools::isZEDX(mCamRealModel) ? 15: mCamTimeoutSec; | ||
|
|
||
|
|
||
| while (1) { |
There was a problem hiding this comment.
Use while (true) instead of while (1) for better readability and to follow modern C++ best practices.
| while (1) { | |
| while (true) { |
|
|
||
| rclcpp::sleep_for(std::chrono::seconds(camera_timeout_sec)); | ||
| } | ||
| return false; |
There was a problem hiding this comment.
The return false; statement on line 3381 is unreachable code because the infinite while (1) loop on line 3329 only exits via return statements inside the loop.
| return false; |
|
|
||
| // If reboot thread is waiting and no threads are accessing ZED, notify it | ||
| if (mCameraRebooting && activeUsers == 0) { | ||
| mRebootCondVar.notify_all(); |
There was a problem hiding this comment.
The indentation is inconsistent here. The code inside the if statement has extra spaces that don't match the project's indentation style.
| mRebootCondVar.notify_all(); | |
| mRebootCondVar.notify_all(); |
| std::lock_guard<std::mutex> lock(mRebootMutex); | ||
| mCameraRebooting = false; |
There was a problem hiding this comment.
The indentation is inconsistent here. The code inside the scope has extra spaces that don't match the project's indentation style.
| std::lock_guard<std::mutex> lock(mRebootMutex); | |
| mCameraRebooting = false; | |
| std::lock_guard<std::mutex> lock(mRebootMutex); | |
| mCameraRebooting = false; |
| std::lock_guard<std::mutex> lock(mRebootMutex); | ||
| mCameraRebooting = true; |
There was a problem hiding this comment.
The indentation is inconsistent here. The code inside the scope has extra spaces that don't match the project's indentation style.
| std::lock_guard<std::mutex> lock(mRebootMutex); | |
| mCameraRebooting = true; | |
| std::lock_guard<std::mutex> lock(mRebootMutex); | |
| mCameraRebooting = true; |
| std::lock_guard<std::mutex> lock(mRebootMutex); | ||
| mCameraRebooting = true; | ||
| } | ||
|
|
||
| // Wait for all threads to stop using camera | ||
| { | ||
| std::unique_lock<std::mutex> lock(mRebootMutex); | ||
| mRebootCondVar.wait(lock, [&]() { return activeUsers == 0; }); |
There was a problem hiding this comment.
The indentation is inconsistent here. The code inside the scope has extra spaces that don't match the project's indentation style.
| std::lock_guard<std::mutex> lock(mRebootMutex); | |
| mCameraRebooting = true; | |
| } | |
| // Wait for all threads to stop using camera | |
| { | |
| std::unique_lock<std::mutex> lock(mRebootMutex); | |
| mRebootCondVar.wait(lock, [&]() { return activeUsers == 0; }); | |
| std::lock_guard<std::mutex> lock(mRebootMutex); | |
| mCameraRebooting = true; | |
| } | |
| // Wait for all threads to stop using camera | |
| { | |
| std::unique_lock<std::mutex> lock(mRebootMutex); | |
| mRebootCondVar.wait(lock, [&]() { return activeUsers == 0; }); |
| } | ||
|
|
||
| // Mark that this thread is using the camera | ||
| ++activeUsers; |
There was a problem hiding this comment.
The indentation is inconsistent here. This line has extra spaces that don't match the surrounding code's indentation style.
| ++activeUsers; | |
| ++activeUsers; |
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment otherwise it will be automatically closed in 5 days |
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment otherwise it will be automatically closed in 5 days |
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment otherwise it will be automatically closed in 5 days |
Add /reboot service to restart camera on failure. Support USB and GMSL.
Please note that GMSL reboot impacts all connected cameras.