mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-06 13:07:47 +08:00
Merge remote-tracking branch 'origin/feat/image-qos-color-queue' into v2/develop
This commit is contained in:
@@ -121,6 +121,11 @@ std::string OBSyncModeToString(const OBMultiDeviceSyncMode& mode) {
|
||||
|
||||
void OBCameraNode::setupCameraCtrlServices() {
|
||||
using std_srvs::srv::SetBool;
|
||||
get_color_queue_stats_srv_ = node_->create_service<SetBool>(
|
||||
"get_color_queue_stats", [this](const std::shared_ptr<SetBool::Request> request,
|
||||
std::shared_ptr<SetBool::Response> response) {
|
||||
getColorQueueStatsCallback(request, response);
|
||||
});
|
||||
for (auto stream_index : IMAGE_STREAMS) {
|
||||
if (!enable_stream_[stream_index]) {
|
||||
continue;
|
||||
@@ -458,6 +463,69 @@ void OBCameraNode::setupCameraCtrlServices() {
|
||||
}
|
||||
}
|
||||
|
||||
void OBCameraNode::getColorQueueStatsCallback(
|
||||
const std::shared_ptr<std_srvs::srv::SetBool::Request>& request,
|
||||
std::shared_ptr<std_srvs::srv::SetBool::Response>& response) {
|
||||
try {
|
||||
const auto to_json = [](const ColorQueueStatsSnapshot& stats) {
|
||||
return nlohmann::json{
|
||||
{"capacity_frames", stats.capacity_frames},
|
||||
{"queue_size", stats.queue_size},
|
||||
{"max_queue_size", stats.max_queue_size},
|
||||
{"overflow_count", stats.overflow_count},
|
||||
{"oldest_queue_wait_ms", stats.oldest_queue_wait_ms},
|
||||
{"max_queue_wait_ms", stats.max_queue_wait_ms},
|
||||
};
|
||||
};
|
||||
|
||||
nlohmann::json queues = nlohmann::json::object();
|
||||
uint64_t overflow_count = 0;
|
||||
const bool reset = request->data;
|
||||
if (enable_stream_[COLOR] || reset) {
|
||||
const auto stats =
|
||||
getColorQueueStats(color_frame_queue_, color_frame_queue_lock_, color_frame_queue_stats_,
|
||||
color_frame_queue_max_frames_, reset);
|
||||
if (enable_stream_[COLOR]) {
|
||||
queues["color"] = to_json(stats);
|
||||
overflow_count += stats.overflow_count;
|
||||
}
|
||||
}
|
||||
if (enable_stream_[COLOR_LEFT] || reset) {
|
||||
const auto stats = getColorQueueStats(left_color_frame_queue_, left_color_frame_queue_lock_,
|
||||
left_color_frame_queue_stats_,
|
||||
left_color_frame_queue_max_frames_, reset);
|
||||
if (enable_stream_[COLOR_LEFT]) {
|
||||
queues["left_color"] = to_json(stats);
|
||||
overflow_count += stats.overflow_count;
|
||||
}
|
||||
}
|
||||
if (enable_stream_[COLOR_RIGHT] || reset) {
|
||||
const auto stats = getColorQueueStats(right_color_frame_queue_, right_color_frame_queue_lock_,
|
||||
right_color_frame_queue_stats_,
|
||||
right_color_frame_queue_max_frames_, reset);
|
||||
if (enable_stream_[COLOR_RIGHT]) {
|
||||
queues["right_color"] = to_json(stats);
|
||||
overflow_count += stats.overflow_count;
|
||||
}
|
||||
}
|
||||
response->success = true;
|
||||
response->message =
|
||||
nlohmann::json{
|
||||
{"namespace", node_->get_namespace()},
|
||||
{"overflow_count", overflow_count},
|
||||
{"statistics_reset", reset},
|
||||
{"queues", queues},
|
||||
}
|
||||
.dump();
|
||||
if (queues.empty()) {
|
||||
RCLCPP_WARN(logger_, "No enabled color streams; color queue statistics are empty");
|
||||
}
|
||||
} catch (const std::exception& error) {
|
||||
response->success = false;
|
||||
response->message = error.what();
|
||||
}
|
||||
}
|
||||
|
||||
void OBCameraNode::getPointCloudDecimationCallback(
|
||||
const std::shared_ptr<GetInt32::Request>& request,
|
||||
std::shared_ptr<GetInt32::Response>& response) {
|
||||
|
||||
Reference in New Issue
Block a user