Add periodic host time synchronization and sync period parameter

This commit is contained in:
xiexun
2025-09-02 17:06:59 +08:00
parent ce52dbd997
commit 27017aa5ed
4 changed files with 54 additions and 6 deletions
+8
View File
@@ -57,6 +57,7 @@ The following are the launch parameters available:
* The delay time in milliseconds for reopening the device. Some devices, such as Astra mini, require a longer time to initialize and reopening the device immediately can cause firmware crashes when hot plugging
* **[color|depth|left_ir|right_ir|ir]_width,[color|depth|left_ir|right_ir|ir]_height,[color|depth|left_ir|right_ir|ir]_fps,[color|depth|left_ir|right_ir|ir]_format**
* The resolution and frame rate of the sensor stream
* **enable_color_auto_exposure_priority**
@@ -69,6 +70,7 @@ The following are the launch parameters available:
* Set the Color exposure
* **color_gain**
* Set the Color gain
* **enable_color_auto_white_balance**
@@ -294,8 +296,14 @@ The following are the launch parameters available:
* `DEPTH`:Align color to depth
* **diagnostic_period**
* Diagnostic period in seconds
* **time_sync_period**
* Interval for synchronizing the camera time with the host system.
* Unit: seconds.
* **enable_laser**
* Enable the laser. The default value is `true`
@@ -226,6 +226,8 @@ class OBCameraNode {
void setupDiagnosticUpdater();
void setupPeriodicHostTimeSync();
void onTemperatureUpdate(diagnostic_updater::DiagnosticStatusWrapper& status);
void setupCameraCtrlServices();
@@ -738,7 +740,9 @@ class OBCameraNode {
// soft ware trigger
rclcpp::TimerBase::SharedPtr software_trigger_timer_;
rclcpp::TimerBase::SharedPtr diagnostic_timer_;
rclcpp::TimerBase::SharedPtr sync_timer_;
std::chrono::milliseconds software_trigger_period_{33};
std::chrono::milliseconds time_sync_period_{6000};
bool enable_heartbeat_ = false;
bool enable_color_undistortion_ = false;
std::shared_ptr<image_publisher> color_undistortion_publisher_;
@@ -239,7 +239,8 @@ def generate_launch_description():
DeclareLaunchArgument('spatial_moderate_filter_radius', default_value='-1'),
DeclareLaunchArgument('align_mode', default_value='SW'),
DeclareLaunchArgument('align_target_stream', default_value='COLOR'),# COLOR or DEPTH
DeclareLaunchArgument('diagnostic_period', default_value='1.0'),
DeclareLaunchArgument('diagnostic_period', default_value='1.0'), # seconds
DeclareLaunchArgument('time_sync_period', default_value='6.0'), # seconds
DeclareLaunchArgument('enable_laser', default_value='true'),
DeclareLaunchArgument('depth_precision', default_value=''),
DeclareLaunchArgument('device_preset', default_value='Default'),
+37 -2
View File
@@ -1882,9 +1882,12 @@ void OBCameraNode::getParameters() {
device_->enableGlobalTimestamp(true);
}
setAndGetNodeParameter<int>(frames_per_trigger_, "frames_per_trigger", 2);
long software_trigger_period = 33;
setAndGetNodeParameter<long>(software_trigger_period, "software_trigger_period", 33);
int software_trigger_period = 33;
setAndGetNodeParameter<int>(software_trigger_period, "software_trigger_period", 33);
software_trigger_period_ = std::chrono::milliseconds(software_trigger_period);
double time_sync_period = 6.0;
setAndGetNodeParameter<double>(time_sync_period, "time_sync_period", 6.0);
time_sync_period_ = std::chrono::milliseconds((int)(time_sync_period*1000));
setAndGetNodeParameter<int>(gmsl_trigger_fps_, "gmsl_trigger_fps", 3000);
setAndGetNodeParameter<bool>(enable_gmsl_trigger_, "enable_gmsl_trigger", false);
setAndGetNodeParameter<std::string>(interleave_ae_mode_, "interleave_ae_mode", "hdr");
@@ -1971,6 +1974,7 @@ void OBCameraNode::setupTopics() {
setupCameraCtrlServices();
setupPublishers();
setupDiagnosticUpdater();
setupPeriodicHostTimeSync();
} catch (const ob::Error &e) {
RCLCPP_ERROR_STREAM(logger_, "Failed to setup topics: " << e.getMessage());
throw std::runtime_error(e.getMessage());
@@ -2079,6 +2083,37 @@ void OBCameraNode::setupDiagnosticUpdater() {
}
}
void OBCameraNode::setupPeriodicHostTimeSync() {
if (time_sync_period_.count() <= 0) {
RCLCPP_INFO(logger_, "Periodic host time sync disabled (time_sync_period <= 0)");
return;
}
try {
RCLCPP_INFO_STREAM(logger_, "Enable periodic host time sync every " << time_sync_period_.count() << " ms");
sync_timer_ = node_->create_wall_timer(
std::chrono::milliseconds(time_sync_period_),
[this]() {
try {
device_->timerSyncWithHost();
RCLCPP_DEBUG(logger_, "Camera time synchronized with host");
} catch (const ob::Error &e) {
RCLCPP_WARN_STREAM(logger_, "Time sync failed: " << e.getMessage());
} catch (const std::exception &e) {
RCLCPP_WARN_STREAM(logger_, "Time sync failed: " << e.what());
} catch (...) {
RCLCPP_WARN(logger_, "Time sync failed due to unknown error");
}
}
);
} catch (const ob::Error &e) {
RCLCPP_ERROR_STREAM(logger_, "Failed to setup periodic host time sync: " << e.getMessage());
} catch (const std::exception &e) {
RCLCPP_ERROR_STREAM(logger_, "Failed to setup periodic host time sync: " << e.what());
} catch (...) {
RCLCPP_ERROR(logger_, "Failed to setup periodic host time sync due to unknown error");
}
}
void OBCameraNode::setupPipelineConfig() {
if (pipeline_config_) {
pipeline_config_.reset();