mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-04 12:07:46 +08:00
fixed compile error
This commit is contained in:
@@ -26,6 +26,7 @@ endif ()
|
||||
set(dependencies
|
||||
ament_cmake
|
||||
ament_index_cpp
|
||||
backward_ros
|
||||
Eigen3
|
||||
builtin_interfaces
|
||||
cv_bridge
|
||||
@@ -119,6 +120,7 @@ set(COMMON_LIBRARIES
|
||||
-L${ORBBEC_LIBS_DIR}
|
||||
Threads::Threads
|
||||
-lrt
|
||||
-ldw
|
||||
)
|
||||
if (USE_RK_HW_DECODER)
|
||||
list(APPEND COMMON_LIBRARIES
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "libobsensor/ObSensor.hpp"
|
||||
#include <pthread.h>
|
||||
#include <std_srvs/srv/empty.hpp>
|
||||
#include <backward_ros/backward.hpp>
|
||||
|
||||
namespace orbbec_camera {
|
||||
|
||||
|
||||
@@ -35,6 +35,33 @@ inline void LogFatal(const char* file, int line, const std::string& message) {
|
||||
}
|
||||
} // namespace orbbec_camera
|
||||
|
||||
#define TRY_EXECUTE_BLOCK(block) \
|
||||
try { \
|
||||
block; \
|
||||
} catch (const ob::Error& e) { \
|
||||
RCLCPP_ERROR(logger_, "Error in %s at line %d: %s", __FUNCTION__, __LINE__, e.getMessage()); \
|
||||
} catch (const std::exception& e) { \
|
||||
RCLCPP_ERROR(logger_, "Exception in %s at line %d: %s", __FUNCTION__, __LINE__, e.what()); \
|
||||
} catch (...) { \
|
||||
RCLCPP_ERROR(logger_, "Unknown exception in %s at line %d", __FUNCTION__, __LINE__); \
|
||||
}
|
||||
|
||||
#define TRY_TO_SET_PROPERTY(func, property, value) \
|
||||
try { \
|
||||
device_->func(property, value); \
|
||||
} catch (const ob::Error& e) { \
|
||||
RCLCPP_ERROR_STREAM(logger_, "Failed to set " << property << " to " << value << " in " \
|
||||
<< __FUNCTION__ << " at line " << __LINE__ \
|
||||
<< ": " << e.getMessage()); \
|
||||
} catch (const std::exception& e) { \
|
||||
RCLCPP_ERROR_STREAM(logger_, "Failed to set " << property << " to " << value << " in " \
|
||||
<< __FUNCTION__ << " at line " << __LINE__ \
|
||||
<< ": " << e.what()); \
|
||||
} catch (...) { \
|
||||
RCLCPP_ERROR_STREAM(logger_, "Failed to set " << property << " to " << value << " in " \
|
||||
<< __FUNCTION__ << " at line " << __LINE__); \
|
||||
}
|
||||
|
||||
// Macros for checking conditions and comparing values
|
||||
#define CHECK(condition) \
|
||||
(!(condition) ? LogFatal(__FILE__, __LINE__, "Check failed: " #condition) : (void)0)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<depend>ament_lint_auto</depend>
|
||||
<depend>ament_lint_common</depend>
|
||||
<depend>ament_index_cpp</depend>
|
||||
<depend>backward_ros</depend>
|
||||
<depend>image_transport</depend>
|
||||
<depend>image_publisher</depend>
|
||||
<depend>rclcpp_components</depend>
|
||||
|
||||
@@ -131,18 +131,6 @@ void OBCameraNode::clean() noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
#define TRY_TO_SET_PROPERTY(func, property, value) \
|
||||
try { \
|
||||
device_->func(property, value); \
|
||||
} catch (const ob::Error &e) { \
|
||||
RCLCPP_ERROR_STREAM( \
|
||||
logger_, "Failed to set " << property << " to " << value << ": " << e.getMessage()); \
|
||||
} catch (const std::exception &e) { \
|
||||
RCLCPP_ERROR_STREAM(logger_, \
|
||||
"Failed to set " << property << " to " << value << ": " << e.what()); \
|
||||
} catch (...) { \
|
||||
RCLCPP_ERROR_STREAM(logger_, "Failed to set " << property << " to " << value); \
|
||||
}
|
||||
|
||||
void OBCameraNode::setupDevices() {
|
||||
auto sensor_list = device_->getSensorList();
|
||||
|
||||
@@ -367,17 +367,15 @@ void OBCameraNodeDriver::initializeDevice(const std::shared_ptr<ob::Device> &dev
|
||||
serial_number_ = device_info_->getSerialNumber();
|
||||
CHECK_NOTNULL(device_info_.get());
|
||||
device_unique_id_ = device_info_->getUid();
|
||||
try {
|
||||
if (enable_sync_host_time_ && !isOpenNIDevice(device_info_->getPid())) {
|
||||
device_->timerSyncWithHost();
|
||||
sync_host_time_timer_ = this->create_wall_timer(std::chrono::milliseconds(30000), [this]() {
|
||||
if (device_) {
|
||||
device_->timerSyncWithHost();
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (...) {
|
||||
if (enable_sync_host_time_ && !isOpenNIDevice(device_info_->pid())) {
|
||||
TRY_EXECUTE_BLOCK(device_->timerSyncWithHost());
|
||||
sync_host_time_timer_ = this->create_wall_timer(std::chrono::milliseconds(30000), [this]() {
|
||||
if (device_) {
|
||||
TRY_EXECUTE_BLOCK(device_->timerSyncWithHost());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
RCLCPP_INFO_STREAM(logger_, "Device " << device_info_->getName() << " connected");
|
||||
RCLCPP_INFO_STREAM(logger_, "Serial number: " << device_info_->getSerialNumber());
|
||||
RCLCPP_INFO_STREAM(logger_, "Firmware version: " << device_info_->getFirmwareVersion());
|
||||
@@ -388,7 +386,7 @@ void OBCameraNodeDriver::initializeDevice(const std::shared_ptr<ob::Device> &dev
|
||||
auto time_cost = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::high_resolution_clock::now() - start_time_);
|
||||
RCLCPP_INFO_STREAM(logger_, "Start device cost " << time_cost.count() << " ms");
|
||||
}
|
||||
} // namespace orbbec_camera
|
||||
|
||||
void OBCameraNodeDriver::connectNetDevice(const std::string &net_device_ip, int net_device_port) {
|
||||
if (net_device_ip.empty() || net_device_port == 0) {
|
||||
|
||||
Reference in New Issue
Block a user