Skip to content

Conversation

@mattrouss
Copy link

Add /reboot service to restart camera on failure. Support USB and GMSL.
Please note that GMSL reboot impacts all connected cameras.

@mattrouss mattrouss requested review from Myzhar and Copilot July 11, 2025 13:45
Copy link
Contributor

Copilot AI left a 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 to mRebootSrv (service pointer). Rename it to mSrvRebootName for 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 /reboot service and restartCamera logic 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()) {
Copy link

Copilot AI Jul 11, 2025

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.

Suggested change
if (mRestartThread.joinable()) {
bool shouldJoin = mRestartThread.joinable();
lock.unlock();
if (shouldJoin) {

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

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

@github-actions github-actions bot added the Stale label Aug 11, 2025
@Myzhar
Copy link
Member

Myzhar commented Aug 11, 2025

Keep alive

@github-actions github-actions bot removed the Stale label Aug 12, 2025
@github-actions
Copy link

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

@github-actions github-actions bot added the Stale label Sep 12, 2025
@Myzhar
Copy link
Member

Myzhar commented Sep 12, 2025

To be merged...

@Myzhar Myzhar requested a review from Copilot September 12, 2025 06:08
Copy link
Contributor

Copilot AI left a 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;
Copy link

Copilot AI Sep 12, 2025

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.

Copilot uses AI. Check for mistakes.
mConnStatus = mZed->open(mInitParams);

if (mConnStatus == sl::ERROR_CODE::SUCCESS) {
DEBUG_STREAM_COMM("Opening successfull");
Copy link

Copilot AI Sep 12, 2025

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'.

Suggested change
DEBUG_STREAM_COMM("Opening successfull");
DEBUG_STREAM_COMM("Opening successful");

Copilot uses AI. Check for mistakes.
int camera_timeout_sec = sl_tools::isZEDX(mCamRealModel) ? 15: mCamTimeoutSec;


while (1) {
Copy link

Copilot AI Sep 12, 2025

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.

Suggested change
while (1) {
while (true) {

Copilot uses AI. Check for mistakes.

rclcpp::sleep_for(std::chrono::seconds(camera_timeout_sec));
}
return false;
Copy link

Copilot AI Sep 12, 2025

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.

Suggested change
return false;

Copilot uses AI. Check for mistakes.

// If reboot thread is waiting and no threads are accessing ZED, notify it
if (mCameraRebooting && activeUsers == 0) {
mRebootCondVar.notify_all();
Copy link

Copilot AI Sep 12, 2025

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.

Suggested change
mRebootCondVar.notify_all();
mRebootCondVar.notify_all();

Copilot uses AI. Check for mistakes.
Comment on lines +4255 to +4256
std::lock_guard<std::mutex> lock(mRebootMutex);
mCameraRebooting = false;
Copy link

Copilot AI Sep 12, 2025

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.

Suggested change
std::lock_guard<std::mutex> lock(mRebootMutex);
mCameraRebooting = false;
std::lock_guard<std::mutex> lock(mRebootMutex);
mCameraRebooting = false;

Copilot uses AI. Check for mistakes.
Comment on lines +6667 to +6668
std::lock_guard<std::mutex> lock(mRebootMutex);
mCameraRebooting = true;
Copy link

Copilot AI Sep 12, 2025

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.

Suggested change
std::lock_guard<std::mutex> lock(mRebootMutex);
mCameraRebooting = true;
std::lock_guard<std::mutex> lock(mRebootMutex);
mCameraRebooting = true;

Copilot uses AI. Check for mistakes.
Comment on lines +6667 to +6674
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; });
Copy link

Copilot AI Sep 12, 2025

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.

Suggested change
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; });

Copilot uses AI. Check for mistakes.
}

// Mark that this thread is using the camera
++activeUsers;
Copy link

Copilot AI Sep 12, 2025

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.

Suggested change
++activeUsers;
++activeUsers;

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot removed the Stale label Sep 13, 2025
@github-actions
Copy link

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

@github-actions github-actions bot added the Stale label Oct 13, 2025
@Myzhar Myzhar removed the Stale label Oct 13, 2025
@github-actions
Copy link

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

@github-actions github-actions bot added Stale closed_for_stale Issue closed for inactivity labels Nov 13, 2025
@github-actions github-actions bot closed this Nov 19, 2025
@Myzhar Myzhar reopened this Nov 19, 2025
@github-actions github-actions bot removed closed_for_stale Issue closed for inactivity Stale labels Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants