Refactor code for improved readability and consistency

This commit is contained in:
slz
2026-06-10 15:17:15 +08:00
parent 77695a78c8
commit 14b62847eb
23 changed files with 271 additions and 275 deletions
@@ -17,8 +17,8 @@ class CameraExampleNode : public rclcpp::Node {
get_params_client_ = this->create_client<orbbec_camera_msgs::srv::GetUserCalibParams>( get_params_client_ = this->create_client<orbbec_camera_msgs::srv::GetUserCalibParams>(
"/camera/get_user_calib_params"); "/camera/get_user_calib_params");
set_streams_client_ = this->create_client<std_srvs::srv::SetBool>("/camera/set_streams_enable"); set_streams_client_ = this->create_client<std_srvs::srv::SetBool>("/camera/set_streams_enable");
set_color_ae_roi_client_ = this->create_client<orbbec_camera_msgs::srv::SetArrays>( set_color_ae_roi_client_ =
"/camera/set_color_ae_roi"); this->create_client<orbbec_camera_msgs::srv::SetArrays>("/camera/set_color_ae_roi");
get_device_info_client_ = get_device_info_client_ =
this->create_client<orbbec_camera_msgs::srv::GetDeviceInfo>("/camera/get_device_info"); this->create_client<orbbec_camera_msgs::srv::GetDeviceInfo>("/camera/get_device_info");
} }
@@ -49,8 +49,8 @@ class ImageSyncNode : public rclcpp::Node {
last_time_(0.0), last_time_(0.0),
frame_interval_(1.0 / hz), frame_interval_(1.0 / hz),
stop_display_thread_(false) { stop_display_thread_(false) {
sync_topics_ = sync_topics_ = this->declare_parameter<std::vector<std::string>>("sync_topics",
this->declare_parameter<std::vector<std::string>>("sync_topics", std::vector<std::string>{}); std::vector<std::string>{});
queue_size_ = this->declare_parameter<int>("queue_size", 10); queue_size_ = this->declare_parameter<int>("queue_size", 10);
sync_tolerance_ms_ = sync_tolerance_ms_ =
this->declare_parameter<double>("sync_tolerance_ms", frame_interval_ * 500.0); this->declare_parameter<double>("sync_tolerance_ms", frame_interval_ * 500.0);
@@ -70,8 +70,8 @@ class ImageSyncNode : public rclcpp::Node {
validate_topics(); validate_topics();
topic_infos_ = make_topic_infos(sync_topics_); topic_infos_ = make_topic_infos(sync_topics_);
RCLCPP_INFO(this->get_logger(), "image sync node started with %zu topic(s):", RCLCPP_INFO(this->get_logger(),
sync_topics_.size()); "image sync node started with %zu topic(s):", sync_topics_.size());
for (const auto &topic : sync_topics_) { for (const auto &topic : sync_topics_) {
RCLCPP_INFO(this->get_logger(), " %s", topic.c_str()); RCLCPP_INFO(this->get_logger(), " %s", topic.c_str());
} }
@@ -325,16 +325,16 @@ class ImageSyncNode : public rclcpp::Node {
using Policy = message_filters::sync_policies::ApproximateTime<Image, Image>; using Policy = message_filters::sync_policies::ApproximateTime<Image, Image>;
using Sync = message_filters::Synchronizer<Policy>; using Sync = message_filters::Synchronizer<Policy>;
auto sync = std::make_shared<Sync>(Policy(queue_size_), subscribers_[0], subscribers_[1]); auto sync = std::make_shared<Sync>(Policy(queue_size_), subscribers_[0], subscribers_[1]);
sync->registerCallback(std::bind(&ImageSyncNode::sync_callback<ImageConstPtr, ImageConstPtr>, sync->registerCallback(
this, _1, _2)); std::bind(&ImageSyncNode::sync_callback<ImageConstPtr, ImageConstPtr>, this, _1, _2));
configure_synchronizer(sync); configure_synchronizer(sync);
} }
void create_synchronizer_3() { void create_synchronizer_3() {
using Policy = message_filters::sync_policies::ApproximateTime<Image, Image, Image>; using Policy = message_filters::sync_policies::ApproximateTime<Image, Image, Image>;
using Sync = message_filters::Synchronizer<Policy>; using Sync = message_filters::Synchronizer<Policy>;
auto sync = auto sync = std::make_shared<Sync>(Policy(queue_size_), subscribers_[0], subscribers_[1],
std::make_shared<Sync>(Policy(queue_size_), subscribers_[0], subscribers_[1], subscribers_[2]); subscribers_[2]);
sync->registerCallback( sync->registerCallback(
std::bind(&ImageSyncNode::sync_callback<ImageConstPtr, ImageConstPtr, ImageConstPtr>, this, std::bind(&ImageSyncNode::sync_callback<ImageConstPtr, ImageConstPtr, ImageConstPtr>, this,
_1, _2, _3)); _1, _2, _3));
@@ -346,9 +346,9 @@ class ImageSyncNode : public rclcpp::Node {
using Sync = message_filters::Synchronizer<Policy>; using Sync = message_filters::Synchronizer<Policy>;
auto sync = std::make_shared<Sync>(Policy(queue_size_), subscribers_[0], subscribers_[1], auto sync = std::make_shared<Sync>(Policy(queue_size_), subscribers_[0], subscribers_[1],
subscribers_[2], subscribers_[3]); subscribers_[2], subscribers_[3]);
sync->registerCallback(std::bind(&ImageSyncNode::sync_callback<ImageConstPtr, ImageConstPtr, sync->registerCallback(std::bind(
ImageConstPtr, ImageConstPtr>, &ImageSyncNode::sync_callback<ImageConstPtr, ImageConstPtr, ImageConstPtr, ImageConstPtr>,
this, _1, _2, _3, _4)); this, _1, _2, _3, _4));
configure_synchronizer(sync); configure_synchronizer(sync);
} }
@@ -358,10 +358,10 @@ class ImageSyncNode : public rclcpp::Node {
using Sync = message_filters::Synchronizer<Policy>; using Sync = message_filters::Synchronizer<Policy>;
auto sync = std::make_shared<Sync>(Policy(queue_size_), subscribers_[0], subscribers_[1], auto sync = std::make_shared<Sync>(Policy(queue_size_), subscribers_[0], subscribers_[1],
subscribers_[2], subscribers_[3], subscribers_[4]); subscribers_[2], subscribers_[3], subscribers_[4]);
sync->registerCallback(std::bind(&ImageSyncNode::sync_callback<ImageConstPtr, ImageConstPtr, sync->registerCallback(
ImageConstPtr, ImageConstPtr, std::bind(&ImageSyncNode::sync_callback<ImageConstPtr, ImageConstPtr, ImageConstPtr,
ImageConstPtr>, ImageConstPtr, ImageConstPtr>,
this, _1, _2, _3, _4, _5)); this, _1, _2, _3, _4, _5));
configure_synchronizer(sync); configure_synchronizer(sync);
} }
@@ -369,13 +369,13 @@ class ImageSyncNode : public rclcpp::Node {
using Policy = using Policy =
message_filters::sync_policies::ApproximateTime<Image, Image, Image, Image, Image, Image>; message_filters::sync_policies::ApproximateTime<Image, Image, Image, Image, Image, Image>;
using Sync = message_filters::Synchronizer<Policy>; using Sync = message_filters::Synchronizer<Policy>;
auto sync = std::make_shared<Sync>(Policy(queue_size_), subscribers_[0], subscribers_[1], auto sync =
subscribers_[2], subscribers_[3], subscribers_[4], std::make_shared<Sync>(Policy(queue_size_), subscribers_[0], subscribers_[1],
subscribers_[5]); subscribers_[2], subscribers_[3], subscribers_[4], subscribers_[5]);
sync->registerCallback(std::bind(&ImageSyncNode::sync_callback<ImageConstPtr, ImageConstPtr, sync->registerCallback(
ImageConstPtr, ImageConstPtr, std::bind(&ImageSyncNode::sync_callback<ImageConstPtr, ImageConstPtr, ImageConstPtr,
ImageConstPtr, ImageConstPtr>, ImageConstPtr, ImageConstPtr, ImageConstPtr>,
this, _1, _2, _3, _4, _5, _6)); this, _1, _2, _3, _4, _5, _6));
configure_synchronizer(sync); configure_synchronizer(sync);
} }
@@ -386,11 +386,10 @@ class ImageSyncNode : public rclcpp::Node {
auto sync = std::make_shared<Sync>(Policy(queue_size_), subscribers_[0], subscribers_[1], auto sync = std::make_shared<Sync>(Policy(queue_size_), subscribers_[0], subscribers_[1],
subscribers_[2], subscribers_[3], subscribers_[4], subscribers_[2], subscribers_[3], subscribers_[4],
subscribers_[5], subscribers_[6]); subscribers_[5], subscribers_[6]);
sync->registerCallback(std::bind(&ImageSyncNode::sync_callback<ImageConstPtr, ImageConstPtr, sync->registerCallback(std::bind(
ImageConstPtr, ImageConstPtr, &ImageSyncNode::sync_callback<ImageConstPtr, ImageConstPtr, ImageConstPtr, ImageConstPtr,
ImageConstPtr, ImageConstPtr, ImageConstPtr, ImageConstPtr, ImageConstPtr>,
ImageConstPtr>, this, _1, _2, _3, _4, _5, _6, _7));
this, _1, _2, _3, _4, _5, _6, _7));
configure_synchronizer(sync); configure_synchronizer(sync);
} }
@@ -401,11 +400,10 @@ class ImageSyncNode : public rclcpp::Node {
auto sync = std::make_shared<Sync>(Policy(queue_size_), subscribers_[0], subscribers_[1], auto sync = std::make_shared<Sync>(Policy(queue_size_), subscribers_[0], subscribers_[1],
subscribers_[2], subscribers_[3], subscribers_[4], subscribers_[2], subscribers_[3], subscribers_[4],
subscribers_[5], subscribers_[6], subscribers_[7]); subscribers_[5], subscribers_[6], subscribers_[7]);
sync->registerCallback(std::bind(&ImageSyncNode::sync_callback<ImageConstPtr, ImageConstPtr, sync->registerCallback(std::bind(
ImageConstPtr, ImageConstPtr, &ImageSyncNode::sync_callback<ImageConstPtr, ImageConstPtr, ImageConstPtr, ImageConstPtr,
ImageConstPtr, ImageConstPtr, ImageConstPtr, ImageConstPtr, ImageConstPtr, ImageConstPtr>,
ImageConstPtr, ImageConstPtr>, this, _1, _2, _3, _4, _5, _6, _7, _8));
this, _1, _2, _3, _4, _5, _6, _7, _8));
configure_synchronizer(sync); configure_synchronizer(sync);
} }
@@ -486,8 +484,8 @@ class ImageSyncNode : public rclcpp::Node {
if (i >= display_images.size()) { if (i >= display_images.size()) {
break; break;
} }
display_images[i].copyTo(canvas(cv::Rect(x_offset, y_offset, display_images[i].cols, display_images[i].copyTo(
display_images[i].rows))); canvas(cv::Rect(x_offset, y_offset, display_images[i].cols, display_images[i].rows)));
x_offset += column_widths[col] + margin; x_offset += column_widths[col] + margin;
} }
y_offset += row_heights[row] + margin; y_offset += row_heights[row] + margin;
@@ -520,10 +518,9 @@ class ImageSyncNode : public rclcpp::Node {
const double base_t = timestamps[0]; const double base_t = timestamps[0];
for (size_t i = 0; i < timestamps.size(); ++i) { for (size_t i = 0; i < timestamps.size(); ++i) {
std::cout << topic_infos_[i].camera_name << " " << topic_infos_[i].image_type std::cout << topic_infos_[i].camera_name << " " << topic_infos_[i].image_type
<< " stamp: " << std::setprecision(6) << timestamps[i] << " stamp: " << std::setprecision(6) << timestamps[i] << " Delay relative to "
<< " Delay relative to " << topic_infos_[0].camera_name << " " << topic_infos_[0].camera_name << " " << topic_infos_[0].image_type << ": "
<< topic_infos_[0].image_type << ": " << std::setprecision(3) << std::setprecision(3) << (timestamps[i] - base_t) * 1000.0 << " ms" << std::endl;
<< (timestamps[i] - base_t) * 1000.0 << " ms" << std::endl;
} }
double cur = 0.0; double cur = 0.0;
@@ -1,18 +1,18 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023 Orbbec 3D Technology, Inc * Copyright (c) 2023 Orbbec 3D Technology, Inc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
#pragma once #pragma once
#include <message_filters/subscriber.h> #include <message_filters/subscriber.h>
#include <message_filters/sync_policies/approximate_time.h> #include <message_filters/sync_policies/approximate_time.h>
@@ -30,7 +30,7 @@ class D2CViewer {
rmw_qos_profile_t depth_qos, bool use_intra_process = false); rmw_qos_profile_t depth_qos, bool use_intra_process = false);
~D2CViewer(); ~D2CViewer();
void messageCallback(const sensor_msgs::msg::Image::ConstSharedPtr & rgb_msg, void messageCallback(const sensor_msgs::msg::Image::ConstSharedPtr& rgb_msg,
const sensor_msgs::msg::Image::ConstSharedPtr& depth_msg); const sensor_msgs::msg::Image::ConstSharedPtr& depth_msg);
private: private:
@@ -1,18 +1,18 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023 Orbbec 3D Technology, Inc * Copyright (c) 2023 Orbbec 3D Technology, Inc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
#pragma once #pragma once
#include <rclcpp/rclcpp.hpp> #include <rclcpp/rclcpp.hpp>
@@ -1,18 +1,18 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023 Orbbec 3D Technology, Inc * Copyright (c) 2023 Orbbec 3D Technology, Inc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
#pragma once #pragma once
#include "utils.h" #include "utils.h"
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
@@ -1,18 +1,18 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023 Orbbec 3D Technology, Inc * Copyright (c) 2023 Orbbec 3D Technology, Inc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
#pragma once #pragma once
#include <string> #include <string>
@@ -239,9 +239,9 @@ class OBCameraNode {
void captureInitialRosParameters(); void captureInitialRosParameters();
bool isLaunchParamProvided(const std::string &param_name) const; bool isLaunchParamProvided(const std::string& param_name) const;
bool exportConfigJsonToFile(const std::string &file_path, std::string &message); bool exportConfigJsonToFile(const std::string& file_path, std::string& message);
void exportConfigJsonIfRequested(); void exportConfigJsonIfRequested();
@@ -249,8 +249,8 @@ class OBCameraNode {
void syncConfigJsonDeviceSettings(); void syncConfigJsonDeviceSettings();
void syncConfigJsonFilterSettings(const std::vector<std::shared_ptr<ob::Filter>> &filters, void syncConfigJsonFilterSettings(const std::vector<std::shared_ptr<ob::Filter>>& filters,
const std::string &sensor_name); const std::string& sensor_name);
void setupProfiles(); void setupProfiles();
@@ -282,19 +282,19 @@ class OBCameraNode {
void publishDepthFiltersStatus(); void publishDepthFiltersStatus();
DepthFilterState buildDepthFilterState(const std::string &filter_name, bool enabled, DepthFilterState buildDepthFilterState(const std::string& filter_name, bool enabled,
const std::shared_ptr<ob::Filter> &filter) const; const std::shared_ptr<ob::Filter>& filter) const;
static std::string normalizeDepthFilterName(const std::string &filter_name); static std::string normalizeDepthFilterName(const std::string& filter_name);
static void appendDepthFilterParam(DepthFilterState &filter_state, const std::string &name, static void appendDepthFilterParam(DepthFilterState& filter_state, const std::string& name,
const std::string &value); const std::string& value);
void updateDepthFilterEnabledCache(const std::string &filter_name, bool enabled); void updateDepthFilterEnabledCache(const std::string& filter_name, bool enabled);
bool applyNamedDepthFilterConfig( bool applyNamedDepthFilterConfig(
const std::string &filter_name, bool enabled, const std::string& filter_name, bool enabled,
const std::vector<orbbec_camera_msgs::msg::DepthFilterParam> &params, std::string &message); const std::vector<orbbec_camera_msgs::msg::DepthFilterParam>& params, std::string& message);
void setupCameraInfo(); void setupCameraInfo();
@@ -435,8 +435,8 @@ 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, void exportConfigJsonCallback(const std::shared_ptr<SetString::Request>& request,
std::shared_ptr<SetString::Response> &response); std::shared_ptr<SetString::Response>& response);
bool writeCustomerData(const std::string& data); bool writeCustomerData(const std::string& data);
@@ -1,18 +1,18 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023 Orbbec 3D Technology, Inc * Copyright (c) 2023 Orbbec 3D Technology, Inc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
#pragma once #pragma once
#include "jpeg_decoder.h" #include "jpeg_decoder.h"
@@ -1,18 +1,18 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023 Orbbec 3D Technology, Inc * Copyright (c) 2023 Orbbec 3D Technology, Inc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
#pragma once #pragma once
#include <rclcpp/rclcpp.hpp> #include <rclcpp/rclcpp.hpp>
+16 -16
View File
@@ -71,20 +71,21 @@ inline std::string formatObErrorWithStatus(const ob::Error& e) {
RCLCPP_ERROR(logger_, "Unknown exception in %s at line %d", __FUNCTION__, __LINE__); \ RCLCPP_ERROR(logger_, "Unknown exception in %s at line %d", __FUNCTION__, __LINE__); \
} }
#define TRY_TO_SET_PROPERTY(func, property, value) \ #define TRY_TO_SET_PROPERTY(func, property, value) \
try { \ try { \
device_->func(property, value); \ device_->func(property, value); \
} catch (const ob::Error& e) { \ } catch (const ob::Error& e) { \
RCLCPP_ERROR_STREAM(logger_, "Failed to set " << property << " to " << value << " in " \ RCLCPP_ERROR_STREAM(logger_, "Failed to set " << property << " to " << value << " in " \
<< __FUNCTION__ << " at line " << __LINE__ \ << __FUNCTION__ << " at line " << __LINE__ \
<< ": " << orbbec_camera::formatObErrorWithStatus(e)); \ << ": " \
} catch (const std::exception& e) { \ << orbbec_camera::formatObErrorWithStatus(e)); \
RCLCPP_ERROR_STREAM(logger_, "Failed to set " << property << " to " << value << " in " \ } catch (const std::exception& e) { \
<< __FUNCTION__ << " at line " << __LINE__ \ RCLCPP_ERROR_STREAM(logger_, "Failed to set " << property << " to " << value << " in " \
<< ": " << e.what()); \ << __FUNCTION__ << " at line " << __LINE__ \
} catch (...) { \ << ": " << e.what()); \
RCLCPP_ERROR_STREAM(logger_, "Failed to set " << property << " to " << value << " in " \ } catch (...) { \
<< __FUNCTION__ << " at line " << __LINE__); \ RCLCPP_ERROR_STREAM(logger_, "Failed to set " << property << " to " << value << " in " \
<< __FUNCTION__ << " at line " << __LINE__); \
} }
// Macros for checking conditions and comparing values // Macros for checking conditions and comparing values
@@ -168,8 +169,7 @@ OBLogSeverity obLogSeverityFromString(const std::string_view& log_level);
std::string getObSdkLogDirectory(); std::string getObSdkLogDirectory();
std::string configureObSdkLoggerForTool(const std::string& tool_name, std::string configureObSdkLoggerForTool(const std::string& tool_name, const std::string& log_level);
const std::string& log_level);
OBFormat OBFormatFromString(const std::string& format); OBFormat OBFormatFromString(const std::string& format);
@@ -181,10 +181,12 @@ class SingleServiceBenchmark {
if (response->success) { if (response->success) {
success++; success++;
RCLCPP_INFO(nh_->get_logger(), "Call %s %d/%d succeeded (cost: %.2f ms)", RCLCPP_INFO(nh_->get_logger(), "Call %s %d/%d succeeded (cost: %.2f ms)",
service_name_.c_str(), i + 1, count_, dt); service_name_.c_str(), i + 1, count_, dt);
} else { } else {
RCLCPP_WARN(nh_->get_logger(), "Call %s %d/%d (cost: %.2f ms) responded with success=false, message='%s'", RCLCPP_WARN(
service_name_.c_str(), i + 1, count_, dt,response->message.c_str()); nh_->get_logger(),
"Call %s %d/%d (cost: %.2f ms) responded with success=false, message='%s'",
service_name_.c_str(), i + 1, count_, dt, response->message.c_str());
} }
} else { } else {
success++; success++;
+14 -14
View File
@@ -1,18 +1,18 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023 Orbbec 3D Technology, Inc * Copyright (c) 2023 Orbbec 3D Technology, Inc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
#include "orbbec_camera/dynamic_params.h" #include "orbbec_camera/dynamic_params.h"
namespace orbbec_camera { namespace orbbec_camera {
+14 -14
View File
@@ -1,18 +1,18 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023 Orbbec 3D Technology, Inc * Copyright (c) 2023 Orbbec 3D Technology, Inc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
#include "orbbec_camera/jetson_nv_decoder.h" #include "orbbec_camera/jetson_nv_decoder.h"
#include <NvJpegDecoder.h> #include <NvJpegDecoder.h>
#include <NvV4l2Element.h> #include <NvV4l2Element.h>
+14 -14
View File
@@ -1,18 +1,18 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023 Orbbec 3D Technology, Inc * Copyright (c) 2023 Orbbec 3D Technology, Inc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
#include <orbbec_camera/jpeg_decoder.h> #include <orbbec_camera/jpeg_decoder.h>
namespace orbbec_camera { namespace orbbec_camera {
+6 -7
View File
@@ -296,9 +296,9 @@ void OBLidarNode::setupProfiles() {
} }
} catch (const ob::Error &ex) { } catch (const ob::Error &ex) {
RCLCPP_ERROR_STREAM( RCLCPP_ERROR_STREAM(logger_, "Failed to get "
logger_, "Failed to get " << stream_name_[elem] << stream_name_[elem] << " profile: "
<< " profile: " << orbbec_camera::formatObErrorWithStatus(ex)); << orbbec_camera::formatObErrorWithStatus(ex));
RCLCPP_ERROR_STREAM(logger_, "Stream: " << magic_enum::enum_name(elem.first) RCLCPP_ERROR_STREAM(logger_, "Stream: " << magic_enum::enum_name(elem.first)
<< ", Stream Index: " << elem.second << ", Stream Index: " << elem.second
<< ", Scan Rate: " << rate_[elem] << ", Scan Rate: " << rate_[elem]
@@ -1262,10 +1262,9 @@ void OBLidarNode::calcAndPublishStaticTransform() {
ex = base_stream_profile->getExtrinsicTo(stream_profile_[GYRO]); ex = base_stream_profile->getExtrinsicTo(stream_profile_[GYRO]);
RCLCPP_INFO_STREAM(logger_, "Using GYRO extrinsic for IMU"); RCLCPP_INFO_STREAM(logger_, "Using GYRO extrinsic for IMU");
} catch (const ob::Error &e2) { } catch (const ob::Error &e2) {
RCLCPP_ERROR_STREAM( RCLCPP_ERROR_STREAM(logger_, "Failed to get "
logger_, "Failed to get " << frame_id << frame_id << " extrinsic from both ACCEL and GYRO: "
<< " extrinsic from both ACCEL and GYRO: " << orbbec_camera::formatObErrorWithStatus(e2));
<< orbbec_camera::formatObErrorWithStatus(e2));
ex = OBExtrinsic({{1, 0, 0, 0, 1, 0, 0, 0, 1}, {0, 0, 0}}); ex = OBExtrinsic({{1, 0, 0, 0, 1, 0, 0, 0, 1}, {0, 0, 0}});
} }
} }
+14 -14
View File
@@ -1,18 +1,18 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023 Orbbec 3D Technology, Inc * Copyright (c) 2023 Orbbec 3D Technology, Inc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
#include "orbbec_camera/rk_mpp_decoder.h" #include "orbbec_camera/rk_mpp_decoder.h"
#include <rclcpp/rclcpp.hpp> #include <rclcpp/rclcpp.hpp>
+2 -2
View File
@@ -1495,8 +1495,8 @@ void OBCameraNode::switchIRCameraCallback(const std::shared_ptr<SetString::Reque
} }
} }
void OBCameraNode::exportConfigJsonCallback(const std::shared_ptr<SetString::Request> &request, void OBCameraNode::exportConfigJsonCallback(const std::shared_ptr<SetString::Request>& request,
std::shared_ptr<SetString::Response> &response) { std::shared_ptr<SetString::Response>& response) {
response->success = exportConfigJsonToFile(request->data, response->message); response->success = exportConfigJsonToFile(request->data, response->message);
} }
+14 -14
View File
@@ -1,18 +1,18 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023 Orbbec 3D Technology, Inc * Copyright (c) 2023 Orbbec 3D Technology, Inc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
#include "orbbec_camera/utils.h" #include "orbbec_camera/utils.h"
#include "orbbec_camera/synced_imu_publisher.h" #include "orbbec_camera/synced_imu_publisher.h"
#include <rclcpp/rclcpp.hpp> #include <rclcpp/rclcpp.hpp>
+2 -4
View File
@@ -44,8 +44,7 @@ void waitForFirmwareLogDrain(const rclcpp::Logger &logger) {
} }
bool isSdkLogEnabled(const std::string &log_level) { bool isSdkLogEnabled(const std::string &log_level) {
return orbbec_camera::obLogSeverityFromString(log_level) != return orbbec_camera::obLogSeverityFromString(log_level) != OBLogSeverity::OB_LOG_SEVERITY_OFF;
OBLogSeverity::OB_LOG_SEVERITY_OFF;
} }
struct CliArgs { struct CliArgs {
@@ -629,8 +628,7 @@ bool updatePresetFirmware(const rclcpp::Logger &logger, const std::shared_ptr<ob
FirmwareUpdateResult updateFirmware(const rclcpp::Logger &logger, FirmwareUpdateResult updateFirmware(const rclcpp::Logger &logger,
const std::shared_ptr<ob::Device> &device, const std::shared_ptr<ob::Device> &device,
const std::string &firmware_path, const std::string &firmware_path, bool firmware_log_enabled) {
bool firmware_log_enabled) {
FirmwareUpdateResult result; FirmwareUpdateResult result;
if (firmware_path.empty()) { if (firmware_path.empty()) {
result.success = true; result.success = true;
+14 -14
View File
@@ -1,18 +1,18 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023 Orbbec 3D Technology, Inc * Copyright (c) 2023 Orbbec 3D Technology, Inc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
#include <orbbec_camera/ob_camera_node.h> #include <orbbec_camera/ob_camera_node.h>
int main() { int main() {
+19 -18
View File
@@ -177,16 +177,18 @@ class ObBenchmark : public rclcpp::Node {
std::ofstream file; std::ofstream file;
file.open(filename, std::ios_base::app); file.open(filename, std::ios_base::app);
if (file.is_open()) { if (file.is_open()) {
file << "Time,CPU,Memory(MB)" << "\n"; file << "Time,CPU,Memory(MB)"
<< "\n";
for (int i = skip_number_; i < usage_count_ - 1; i++) { for (int i = skip_number_; i < usage_count_ - 1; i++) {
file << current_time_[i] << "," << cpu_usage_[i] << "%" << "," << memory_usage_[i] << "\n"; file << current_time_[i] << "," << cpu_usage_[i] << "%"
<< "," << memory_usage_[i] << "\n";
} }
float cpu_average = float cpu_average = std::accumulate(cpu_usage_.begin() + skip_number_,
std::accumulate(cpu_usage_.begin() + skip_number_, cpu_usage_.begin() + usage_count_ - 1, 0.0f) / cpu_usage_.begin() + usage_count_ - 1, 0.0f) /
(usage_count_ - (skip_number_+1)); (usage_count_ - (skip_number_ + 1));
float memory_average = std::accumulate(memory_usage_.begin() + skip_number_, float memory_average = std::accumulate(memory_usage_.begin() + skip_number_,
memory_usage_.begin() + usage_count_ - 1, 0.0f) / memory_usage_.begin() + usage_count_ - 1, 0.0f) /
(usage_count_ - (skip_number_+1)); (usage_count_ - (skip_number_ + 1));
file << "Average: ," << cpu_average << "%, " << memory_average << "\n"; file << "Average: ," << cpu_average << "%, " << memory_average << "\n";
RCLCPP_INFO_STREAM(rclcpp::get_logger("ObBenchmark"), RCLCPP_INFO_STREAM(rclcpp::get_logger("ObBenchmark"),
"Average: " << cpu_average << "%" << memory_average << "MB"); "Average: " << cpu_average << "%" << memory_average << "MB");
@@ -200,7 +202,7 @@ class ObBenchmark : public rclcpp::Node {
usage_count_ = 0; usage_count_ = 0;
++launch_count_; ++launch_count_;
} }
void kill_process(const std::string& process_name) { void kill_process(const std::string& process_name) {
std::string command = "ps aux | grep " + process_name + " | grep -v grep | awk '{print $2}'"; std::string command = "ps aux | grep " + process_name + " | grep -v grep | awk '{print $2}'";
std::shared_ptr<FILE> pipe(popen(command.c_str(), "r"), pclose); std::shared_ptr<FILE> pipe(popen(command.c_str(), "r"), pclose);
@@ -224,15 +226,15 @@ void kill_process(const std::string& process_name) {
} }
for (int pid : pids) { for (int pid : pids) {
if (kill(pid, SIGINT) == 0) { if (kill(pid, SIGINT) == 0) {
RCLCPP_INFO_STREAM(rclcpp::get_logger("ObBenchmark"), RCLCPP_INFO_STREAM(rclcpp::get_logger("ObBenchmark"),
"Successfully sent SIGINT (Ctrl+C) to process with PID " << pid); "Successfully sent SIGINT (Ctrl+C) to process with PID " << pid);
} else { } else {
RCLCPP_ERROR_STREAM(this->get_logger(), RCLCPP_ERROR_STREAM(this->get_logger(),
"Failed to send SIGINT to process with PID " << pid); "Failed to send SIGINT to process with PID " << pid);
} }
} }
} }
void stat_process() { void stat_process() {
const char* ros2_launch = "/opt/ros/humble/bin/ros2"; const char* ros2_launch = "/opt/ros/humble/bin/ros2";
std::string start_launch = "ob_benchmark_" + std::to_string(launch_count_) + ".launch.py"; std::string start_launch = "ob_benchmark_" + std::to_string(launch_count_) + ".launch.py";
@@ -272,9 +274,8 @@ void kill_process(const std::string& process_name) {
current_time_.push_back(getCurrentTimes()); current_time_.push_back(getCurrentTimes());
RCLCPP_INFO_STREAM(rclcpp::get_logger("ObBenchmark"), RCLCPP_INFO_STREAM(rclcpp::get_logger("ObBenchmark"),
"CurrentTimes: " << current_time_[usage_count_]); "CurrentTimes: " << current_time_[usage_count_]);
RCLCPP_INFO_STREAM(rclcpp::get_logger("ObBenchmark"), "CPU Usage of " RCLCPP_INFO_STREAM(rclcpp::get_logger("ObBenchmark"),
<< process_name_ << ":" "CPU Usage of " << process_name_ << ":" << cpu_usage_[usage_count_] << "%");
<< cpu_usage_[usage_count_] << "%");
RCLCPP_INFO_STREAM( RCLCPP_INFO_STREAM(
rclcpp::get_logger("ObBenchmark"), rclcpp::get_logger("ObBenchmark"),
"Memory Usage of " << process_name_ << ":" << memory_usage_[usage_count_] << "MB"); "Memory Usage of " << process_name_ << ":" << memory_usage_[usage_count_] << "MB");
-1
View File
@@ -68,7 +68,6 @@ class StartBenchmark : public rclcpp::Node {
std::vector<rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr> std::vector<rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr>
color_point_cloud_subs_; color_point_cloud_subs_;
std::vector<std::string> camera_name_; std::vector<std::string> camera_name_;
std::vector<std::string> color_topics_; std::vector<std::string> color_topics_;
std::vector<std::string> depth_topics_; std::vector<std::string> depth_topics_;
+1 -1
View File
@@ -1,6 +1,6 @@
#include "topic_statistics.hpp" #include "topic_statistics.hpp"
int main(int argc, char * argv[]) { int main(int argc, char* argv[]) {
rclcpp::init(argc, argv); rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<orbbec_camera::tools::TopicStatistics>()); rclcpp::spin(std::make_shared<orbbec_camera::tools::TopicStatistics>());
rclcpp::shutdown(); rclcpp::shutdown();