refactor: sync service-updated settings

This commit is contained in:
ob-yalian
2026-05-27 09:50:32 +08:00
parent 3b2b92b2f3
commit 139add9f02
+67
View File
@@ -437,6 +437,7 @@ void OBCameraNode::setDisparityRangeModeCallback(const std::shared_ptr<SetInt32:
: (current_mode_index == 1) ? 128
: (current_mode_index == 2) ? 256
: current_mode_index;
disparity_range_mode_ = current_mode_value;
response->success = true;
response->message = "disparity_range_mode updated to " + std::to_string(current_mode_value);
} catch (const ob::Error& e) {
@@ -494,6 +495,7 @@ void OBCameraNode::setDisparitySearchOffsetCallback(
device_->setIntProperty(OB_PROP_DISP_SEARCH_OFFSET_INT, request->data);
auto current_offset = device_->getIntProperty(OB_PROP_DISP_SEARCH_OFFSET_INT);
disparity_search_offset_ = current_offset;
RCLCPP_INFO_STREAM(logger_, "Set disparity_search_offset to " << current_offset);
response->success = true;
response->message = "disparity_search_offset updated to " + std::to_string(current_offset);
@@ -557,14 +559,17 @@ void OBCameraNode::setExposureCallback(const std::shared_ptr<SetInt32::Request>&
case OB_STREAM_IR_RIGHT:
case OB_STREAM_IR:
device_->setIntProperty(OB_PROP_IR_EXPOSURE_INT, request->data);
ir_exposure_ = device_->getIntProperty(OB_PROP_IR_EXPOSURE_INT);
break;
case OB_STREAM_DEPTH:
device_->setIntProperty(OB_PROP_DEPTH_EXPOSURE_INT, request->data);
depth_exposure_ = device_->getIntProperty(OB_PROP_DEPTH_EXPOSURE_INT);
break;
case OB_STREAM_COLOR:
case OB_STREAM_COLOR_LEFT:
case OB_STREAM_COLOR_RIGHT:
device_->setIntProperty(OB_PROP_COLOR_EXPOSURE_INT, request->data);
color_exposure_ = device_->getIntProperty(OB_PROP_COLOR_EXPOSURE_INT);
break;
default:
RCLCPP_ERROR(logger_, "%s NOT a video stream", __FUNCTION__);
@@ -655,6 +660,15 @@ void OBCameraNode::setGainCallback(const std::shared_ptr<SetInt32 ::Request>& re
return;
}
device_->setIntProperty(prop_id, request->data);
const auto current_gain = device_->getIntProperty(prop_id);
if (stream == OB_STREAM_IR_LEFT || stream == OB_STREAM_IR_RIGHT || stream == OB_STREAM_IR) {
ir_gain_ = current_gain;
} else if (stream == OB_STREAM_DEPTH) {
depth_gain_ = current_gain;
} else if (stream == OB_STREAM_COLOR || stream == OB_STREAM_COLOR_LEFT ||
stream == OB_STREAM_COLOR_RIGHT) {
color_gain_ = current_gain;
}
response->success = true;
} catch (const ob::Error& e) {
response->success = false;
@@ -725,6 +739,10 @@ void OBCameraNode::setAeRoiCallback(const std::shared_ptr<SetArrays ::Request>&
logger_, "Set depth AE ROI to "
<< "[Left: " << config.x0_left << ", Right: " << config.x1_right
<< ", Top: " << config.y0_top << ", Bottom: " << config.y1_bottom << "]");
depth_ae_roi_left_ = config.x0_left;
depth_ae_roi_top_ = config.y0_top;
depth_ae_roi_right_ = config.x1_right;
depth_ae_roi_bottom_ = config.y1_bottom;
break;
case OB_STREAM_COLOR:
case OB_STREAM_COLOR_LEFT:
@@ -761,6 +779,10 @@ void OBCameraNode::setAeRoiCallback(const std::shared_ptr<SetArrays ::Request>&
logger_, "Set color AE ROI to "
<< "[Left: " << config.x0_left << ", Right: " << config.x1_right
<< ", Top: " << config.y0_top << ", Bottom: " << config.y1_bottom << "]");
color_ae_roi_left_ = config.x0_left;
color_ae_roi_top_ = config.y0_top;
color_ae_roi_right_ = config.x1_right;
color_ae_roi_bottom_ = config.y1_bottom;
break;
default:
RCLCPP_ERROR(logger_, "%s NOT a video stream", __FUNCTION__);
@@ -817,6 +839,7 @@ void OBCameraNode::setWhiteBalanceCallback(const std::shared_ptr<SetInt32 ::Requ
return;
}
device_->setIntProperty(OB_PROP_COLOR_WHITE_BALANCE_INT, request->data);
color_white_balance_ = device_->getIntProperty(OB_PROP_COLOR_WHITE_BALANCE_INT);
response->success = true;
} catch (const ob::Error& e) {
response->message = orbbec_camera::formatObErrorWithStatus(e);
@@ -850,6 +873,8 @@ void OBCameraNode::setAutoWhiteBalanceCallback(const std::shared_ptr<SetBool::Re
std::shared_ptr<SetBool::Response>& response) {
try {
device_->setBoolProperty(OB_PROP_COLOR_AUTO_WHITE_BALANCE_BOOL, request->data);
enable_color_auto_white_balance_ =
device_->getBoolProperty(OB_PROP_COLOR_AUTO_WHITE_BALANCE_BOOL);
response->success = true;
} catch (const ob::Error& e) {
response->success = false;
@@ -897,6 +922,15 @@ void OBCameraNode::setAutoExposureCallback(
return;
}
device_->setIntProperty(prop_id, request->data);
const bool current_auto_exposure = device_->getBoolProperty(prop_id);
if (stream == OB_STREAM_IR_LEFT || stream == OB_STREAM_IR_RIGHT || stream == OB_STREAM_IR) {
enable_ir_auto_exposure_ = current_auto_exposure;
} else if (stream == OB_STREAM_DEPTH) {
enable_ir_auto_exposure_ = current_auto_exposure;
} else if (stream == OB_STREAM_COLOR || stream == OB_STREAM_COLOR_LEFT ||
stream == OB_STREAM_COLOR_RIGHT) {
enable_color_auto_exposure_ = current_auto_exposure;
}
response->success = true;
} catch (const ob::Error& e) {
response->success = false;
@@ -958,10 +992,16 @@ void OBCameraNode::setLaserEnableCallback(
(void)response;
int laser_enable = request->data ? 1 : 0;
try {
bool property_modified = false;
if (device_->isPropertySupported(OB_PROP_LASER_CONTROL_INT, OB_PERMISSION_READ_WRITE)) {
device_->setIntProperty(OB_PROP_LASER_CONTROL_INT, laser_enable);
property_modified = true;
} else if (device_->isPropertySupported(OB_PROP_LASER_BOOL, OB_PERMISSION_READ_WRITE)) {
device_->setIntProperty(OB_PROP_LASER_BOOL, laser_enable);
property_modified = true;
}
if (property_modified) {
enable_laser_ = request->data;
}
response->success = true;
} catch (const ob::Error& e) {
@@ -984,10 +1024,12 @@ void OBCameraNode::setLdpEnableCallback(
(void)response;
bool ldp_enable = request->data;
try {
bool property_modified = false;
if (device_->isPropertySupported(OB_PROP_LASER_CONTROL_INT, OB_PERMISSION_READ_WRITE)) {
auto laser_enable = device_->getIntProperty(OB_PROP_LASER_CONTROL_INT);
device_->setBoolProperty(OB_PROP_LDP_BOOL, ldp_enable);
device_->setIntProperty(OB_PROP_LASER_CONTROL_INT, laser_enable);
property_modified = true;
} else if (device_->isPropertySupported(OB_PROP_LASER_BOOL, OB_PERMISSION_READ_WRITE)) {
if (!ldp_enable) {
auto laser_enable = device_->getIntProperty(OB_PROP_LASER_BOOL);
@@ -997,6 +1039,10 @@ void OBCameraNode::setLdpEnableCallback(
} else {
device_->setBoolProperty(OB_PROP_LDP_BOOL, ldp_enable);
}
property_modified = true;
}
if (property_modified) {
enable_ldp_ = ldp_enable;
}
response->success = true;
} catch (const ob::Error& e) {
@@ -1105,22 +1151,28 @@ void OBCameraNode::setMirrorCallback(const std::shared_ptr<SetBool::Request>& re
switch (stream) {
case OB_STREAM_IR_RIGHT:
device_->setBoolProperty(OB_PROP_IR_RIGHT_MIRROR_BOOL, request->data);
mirror_stream_[stream_index] = device_->getBoolProperty(OB_PROP_IR_RIGHT_MIRROR_BOOL);
break;
case OB_STREAM_IR_LEFT:
case OB_STREAM_IR:
device_->setBoolProperty(OB_PROP_IR_MIRROR_BOOL, request->data);
mirror_stream_[stream_index] = device_->getBoolProperty(OB_PROP_IR_MIRROR_BOOL);
break;
case OB_STREAM_DEPTH:
device_->setBoolProperty(OB_PROP_DEPTH_MIRROR_BOOL, request->data);
mirror_stream_[stream_index] = device_->getBoolProperty(OB_PROP_DEPTH_MIRROR_BOOL);
break;
case OB_STREAM_COLOR:
device_->setBoolProperty(OB_PROP_COLOR_MIRROR_BOOL, request->data);
mirror_stream_[stream_index] = device_->getBoolProperty(OB_PROP_COLOR_MIRROR_BOOL);
break;
case OB_STREAM_COLOR_LEFT:
device_->setBoolProperty(OB_PROP_COLOR_LEFT_MIRROR_BOOL, request->data);
mirror_stream_[stream_index] = device_->getBoolProperty(OB_PROP_COLOR_LEFT_MIRROR_BOOL);
break;
case OB_STREAM_COLOR_RIGHT:
device_->setBoolProperty(OB_PROP_COLOR_RIGHT_MIRROR_BOOL, request->data);
mirror_stream_[stream_index] = device_->getBoolProperty(OB_PROP_COLOR_RIGHT_MIRROR_BOOL);
break;
default:
RCLCPP_ERROR(logger_, " %s NOT a video stream", __FUNCTION__);
@@ -1148,24 +1200,31 @@ void OBCameraNode::setFlipCallback(const std::shared_ptr<SetBool::Request>& requ
switch (stream) {
case OB_STREAM_IR_RIGHT:
device_->setBoolProperty(OB_PROP_IR_RIGHT_FLIP_BOOL, request->data);
flip_stream_[stream_index] = device_->getBoolProperty(OB_PROP_IR_RIGHT_FLIP_BOOL);
break;
case OB_STREAM_IR_LEFT:
device_->setBoolProperty(OB_PROP_IR_FLIP_BOOL, request->data);
flip_stream_[stream_index] = device_->getBoolProperty(OB_PROP_IR_FLIP_BOOL);
break;
case OB_STREAM_IR:
device_->setBoolProperty(OB_PROP_IR_FLIP_BOOL, request->data);
flip_stream_[stream_index] = device_->getBoolProperty(OB_PROP_IR_FLIP_BOOL);
break;
case OB_STREAM_DEPTH:
device_->setBoolProperty(OB_PROP_DEPTH_FLIP_BOOL, request->data);
flip_stream_[stream_index] = device_->getBoolProperty(OB_PROP_DEPTH_FLIP_BOOL);
break;
case OB_STREAM_COLOR:
device_->setBoolProperty(OB_PROP_COLOR_FLIP_BOOL, request->data);
flip_stream_[stream_index] = device_->getBoolProperty(OB_PROP_COLOR_FLIP_BOOL);
break;
case OB_STREAM_COLOR_LEFT:
device_->setBoolProperty(OB_PROP_COLOR_LEFT_FLIP_BOOL, request->data);
flip_stream_[stream_index] = device_->getBoolProperty(OB_PROP_COLOR_LEFT_FLIP_BOOL);
break;
case OB_STREAM_COLOR_RIGHT:
device_->setBoolProperty(OB_PROP_COLOR_RIGHT_FLIP_BOOL, request->data);
flip_stream_[stream_index] = device_->getBoolProperty(OB_PROP_COLOR_RIGHT_FLIP_BOOL);
break;
default:
RCLCPP_ERROR(logger_, " %s NOT a video stream", __FUNCTION__);
@@ -1193,24 +1252,31 @@ void OBCameraNode::setRotationCallback(const std::shared_ptr<SetInt32::Request>&
switch (stream) {
case OB_STREAM_IR_RIGHT:
device_->setIntProperty(OB_PROP_IR_RIGHT_ROTATE_INT, request->data);
rotation_stream_[stream_index] = device_->getIntProperty(OB_PROP_IR_RIGHT_ROTATE_INT);
break;
case OB_STREAM_IR_LEFT:
device_->setIntProperty(OB_PROP_IR_ROTATE_INT, request->data);
rotation_stream_[stream_index] = device_->getIntProperty(OB_PROP_IR_ROTATE_INT);
break;
case OB_STREAM_IR:
device_->setIntProperty(OB_PROP_IR_ROTATE_INT, request->data);
rotation_stream_[stream_index] = device_->getIntProperty(OB_PROP_IR_ROTATE_INT);
break;
case OB_STREAM_DEPTH:
device_->setIntProperty(OB_PROP_DEPTH_ROTATE_INT, request->data);
rotation_stream_[stream_index] = device_->getIntProperty(OB_PROP_DEPTH_ROTATE_INT);
break;
case OB_STREAM_COLOR:
device_->setIntProperty(OB_PROP_COLOR_ROTATE_INT, request->data);
rotation_stream_[stream_index] = device_->getIntProperty(OB_PROP_COLOR_ROTATE_INT);
break;
case OB_STREAM_COLOR_LEFT:
device_->setIntProperty(OB_PROP_COLOR_LEFT_ROTATE_INT, request->data);
rotation_stream_[stream_index] = device_->getIntProperty(OB_PROP_COLOR_LEFT_ROTATE_INT);
break;
case OB_STREAM_COLOR_RIGHT:
device_->setIntProperty(OB_PROP_COLOR_RIGHT_ROTATE_INT, request->data);
rotation_stream_[stream_index] = device_->getIntProperty(OB_PROP_COLOR_RIGHT_ROTATE_INT);
break;
default:
RCLCPP_ERROR(logger_, " %s NOT a video stream", __FUNCTION__);
@@ -1283,6 +1349,7 @@ void OBCameraNode::setPtpConfigCallback(
return;
}
device_->setBoolProperty(OB_DEVICE_PTP_CLOCK_SYNC_ENABLE_BOOL, request->data);
enable_ptp_config_ = device_->getBoolProperty(OB_DEVICE_PTP_CLOCK_SYNC_ENABLE_BOOL);
response->success = true;
} catch (const ob::Error& e) {
response->success = false;