-
Notifications
You must be signed in to change notification settings - Fork 276
Add reboot service #359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add reboot service #359
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()) { |
Copilot
AI
Jul 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"); |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; }); |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Add /reboot service to restart camera on failure. Support USB and GMSL.
Please note that GMSL reboot impacts all connected cameras.