From 1b24c9c56684ef2022208005f09972ab6ee98b96 Mon Sep 17 00:00:00 2001 From: cyy_mac Date: Sat, 28 Mar 2026 04:46:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=9C=8D=E5=8A=A1=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E7=9B=B8=E6=9C=BA=E6=9B=9D=E5=85=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../armor_yolo_detector_node.hpp | 2 ++ .../src/armor_yolo_detector_node.cpp | 17 +++++++++-------- .../ros2_hik_camera/src/hik_camera_node.cpp | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/rm_auto_aim/armor_yolo_detect/include/armor_yolo_detect/armor_yolo_detector_node.hpp b/src/rm_auto_aim/armor_yolo_detect/include/armor_yolo_detect/armor_yolo_detector_node.hpp index 892056d..33b8ff6 100644 --- a/src/rm_auto_aim/armor_yolo_detect/include/armor_yolo_detect/armor_yolo_detector_node.hpp +++ b/src/rm_auto_aim/armor_yolo_detect/include/armor_yolo_detect/armor_yolo_detector_node.hpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -95,6 +96,7 @@ private: rclcpp::Subscription::SharedPtr cam_info_sub_; rclcpp::Publisher::SharedPtr armors_pub_; rclcpp::Publisher::SharedPtr marker_pub_; + rclcpp::Publisher::SharedPtr auto_exposure_pub_; rclcpp::Service::SharedPtr set_mode_srv_; // Image transport for debug diff --git a/src/rm_auto_aim/armor_yolo_detect/src/armor_yolo_detector_node.cpp b/src/rm_auto_aim/armor_yolo_detect/src/armor_yolo_detector_node.cpp index 50ddb40..44a5c51 100644 --- a/src/rm_auto_aim/armor_yolo_detect/src/armor_yolo_detector_node.cpp +++ b/src/rm_auto_aim/armor_yolo_detect/src/armor_yolo_detector_node.cpp @@ -118,6 +118,10 @@ ArmorYoloDetectorNode::ArmorYoloDetectorNode(const rclcpp::NodeOptions& options) marker_pub_ = this->create_publisher("armor_detector/marker", 10); + // Auto exposure publisher + auto_exposure_pub_ = + this->create_publisher("auto_exposure/set_exposure", 10); + // Debug debug_ = this->declare_parameter("debug", false); debug_log_interval_frames_ = @@ -1000,14 +1004,11 @@ double ArmorYoloDetectorNode::computeBrightnessInRois( } void ArmorYoloDetectorNode::callSetExposureService(double exposure_time) { - // Set exposure time via parameter - camera driver should subscribe to this parameter - // or this node should be in same container with camera driver to share parameter - auto result = this->set_parameter(rclcpp::Parameter("exposure_time", static_cast(exposure_time))); - if (result.successful) { - FYT_DEBUG("armor_yolo_detect", "Set exposure time to {:.1f}", exposure_time); - } else { - FYT_WARN("armor_yolo_detect", "Failed to set exposure time: {}", result.reason); - } + // Publish exposure time to camera driver via topic + std_msgs::msg::Float32 msg; + msg.data = exposure_time; + auto_exposure_pub_->publish(msg); + FYT_DEBUG("armor_yolo_detect", "Auto exposure set exposure_time: {:.1f}", exposure_time); } } // namespace armor_yolo_detect diff --git a/src/rm_hardware_driver/ros2_hik_camera/src/hik_camera_node.cpp b/src/rm_hardware_driver/ros2_hik_camera/src/hik_camera_node.cpp index c70542d..84b8c09 100644 --- a/src/rm_hardware_driver/ros2_hik_camera/src/hik_camera_node.cpp +++ b/src/rm_hardware_driver/ros2_hik_camera/src/hik_camera_node.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -65,6 +66,20 @@ public: // Heartbeat heartbeat_ = fyt::HeartBeatPublisher::create(this); + // Auto exposure subscriber - receives target exposure time from armor detector + auto_exposure_sub_ = this->create_subscription( + "auto_exposure/set_exposure", rclcpp::SensorDataQoS(), + [this](const std_msgs::msg::Float32::SharedPtr msg) { + if (msg->data > 0) { + std::lock_guard lock(camera_mutex_); + exposure_time_ = static_cast(msg->data); + if (camera_handle_ != nullptr) { + (void)MV_CC_SetFloatValue(camera_handle_, "ExposureTime", static_cast(exposure_time_)); + FYT_DEBUG("camera_driver", "Auto exposure set exposure_time: {}", exposure_time_); + } + } + }); + // Param set callback params_callback_handle_ = this->add_on_set_parameters_callback( std::bind(&HikCameraNode::parametersCallback, this, std::placeholders::_1)); @@ -482,6 +497,9 @@ private: // Heartbeat fyt::HeartBeatPublisher::SharedPtr heartbeat_; + // Auto exposure subscriber + rclcpp::Subscription::SharedPtr auto_exposure_sub_; + // Params int frame_rate_{210}; int exposure_time_{5000};