Add Color AE ROI feature for 435le example nodes

This commit is contained in:
slz
2025-09-02 17:09:25 +08:00
committed by xiexun
parent 3622fbb09f
commit d657b3da47
4 changed files with 54 additions and 10 deletions
@@ -23,6 +23,7 @@ Once successfully started, the following menu will appear. Enter the correspondi
4. Disable camera streams 4. Disable camera streams
5. Get device info 5. Get device info
6. Show device status 6. Show device status
7. Set Color AE ROI
0. Exit 0. Exit
``` ```
@@ -117,6 +118,15 @@ ros2 topic echo /camera/device_status
--- ---
### 2.5 Set Color AE ROI
In data_param, the first value is the Left setting, the second value is the Right setting, the third value is the Top setting, and the fourth value is the Bottom setting.
```bash
ros2 service call /camera/set_color_ae_roi orbbec_camera_msgs/srv/SetArrays '{data_param: [0,1279,0,719]}'
```
---
## 3. Additional Features ## 3. Additional Features
### 3.1 Optimized Color Stream Latency ### 3.1 Optimized Color Stream Latency
@@ -1,6 +1,7 @@
#include <rclcpp/rclcpp.hpp> #include <rclcpp/rclcpp.hpp>
#include "orbbec_camera_msgs/srv/get_user_calib_params.hpp" #include "orbbec_camera_msgs/srv/get_user_calib_params.hpp"
#include "orbbec_camera_msgs/srv/set_user_calib_params.hpp" #include "orbbec_camera_msgs/srv/set_user_calib_params.hpp"
#include "orbbec_camera_msgs/srv/set_arrays.hpp"
#include "orbbec_camera_msgs/msg/device_status.hpp" #include "orbbec_camera_msgs/msg/device_status.hpp"
#include <orbbec_camera_msgs/srv/get_device_info.hpp> #include <orbbec_camera_msgs/srv/get_device_info.hpp>
#include <std_srvs/srv/set_bool.hpp> #include <std_srvs/srv/set_bool.hpp>
@@ -16,11 +17,13 @@ class CameraExampleNode : public rclcpp::Node {
get_params_client_ = this->create_client<orbbec_camera_msgs::srv::GetUserCalibParams>( get_params_client_ = this->create_client<orbbec_camera_msgs::srv::GetUserCalibParams>(
"/camera/get_user_calib_params"); "/camera/get_user_calib_params");
set_streams_client_ = this->create_client<std_srvs::srv::SetBool>("/camera/set_streams_enable"); set_streams_client_ = this->create_client<std_srvs::srv::SetBool>("/camera/set_streams_enable");
set_color_ae_roi_client_ = this->create_client<orbbec_camera_msgs::srv::SetArrays>(
"/camera/set_color_ae_roi");
get_device_info_client_ = get_device_info_client_ =
this->create_client<orbbec_camera_msgs::srv::GetDeviceInfo>("/camera/get_device_info"); this->create_client<orbbec_camera_msgs::srv::GetDeviceInfo>("/camera/get_device_info");
} }
// Feature 1a: Write camera parameters // Feature 1: Write camera parameters
void exampleWriteParams() { void exampleWriteParams() {
if (!set_params_client_->wait_for_service(2s)) { if (!set_params_client_->wait_for_service(2s)) {
RCLCPP_ERROR(this->get_logger(), "SetUserCalibParams service not available"); RCLCPP_ERROR(this->get_logger(), "SetUserCalibParams service not available");
@@ -59,7 +62,7 @@ class CameraExampleNode : public rclcpp::Node {
RCLCPP_INFO(this->get_logger(), "Set result: %s", result.get()->message.c_str()); RCLCPP_INFO(this->get_logger(), "Set result: %s", result.get()->message.c_str());
} }
// Feature 1b: Read camera parameters // Feature 2: Read camera parameters
void exampleReadParams() { void exampleReadParams() {
if (!get_params_client_->wait_for_service(2s)) { if (!get_params_client_->wait_for_service(2s)) {
RCLCPP_ERROR(this->get_logger(), "GetUserCalibParams service not available"); RCLCPP_ERROR(this->get_logger(), "GetUserCalibParams service not available");
@@ -94,13 +97,13 @@ class CameraExampleNode : public rclcpp::Node {
std::cout << std::endl; std::cout << std::endl;
} }
// Feature 2a: Enable camera streams // Feature 3: Enable camera streams
void exampleEnableStreams() { exampleSetStreamsEnable(true); } void exampleEnableStreams() { exampleSetStreamsEnable(true); }
// Feature 2b: Disable camera streams // Feature 4: Disable camera streams
void exampleDisableStreams() { exampleSetStreamsEnable(false); } void exampleDisableStreams() { exampleSetStreamsEnable(false); }
// Feature 3: Get device info // Feature 5: Get device info
void exampleGetDeviceInfo() { void exampleGetDeviceInfo() {
if (!get_device_info_client_->wait_for_service(2s)) { if (!get_device_info_client_->wait_for_service(2s)) {
RCLCPP_ERROR(this->get_logger(), "GetDeviceInfo service not available"); RCLCPP_ERROR(this->get_logger(), "GetDeviceInfo service not available");
@@ -130,7 +133,7 @@ class CameraExampleNode : public rclcpp::Node {
std::cout << "Hardware Version: " << res->info.hardware_version << std::endl; std::cout << "Hardware Version: " << res->info.hardware_version << std::endl;
} }
// Feature 4: Show device status // Feature 6: Show device status
void exampleShowdeviceStatus() { void exampleShowdeviceStatus() {
device_status_sub_ = this->create_subscription<orbbec_camera_msgs::msg::DeviceStatus>( device_status_sub_ = this->create_subscription<orbbec_camera_msgs::msg::DeviceStatus>(
"/camera/device_status", 10, "/camera/device_status", 10,
@@ -141,6 +144,31 @@ class CameraExampleNode : public rclcpp::Node {
} }
} }
// Feature 7: Set Color AE ROI
void exampleSetColorAERoi(float left, float right, float top, float bottom) {
if (!set_color_ae_roi_client_->wait_for_service(2s)) {
RCLCPP_ERROR(this->get_logger(), "SetColorAERoi service not available");
return;
}
auto req = std::make_shared<orbbec_camera_msgs::srv::SetArrays::Request>();
req->data_param = {left, right, top, bottom};
auto result = set_color_ae_roi_client_->async_send_request(req);
if (rclcpp::spin_until_future_complete(this->get_node_base_interface(), result) !=
rclcpp::FutureReturnCode::SUCCESS) {
RCLCPP_ERROR(this->get_logger(), "Failed to call SetColorAERoi");
return;
}
auto res = result.get();
if (res->success) {
RCLCPP_INFO(this->get_logger(), "SetColorAERoi success: %s", res->message.c_str());
} else {
RCLCPP_ERROR(this->get_logger(), "SetColorAERoi failed: %s", res->message.c_str());
}
}
private: private:
void exampleSetStreamsEnable(bool enable) { void exampleSetStreamsEnable(bool enable) {
if (!set_streams_client_->wait_for_service(2s)) { if (!set_streams_client_->wait_for_service(2s)) {
@@ -189,7 +217,7 @@ class CameraExampleNode : public rclcpp::Node {
rclcpp::Client<orbbec_camera_msgs::srv::GetUserCalibParams>::SharedPtr get_params_client_; rclcpp::Client<orbbec_camera_msgs::srv::GetUserCalibParams>::SharedPtr get_params_client_;
rclcpp::Client<std_srvs::srv::SetBool>::SharedPtr set_streams_client_; rclcpp::Client<std_srvs::srv::SetBool>::SharedPtr set_streams_client_;
rclcpp::Client<orbbec_camera_msgs::srv::GetDeviceInfo>::SharedPtr get_device_info_client_; rclcpp::Client<orbbec_camera_msgs::srv::GetDeviceInfo>::SharedPtr get_device_info_client_;
rclcpp::Client<orbbec_camera_msgs::srv::SetArrays>::SharedPtr set_color_ae_roi_client_;
rclcpp::Subscription<orbbec_camera_msgs::msg::DeviceStatus>::SharedPtr device_status_sub_; rclcpp::Subscription<orbbec_camera_msgs::msg::DeviceStatus>::SharedPtr device_status_sub_;
}; };
@@ -205,6 +233,7 @@ int main(int argc, char **argv) {
std::cout << "4. Disable camera streams\n"; std::cout << "4. Disable camera streams\n";
std::cout << "5. Get device info\n"; std::cout << "5. Get device info\n";
std::cout << "6. Show device status\n"; std::cout << "6. Show device status\n";
std::cout << "7. Set Color AE ROI\n";
std::cout << "0. Exit\n"; std::cout << "0. Exit\n";
std::cout << "Choose option: "; std::cout << "Choose option: ";
@@ -230,6 +259,12 @@ int main(int argc, char **argv) {
case 6: case 6:
node->exampleShowdeviceStatus(); node->exampleShowdeviceStatus();
break; break;
case 7:
float l, r, t, b;
std::cout << "Enter ROI (left right top bottom): ";
std::cin >> l >> r >> t >> b;
node->exampleSetColorAERoi(l, r, t, b);
break;
case 0: case 0:
rclcpp::shutdown(); rclcpp::shutdown();
return 0; return 0;
@@ -96,7 +96,6 @@ def generate_launch_description():
DeclareLaunchArgument('color_flip', default_value='false'), DeclareLaunchArgument('color_flip', default_value='false'),
DeclareLaunchArgument('color_mirror', default_value='false'), DeclareLaunchArgument('color_mirror', default_value='false'),
DeclareLaunchArgument('color_ae_roi_left', default_value='-1'), DeclareLaunchArgument('color_ae_roi_left', default_value='-1'),
DeclareLaunchArgument('color_ae_roi_left', default_value='-1'),
DeclareLaunchArgument('color_ae_roi_right', default_value='-1'), DeclareLaunchArgument('color_ae_roi_right', default_value='-1'),
DeclareLaunchArgument('color_ae_roi_top', default_value='-1'), DeclareLaunchArgument('color_ae_roi_top', default_value='-1'),
DeclareLaunchArgument('color_ae_roi_bottom', default_value='-1'), DeclareLaunchArgument('color_ae_roi_bottom', default_value='-1'),
@@ -175,8 +175,8 @@ def generate_launch_description():
DeclareLaunchArgument('angular_vel_cov', default_value='0.01'), DeclareLaunchArgument('angular_vel_cov', default_value='0.01'),
DeclareLaunchArgument('publish_tf', default_value='true'), DeclareLaunchArgument('publish_tf', default_value='true'),
DeclareLaunchArgument('tf_publish_rate', default_value='0.0'), DeclareLaunchArgument('tf_publish_rate', default_value='0.0'),
DeclareLaunchArgument('ir_info_url', default_value='file:///home/yalian/work/test.yaml'), DeclareLaunchArgument('ir_info_url', default_value=''),
DeclareLaunchArgument('color_info_url', default_value='file:///home/yalian/work/test.yaml'), DeclareLaunchArgument('color_info_url', default_value=''),
# Network device settings: default enumerate_net_device is set to true, which will automatically enumerate network devices # Network device settings: default enumerate_net_device is set to true, which will automatically enumerate network devices
# If you do not want to automatically enumerate network devices, # If you do not want to automatically enumerate network devices,
# you can set enumerate_net_device to false, net_device_ip to the device's IP address, and net_device_port to the default value of 8090 # you can set enumerate_net_device to false, net_device_ip to the device's IP address, and net_device_port to the default value of 8090