feat: add config JSON export service

This commit is contained in:
ob-yalian
2026-05-27 09:42:02 +08:00
parent 4107a1f66e
commit 2e673ba95b
3 changed files with 53 additions and 5 deletions
+34 -5
View File
@@ -1405,11 +1405,6 @@ void OBCameraNode::setupDevices() {
RCLCPP_INFO_STREAM(logger_, "Current exposure range mode: "
<< exposureRangeModeToString(current_exposure_range_mode));
}
if (!export_config_json_file_path_.empty()) {
device_->exportSettingsAsPresetJsonFile(export_config_json_file_path_.c_str());
RCLCPP_INFO_STREAM(logger_,
"Exporting config json file path : " << export_config_json_file_path_);
}
if (device_->isPropertySupported(OB_PROP_SDK_ACCEL_FRAME_TRANSFORMED_BOOL, OB_PERMISSION_WRITE)) {
TRY_TO_SET_PROPERTY(setBoolProperty, OB_PROP_SDK_ACCEL_FRAME_TRANSFORMED_BOOL,
enable_accel_data_correction_);
@@ -1465,6 +1460,39 @@ void OBCameraNode::setupDevices() {
}
}
bool OBCameraNode::exportConfigJsonToFile(const std::string &file_path, std::string &message) {
if (file_path.empty()) {
message = "Config json export file path is empty";
RCLCPP_ERROR_STREAM(logger_, message);
return false;
}
try {
device_->exportSettingsAsPresetJsonFile(file_path.c_str());
message = "Exported config json file path: " + file_path;
RCLCPP_INFO_STREAM(logger_, message);
return true;
} catch (const ob::Error &e) {
message = "Failed to export config json file: " + orbbec_camera::formatObErrorWithStatus(e);
RCLCPP_ERROR_STREAM(logger_, message);
} catch (const std::exception &e) {
message = std::string("Failed to export config json file: ") + e.what();
RCLCPP_ERROR_STREAM(logger_, message);
} catch (...) {
message = "Failed to export config json file";
RCLCPP_ERROR_STREAM(logger_, message);
}
return false;
}
void OBCameraNode::exportConfigJsonIfRequested() {
if (export_config_json_file_path_.empty()) {
return;
}
std::string message;
exportConfigJsonToFile(export_config_json_file_path_, message);
}
bool OBCameraNode::isConfigJsonLoaded() const { return config_json_loaded_; }
void OBCameraNode::loadConfigJson() {
@@ -3442,6 +3470,7 @@ void OBCameraNode::setupTopics() {
setupCameraCtrlServices();
setupPublishers();
setupDiagnosticUpdater();
exportConfigJsonIfRequested();
} catch (const ob::Error &e) {
RCLCPP_ERROR_STREAM(logger_,
"Failed to setup topics: " << orbbec_camera::formatObErrorWithStatus(e));
+11
View File
@@ -227,6 +227,11 @@ void OBCameraNode::setupCameraCtrlServices() {
std::shared_ptr<std_srvs::srv::Empty::Response> response) {
savePointCloudCallback(request, response);
});
export_config_json_srv_ = node_->create_service<SetString>(
"export_config_json", [this](const std::shared_ptr<SetString::Request> request,
std::shared_ptr<SetString::Response> response) {
exportConfigJsonCallback(request, response);
});
switch_ir_camera_srv_ = node_->create_service<SetString>(
"switch_ir", [this](const std::shared_ptr<SetString::Request> request,
std::shared_ptr<SetString::Response> response) {
@@ -1422,6 +1427,12 @@ void OBCameraNode::switchIRCameraCallback(const std::shared_ptr<SetString::Reque
response->success = false;
}
}
void OBCameraNode::exportConfigJsonCallback(const std::shared_ptr<SetString::Request> &request,
std::shared_ptr<SetString::Response> &response) {
response->success = exportConfigJsonToFile(request->data, response->message);
}
void OBCameraNode::setIRLongExposureCallback(
const std::shared_ptr<std_srvs::srv::SetBool::Request>& request,
std::shared_ptr<std_srvs::srv::SetBool::Response>& response) {