From 6776bfc44e484ccdb1fc1f3f653544af3ee1de07 Mon Sep 17 00:00:00 2001 From: musyaree Date: Sat, 16 May 2026 03:26:47 +0700 Subject: [PATCH 1/2] fix: fix config overwrite and auto mode --- src/shisen_cpp/camera/node/camera_node.cpp | 35 +++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/shisen_cpp/camera/node/camera_node.cpp b/src/shisen_cpp/camera/node/camera_node.cpp index ef76059..5abfe7a 100644 --- a/src/shisen_cpp/camera/node/camera_node.cpp +++ b/src/shisen_cpp/camera/node/camera_node.cpp @@ -197,10 +197,12 @@ CaptureSetting CameraNode::on_configure_capture_setting( } if (new_capture_setting.temperature.is_not_empty()) { + video_capture->set(cv::CAP_PROP_AUTO_WB, 0); video_capture->set(cv::CAP_PROP_WB_TEMPERATURE, new_capture_setting.temperature); } if (new_capture_setting.exposure.is_not_empty()) { + video_capture->set(cv::CAP_PROP_AUTO_EXPOSURE, 1); video_capture->set(cv::CAP_PROP_EXPOSURE, new_capture_setting.exposure); } @@ -209,13 +211,30 @@ CaptureSetting CameraNode::on_configure_capture_setting( } } - // Get new capture setting from the camera - new_capture_setting.brightness = video_capture->get(cv::CAP_PROP_BRIGHTNESS); - new_capture_setting.contrast = video_capture->get(cv::CAP_PROP_CONTRAST); - new_capture_setting.saturation = video_capture->get(cv::CAP_PROP_SATURATION); - new_capture_setting.temperature = video_capture->get(cv::CAP_PROP_WB_TEMPERATURE); - new_capture_setting.exposure = video_capture->get(cv::CAP_PROP_EXPOSURE); - new_capture_setting.gain = video_capture->get(cv::CAP_PROP_GAIN); + // Get new capture setting from the camera if they were empty + if (new_capture_setting.brightness.is_empty()) { + new_capture_setting.brightness = video_capture->get(cv::CAP_PROP_BRIGHTNESS); + } + + if (new_capture_setting.contrast.is_empty()) { + new_capture_setting.contrast = video_capture->get(cv::CAP_PROP_CONTRAST); + } + + if (new_capture_setting.saturation.is_empty()) { + new_capture_setting.saturation = video_capture->get(cv::CAP_PROP_SATURATION); + } + + if (new_capture_setting.temperature.is_empty()) { + new_capture_setting.temperature = video_capture->get(cv::CAP_PROP_WB_TEMPERATURE); + } + + if (new_capture_setting.exposure.is_empty()) { + new_capture_setting.exposure = video_capture->get(cv::CAP_PROP_EXPOSURE); + } + + if (new_capture_setting.gain.is_empty()) { + new_capture_setting.gain = video_capture->get(cv::CAP_PROP_GAIN); + } return new_capture_setting; } @@ -229,6 +248,8 @@ void CameraNode::configure_capture_setting(const CaptureSetting & capture_settin void CameraNode::load_configuration(const std::string & path) { + RCLCPP_INFO_STREAM(node->get_logger(), "Loading configuration from: " << path); + nlohmann::json config; if (!jitsuyo::load_config(path, "capture_settings.json", config)) { throw std::runtime_error("Unable to open `" + path + "capture_settings.json`!"); From 821d444fa3cf004d1af22369e532430aa9173ce6 Mon Sep 17 00:00:00 2001 From: musyaree Date: Sat, 16 May 2026 03:27:12 +0700 Subject: [PATCH 2/2] fix: wait for camera to be ready --- src/shisen_cpp/node/shisen_cpp_node.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/shisen_cpp/node/shisen_cpp_node.cpp b/src/shisen_cpp/node/shisen_cpp_node.cpp index 438ab45..274d0bc 100644 --- a/src/shisen_cpp/node/shisen_cpp_node.cpp +++ b/src/shisen_cpp/node/shisen_cpp_node.cpp @@ -21,6 +21,7 @@ #include #include +#include namespace shisen_cpp { @@ -32,6 +33,17 @@ ShisenCppNode::ShisenCppNode(rclcpp::Node::SharedPtr node, const std::string & p auto image_provider = std::make_shared(options); auto camera_config_provider = std::make_shared(options); camera_node->set_provider(image_provider, camera_config_provider); + + for (int i = 0; i < 10; ++i) { + try { + camera_node->update(); + break; + } catch (const std::exception & e) { + RCLCPP_WARN(node->get_logger(), "Waiting for camera to be ready..."); + std::this_thread::sleep_for(100ms); + } + } + camera_node->load_configuration(path); node_timer = node->create_wall_timer(