mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-10 22:49:51 +08:00
feat: use name-based color preset API
This commit is contained in:
@@ -27,6 +27,7 @@ align_mode: SW
|
|||||||
align_target_stream: COLOR
|
align_target_stream: COLOR
|
||||||
diagnostic_period: 1.0
|
diagnostic_period: 1.0
|
||||||
device_preset: Dual Color Streams
|
device_preset: Dual Color Streams
|
||||||
|
color_preset: Default
|
||||||
retry_on_usb3_detection_failure: false
|
retry_on_usb3_detection_failure: false
|
||||||
enable_sync_host_time: true
|
enable_sync_host_time: true
|
||||||
sync_io_voltage_level: -1
|
sync_io_voltage_level: -1
|
||||||
|
|||||||
@@ -271,6 +271,7 @@ def generate_launch_description():
|
|||||||
DeclareLaunchArgument('diagnostic_period', default_value='1.0'), # seconds
|
DeclareLaunchArgument('diagnostic_period', default_value='1.0'), # seconds
|
||||||
DeclareLaunchArgument('depth_precision', default_value=''),
|
DeclareLaunchArgument('depth_precision', default_value=''),
|
||||||
DeclareLaunchArgument('device_preset', default_value='Default'), # Default, High Accuracy, Close Range High Accuracy, Factory Calib, Dual Color Streams, Custom
|
DeclareLaunchArgument('device_preset', default_value='Default'), # Default, High Accuracy, Close Range High Accuracy, Factory Calib, Dual Color Streams, Custom
|
||||||
|
DeclareLaunchArgument('color_preset', default_value='Default'), # color preset name reported by the device
|
||||||
DeclareLaunchArgument('retry_on_usb3_detection_failure', default_value='false'),
|
DeclareLaunchArgument('retry_on_usb3_detection_failure', default_value='false'),
|
||||||
DeclareLaunchArgument('enable_sync_host_time', default_value='false'),
|
DeclareLaunchArgument('enable_sync_host_time', default_value='false'),
|
||||||
DeclareLaunchArgument('sync_io_voltage_level', default_value='-1'),
|
DeclareLaunchArgument('sync_io_voltage_level', default_value='-1'),
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ def generate_launch_description():
|
|||||||
DeclareLaunchArgument('enable_laser', default_value='true'),
|
DeclareLaunchArgument('enable_laser', default_value='true'),
|
||||||
DeclareLaunchArgument('depth_precision', default_value=''),
|
DeclareLaunchArgument('depth_precision', default_value=''),
|
||||||
DeclareLaunchArgument('device_preset', default_value='Default'),
|
DeclareLaunchArgument('device_preset', default_value='Default'),
|
||||||
DeclareLaunchArgument('color_preset', default_value='Default'),# color preset: Default, Warm Biased AWB
|
DeclareLaunchArgument('color_preset', default_value='Default'),# color preset name reported by the device
|
||||||
DeclareLaunchArgument('retry_on_usb3_detection_failure', default_value='false'),
|
DeclareLaunchArgument('retry_on_usb3_detection_failure', default_value='false'),
|
||||||
DeclareLaunchArgument('laser_energy_level', default_value='-1'),
|
DeclareLaunchArgument('laser_energy_level', default_value='-1'),
|
||||||
DeclareLaunchArgument('enable_sync_host_time', default_value='false'),
|
DeclareLaunchArgument('enable_sync_host_time', default_value='false'),
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ def generate_launch_description():
|
|||||||
DeclareLaunchArgument('enable_laser', default_value='true'),
|
DeclareLaunchArgument('enable_laser', default_value='true'),
|
||||||
DeclareLaunchArgument('depth_precision', default_value=''),
|
DeclareLaunchArgument('depth_precision', default_value=''),
|
||||||
DeclareLaunchArgument('device_preset', default_value='Default'),
|
DeclareLaunchArgument('device_preset', default_value='Default'),
|
||||||
DeclareLaunchArgument('color_preset', default_value='Default'),# color preset: Default, Warm Biased AWB
|
DeclareLaunchArgument('color_preset', default_value='Default'),# color preset name reported by the device
|
||||||
DeclareLaunchArgument('retry_on_usb3_detection_failure', default_value='false'),
|
DeclareLaunchArgument('retry_on_usb3_detection_failure', default_value='false'),
|
||||||
DeclareLaunchArgument('laser_energy_level', default_value='-1'),
|
DeclareLaunchArgument('laser_energy_level', default_value='-1'),
|
||||||
DeclareLaunchArgument('enable_sync_host_time', default_value='false'),
|
DeclareLaunchArgument('enable_sync_host_time', default_value='false'),
|
||||||
|
|||||||
@@ -182,6 +182,14 @@ std::string lowerFilterConfigValue(std::string value) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool equalsIgnoreCase(std::string lhs, std::string rhs) {
|
||||||
|
std::transform(lhs.begin(), lhs.end(), lhs.begin(),
|
||||||
|
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
|
||||||
|
std::transform(rhs.begin(), rhs.end(), rhs.begin(),
|
||||||
|
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
|
||||||
|
return lhs == rhs;
|
||||||
|
}
|
||||||
|
|
||||||
std::string lowerParameterValue(std::string value) {
|
std::string lowerParameterValue(std::string value) {
|
||||||
std::transform(value.begin(), value.end(), value.begin(),
|
std::transform(value.begin(), value.end(), value.begin(),
|
||||||
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
|
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
|
||||||
@@ -1192,26 +1200,47 @@ void OBCameraNode::setupDevices() {
|
|||||||
"Current color auto white balance: "
|
"Current color auto white balance: "
|
||||||
<< (device_->getBoolProperty(OB_PROP_COLOR_AUTO_WHITE_BALANCE_BOOL) ? "ON" : "OFF"));
|
<< (device_->getBoolProperty(OB_PROP_COLOR_AUTO_WHITE_BALANCE_BOOL) ? "ON" : "OFF"));
|
||||||
}
|
}
|
||||||
if (should_apply_launch_config("color_preset") && !color_preset_.empty() &&
|
if (should_apply_launch_config("color_preset") && !color_preset_.empty()) {
|
||||||
device_->isPropertySupported(OB_PROP_COLOR_PRESET_PRIORITY_INT, OB_PERMISSION_WRITE)) {
|
try {
|
||||||
std::string preset_key = color_preset_;
|
if (!device_->isColorPresetSupported()) {
|
||||||
std::transform(preset_key.begin(), preset_key.end(), preset_key.begin(), ::tolower);
|
RCLCPP_WARN_STREAM(logger_, "Color preset is not supported by this device");
|
||||||
int preset_value = -1;
|
} else {
|
||||||
if (preset_key == "default") {
|
auto color_preset_list = device_->getColorPresetList();
|
||||||
preset_value = 0;
|
std::string selected_preset;
|
||||||
} else if (preset_key == "warm biased awb") {
|
std::ostringstream supported_presets;
|
||||||
preset_value = 1;
|
bool has_supported_preset = false;
|
||||||
} else {
|
const uint32_t preset_count = color_preset_list ? color_preset_list->getCount() : 0;
|
||||||
|
for (uint32_t i = 0; i < preset_count; ++i) {
|
||||||
|
const char *preset_name = color_preset_list->getName(i);
|
||||||
|
if (preset_name == nullptr || preset_name[0] == '\0') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (has_supported_preset) {
|
||||||
|
supported_presets << ", ";
|
||||||
|
}
|
||||||
|
supported_presets << preset_name;
|
||||||
|
has_supported_preset = true;
|
||||||
|
if (equalsIgnoreCase(color_preset_, preset_name)) {
|
||||||
|
selected_preset = preset_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selected_preset.empty()) {
|
||||||
|
RCLCPP_WARN_STREAM(logger_, "Unsupported color_preset: " << color_preset_
|
||||||
|
<< ". Supported values: "
|
||||||
|
<< supported_presets.str());
|
||||||
|
} else {
|
||||||
|
device_->switchColorPreset(selected_preset.c_str());
|
||||||
|
const char *current_preset = device_->getCurrentColorPresetName();
|
||||||
|
color_preset_ = current_preset != nullptr ? current_preset : selected_preset;
|
||||||
|
RCLCPP_INFO_STREAM(logger_, "Current color preset: " << color_preset_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (const ob::Error &e) {
|
||||||
RCLCPP_WARN_STREAM(
|
RCLCPP_WARN_STREAM(
|
||||||
logger_, "Unsupported color_preset: " << color_preset_
|
logger_, "Failed to set color preset: " << orbbec_camera::formatObErrorWithStatus(e));
|
||||||
<< ". Supported values: Default, Warm Biased AWB");
|
} catch (const std::exception &e) {
|
||||||
}
|
RCLCPP_WARN_STREAM(logger_, "Failed to set color preset: " << e.what());
|
||||||
if (preset_value >= 0) {
|
|
||||||
TRY_TO_SET_PROPERTY(setIntProperty, OB_PROP_COLOR_PRESET_PRIORITY_INT, preset_value);
|
|
||||||
RCLCPP_INFO_STREAM(logger_, "Current color preset: "
|
|
||||||
<< (device_->getIntProperty(OB_PROP_COLOR_PRESET_PRIORITY_INT)
|
|
||||||
? "Warm Biased AWB"
|
|
||||||
: "Default"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (color_exposure_ != -1 &&
|
if (color_exposure_ != -1 &&
|
||||||
@@ -2413,13 +2442,15 @@ void OBCameraNode::syncConfigJsonDeviceSettings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sync_bool("color", "color_anti_flicker", color_anti_flicker_, OB_PROP_COLOR_ANTI_FLICKER_BOOL);
|
sync_bool("color", "color_anti_flicker", color_anti_flicker_, OB_PROP_COLOR_ANTI_FLICKER_BOOL);
|
||||||
if (can_read(OB_PROP_COLOR_PRESET_PRIORITY_INT)) {
|
try {
|
||||||
try {
|
if (device_->isColorPresetSupported()) {
|
||||||
const auto color_preset = device_->getIntProperty(OB_PROP_COLOR_PRESET_PRIORITY_INT);
|
const char *color_preset = device_->getCurrentColorPresetName();
|
||||||
color_preset_ = color_preset == 1 ? "Warm Biased AWB" : "Default";
|
if (color_preset != nullptr) {
|
||||||
log_readback("color", "color_preset", color_preset_);
|
color_preset_ = color_preset;
|
||||||
} catch (const std::exception &) {
|
log_readback("color", "color_preset", color_preset_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (const std::exception &) {
|
||||||
}
|
}
|
||||||
if (can_read(OB_STRUCT_COLOR_AE_ROI)) {
|
if (can_read(OB_STRUCT_COLOR_AE_ROI)) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -62,17 +62,6 @@ std::string alignTargetStreamToString(OBStreamType stream_type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string colorPresetToString(int value) {
|
|
||||||
switch (value) {
|
|
||||||
case 0:
|
|
||||||
return "Default";
|
|
||||||
case 1:
|
|
||||||
return "Warm Biased AWB";
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string disparityToDepthModeToString(bool hardware_enabled, bool software_enabled) {
|
std::string disparityToDepthModeToString(bool hardware_enabled, bool software_enabled) {
|
||||||
if (hardware_enabled) {
|
if (hardware_enabled) {
|
||||||
return "HW";
|
return "HW";
|
||||||
@@ -1373,10 +1362,11 @@ void OBCameraNode::getDeviceConfigCallback(const std::shared_ptr<GetDeviceConfig
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const auto color_preset = device_->getIntProperty(OB_PROP_COLOR_PRESET_PRIORITY_INT);
|
if (device_->isColorPresetSupported()) {
|
||||||
const auto color_preset_name = colorPresetToString(color_preset);
|
const char* color_preset_name = device_->getCurrentColorPresetName();
|
||||||
if (!color_preset_name.empty()) {
|
if (color_preset_name != nullptr && color_preset_name[0] != '\0') {
|
||||||
response->color_preset = color_preset_name;
|
response->color_preset = color_preset_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (const ob::Error& e) {
|
} catch (const ob::Error& e) {
|
||||||
RCLCPP_DEBUG_STREAM(
|
RCLCPP_DEBUG_STREAM(
|
||||||
|
|||||||
Reference in New Issue
Block a user