feat: add set_disparity_search_offset service and callback to OBCameraNode

This commit is contained in:
ob-yalian
2026-03-16 15:33:57 +08:00
parent b583bae1ea
commit 134028503a
2 changed files with 58 additions and 0 deletions
+55
View File
@@ -288,6 +288,11 @@ void OBCameraNode::setupCameraCtrlServices() {
std::shared_ptr<SetInt32::Response> response) {
setDisparityRangeModeCallback(request, response);
});
set_disparity_search_offset_srv_ = node_->create_service<SetInt32>(
"set_disparity_search_offset", [this](const std::shared_ptr<SetInt32::Request> request,
std::shared_ptr<SetInt32::Response> response) {
setDisparitySearchOffsetCallback(request, response);
});
}
void OBCameraNode::getPointCloudDecimationCallback(
@@ -386,6 +391,56 @@ void OBCameraNode::setDisparityRangeModeCallback(const std::shared_ptr<SetInt32:
}
}
void OBCameraNode::setDisparitySearchOffsetCallback(
const std::shared_ptr<SetInt32::Request>& request,
std::shared_ptr<SetInt32::Response>& response) {
if (!request) {
response->success = false;
response->message = "Invalid request";
return;
}
try {
if (!device_->isPropertySupported(OB_PROP_DISP_SEARCH_OFFSET_INT, OB_PERMISSION_WRITE)) {
response->success = false;
response->message = "OB_PROP_DISP_SEARCH_OFFSET_INT is not supported";
return;
}
const bool allow_set = isGemini435LePID(pid_) || enable_stream_[DEPTH];
if (!allow_set) {
response->success = false;
response->message = "Disparity search offset can only be set when depth stream is enabled";
return;
}
auto range = device_->getIntPropertyRange(OB_PROP_DISP_SEARCH_OFFSET_INT);
if (request->data < range.min || request->data > range.max) {
response->success = false;
response->message =
"Invalid disparity search offset. Allowed values:" + std::to_string(range.min) + " to " +
std::to_string(range.max);
return;
}
device_->setIntProperty(OB_PROP_DISP_SEARCH_OFFSET_INT, request->data);
disparity_search_offset_ = request->data;
RCLCPP_INFO_STREAM(logger_, "Set disparity_search_offset to " << disparity_search_offset_);
response->success = true;
response->message = "disparity_search_offset updated";
} catch (const ob::Error& e) {
response->success = false;
response->message = e.getMessage();
} catch (const std::exception& e) {
response->success = false;
response->message = e.what();
} catch (...) {
response->success = false;
response->message = "unknown error";
}
}
void OBCameraNode::setStreamsEnableCallback(
const std::shared_ptr<std_srvs::srv::SetBool::Request> request,
std::shared_ptr<std_srvs::srv::SetBool::Response> response) {