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
@@ -237,6 +237,10 @@ class OBCameraNode {
void loadConfigJson(); void loadConfigJson();
bool exportConfigJsonToFile(const std::string &file_path, std::string &message);
void exportConfigJsonIfRequested();
bool isConfigJsonLoaded() const; bool isConfigJsonLoaded() const;
void syncConfigJsonDeviceSettings(); void syncConfigJsonDeviceSettings();
@@ -421,6 +425,9 @@ class OBCameraNode {
void switchIRCameraCallback(const std::shared_ptr<SetString::Request>& request, void switchIRCameraCallback(const std::shared_ptr<SetString::Request>& request,
std::shared_ptr<SetString::Response>& response); std::shared_ptr<SetString::Response>& response);
void exportConfigJsonCallback(const std::shared_ptr<SetString::Request> &request,
std::shared_ptr<SetString::Response> &response);
bool writeCustomerData(const std::string& data); bool writeCustomerData(const std::string& data);
bool readCustomerData(std::string& out_data); bool readCustomerData(std::string& out_data);
@@ -624,6 +631,7 @@ class OBCameraNode {
rclcpp::Service<SetBool>::SharedPtr set_auto_white_balance_srv_; rclcpp::Service<SetBool>::SharedPtr set_auto_white_balance_srv_;
rclcpp::Service<GetString>::SharedPtr get_sdk_version_srv_; rclcpp::Service<GetString>::SharedPtr get_sdk_version_srv_;
rclcpp::Service<SetString>::SharedPtr switch_ir_camera_srv_; rclcpp::Service<SetString>::SharedPtr switch_ir_camera_srv_;
rclcpp::Service<SetString>::SharedPtr export_config_json_srv_;
rclcpp::Service<SetString>::SharedPtr write_customerdata_srv_; rclcpp::Service<SetString>::SharedPtr write_customerdata_srv_;
rclcpp::Service<GetString>::SharedPtr read_customerdata_srv_; rclcpp::Service<GetString>::SharedPtr read_customerdata_srv_;
rclcpp::Service<std_srvs::srv::SetBool>::SharedPtr set_ir_long_exposure_srv_; rclcpp::Service<std_srvs::srv::SetBool>::SharedPtr set_ir_long_exposure_srv_;
+34 -5
View File
@@ -1405,11 +1405,6 @@ void OBCameraNode::setupDevices() {
RCLCPP_INFO_STREAM(logger_, "Current exposure range mode: " RCLCPP_INFO_STREAM(logger_, "Current exposure range mode: "
<< exposureRangeModeToString(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)) { 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, TRY_TO_SET_PROPERTY(setBoolProperty, OB_PROP_SDK_ACCEL_FRAME_TRANSFORMED_BOOL,
enable_accel_data_correction_); 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_; } bool OBCameraNode::isConfigJsonLoaded() const { return config_json_loaded_; }
void OBCameraNode::loadConfigJson() { void OBCameraNode::loadConfigJson() {
@@ -3442,6 +3470,7 @@ void OBCameraNode::setupTopics() {
setupCameraCtrlServices(); setupCameraCtrlServices();
setupPublishers(); setupPublishers();
setupDiagnosticUpdater(); setupDiagnosticUpdater();
exportConfigJsonIfRequested();
} catch (const ob::Error &e) { } catch (const ob::Error &e) {
RCLCPP_ERROR_STREAM(logger_, RCLCPP_ERROR_STREAM(logger_,
"Failed to setup topics: " << orbbec_camera::formatObErrorWithStatus(e)); "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) { std::shared_ptr<std_srvs::srv::Empty::Response> response) {
savePointCloudCallback(request, 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_camera_srv_ = node_->create_service<SetString>(
"switch_ir", [this](const std::shared_ptr<SetString::Request> request, "switch_ir", [this](const std::shared_ptr<SetString::Request> request,
std::shared_ptr<SetString::Response> response) { std::shared_ptr<SetString::Response> response) {
@@ -1422,6 +1427,12 @@ void OBCameraNode::switchIRCameraCallback(const std::shared_ptr<SetString::Reque
response->success = false; 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( void OBCameraNode::setIRLongExposureCallback(
const std::shared_ptr<std_srvs::srv::SetBool::Request>& request, const std::shared_ptr<std_srvs::srv::SetBool::Request>& request,
std::shared_ptr<std_srvs::srv::SetBool::Response>& response) { std::shared_ptr<std_srvs::srv::SetBool::Response>& response) {