mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-13 07:49:49 +08:00
fixed hotplug
This commit is contained in:
@@ -42,9 +42,11 @@ if (NOT ORBBEC_SDK_FOUND)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} SHARED
|
add_library(${PROJECT_NAME} SHARED
|
||||||
src/device_ctrl_service.cpp
|
src/dynamic_params.cpp
|
||||||
src/ob_camera_node_factory.cpp
|
src/ob_camera_node_factory.cpp
|
||||||
src/ob_camera_node.cpp
|
src/ob_camera_node.cpp
|
||||||
|
src/ros_param_backend.cpp
|
||||||
|
src/ros_service.cpp
|
||||||
src/utils.cpp
|
src/utils.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2013-2022 Orbbec 3D Technology, Inc */
|
||||||
|
/* */
|
||||||
|
/* PROPRIETARY RIGHTS of Orbbec 3D Technology are involved in the */
|
||||||
|
/* subject matter of this material. All manufacturing, reproduction, use, */
|
||||||
|
/* and sales rights pertaining to this subject matter are governed by the */
|
||||||
|
/* license agreement. The recipient of this software implicitly accepts */
|
||||||
|
/* the terms of the license. */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <rclcpp/rclcpp.hpp>
|
||||||
|
|
||||||
|
#include "ros_param_backend.h"
|
||||||
|
|
||||||
|
namespace orbbec_camera {
|
||||||
|
class Parameters {
|
||||||
|
public:
|
||||||
|
Parameters(rclcpp::Node* node);
|
||||||
|
~Parameters();
|
||||||
|
rclcpp::ParameterValue setParam(const std::string& param_name, rclcpp::ParameterValue initial_value,
|
||||||
|
const std::function<void(const rclcpp::Parameter&)>& func =
|
||||||
|
std::function<void(const rclcpp::Parameter&)>(),
|
||||||
|
const rcl_interfaces::msg::ParameterDescriptor& descriptor =
|
||||||
|
rcl_interfaces::msg::ParameterDescriptor());
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void setParamT(std::string param_name, rclcpp::ParameterValue initial_value, T& param,
|
||||||
|
std::function<void(const rclcpp::Parameter&)> func =
|
||||||
|
std::function<void(const rclcpp::Parameter&)>(),
|
||||||
|
rcl_interfaces::msg::ParameterDescriptor descriptor =
|
||||||
|
rcl_interfaces::msg::ParameterDescriptor());
|
||||||
|
template <class T>
|
||||||
|
void setParamValue(T& param, const T& value); // function updates the parameter value both
|
||||||
|
// locally and in the parameters server
|
||||||
|
void removeParam(const std::string& param_name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
private:
|
||||||
|
rclcpp::Node* node_;
|
||||||
|
rclcpp::Logger logger_;
|
||||||
|
std::map<std::string, std::vector<std::function<void(const rclcpp::Parameter&)> > >
|
||||||
|
param_functions_;
|
||||||
|
std::map<void*, std::string> param_names_;
|
||||||
|
ParametersBackend params_backend_;
|
||||||
|
};
|
||||||
|
} // namespace orbbec_camera
|
||||||
@@ -44,6 +44,7 @@
|
|||||||
#include "orbbec_camera_msgs/srv/set_int32.hpp"
|
#include "orbbec_camera_msgs/srv/set_int32.hpp"
|
||||||
|
|
||||||
#include "orbbec_camera/constants.h"
|
#include "orbbec_camera/constants.h"
|
||||||
|
#include "orbbec_camera/dynamic_params.h"
|
||||||
|
|
||||||
#define STREAM_NAME(sip) \
|
#define STREAM_NAME(sip) \
|
||||||
(static_cast<std::ostringstream&&>(std::ostringstream() \
|
(static_cast<std::ostringstream&&>(std::ostringstream() \
|
||||||
@@ -89,9 +90,16 @@ const stream_index_pair ACCEL{OB_STREAM_ACCEL, 0};
|
|||||||
const std::vector<stream_index_pair> IMAGE_STREAMS = {DEPTH, IR0, COLOR};
|
const std::vector<stream_index_pair> IMAGE_STREAMS = {DEPTH, IR0, COLOR};
|
||||||
|
|
||||||
const std::vector<stream_index_pair> HID_STREAMS = {GYRO, ACCEL};
|
const std::vector<stream_index_pair> HID_STREAMS = {GYRO, ACCEL};
|
||||||
|
|
||||||
class OBCameraNode {
|
class OBCameraNode {
|
||||||
public:
|
public:
|
||||||
OBCameraNode(rclcpp::Node* node, std::shared_ptr<ob::Device> device);
|
OBCameraNode(rclcpp::Node* node, std::shared_ptr<ob::Device> device,
|
||||||
|
std::shared_ptr<Parameters> parameters);
|
||||||
|
template <class T>
|
||||||
|
void setNgetNodeParameter(T& param, const std::string& param_name, const T& default_value,
|
||||||
|
const rcl_interfaces::msg::ParameterDescriptor& parameter_descriptor =
|
||||||
|
rcl_interfaces::msg::ParameterDescriptor()); // set and get parameter
|
||||||
|
|
||||||
~OBCameraNode();
|
~OBCameraNode();
|
||||||
|
|
||||||
void clean();
|
void clean();
|
||||||
@@ -197,6 +205,7 @@ class OBCameraNode {
|
|||||||
private:
|
private:
|
||||||
rclcpp::Node* node_;
|
rclcpp::Node* node_;
|
||||||
std::shared_ptr<ob::Device> device_;
|
std::shared_ptr<ob::Device> device_;
|
||||||
|
std::shared_ptr<Parameters> parameters_;
|
||||||
rclcpp::Logger logger_;
|
rclcpp::Logger logger_;
|
||||||
std::atomic_bool is_running_{false};
|
std::atomic_bool is_running_{false};
|
||||||
std::unique_ptr<ob::Pipeline> pipeline_;
|
std::unique_ptr<ob::Pipeline> pipeline_;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <rclcpp/rclcpp.hpp>
|
#include <rclcpp/rclcpp.hpp>
|
||||||
#include "ob_camera_node.h"
|
#include "ob_camera_node.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "dynamic_params.h"
|
||||||
|
|
||||||
#include "libobsensor/ObSensor.hpp"
|
#include "libobsensor/ObSensor.hpp"
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ class OBCameraNodeFactory : public rclcpp::Node {
|
|||||||
explicit OBCameraNodeFactory(const rclcpp::NodeOptions& node_options = rclcpp::NodeOptions());
|
explicit OBCameraNodeFactory(const rclcpp::NodeOptions& node_options = rclcpp::NodeOptions());
|
||||||
OBCameraNodeFactory(const std::string& node_name, const std::string& ns,
|
OBCameraNodeFactory(const std::string& node_name, const std::string& ns,
|
||||||
const rclcpp::NodeOptions& node_options = rclcpp::NodeOptions());
|
const rclcpp::NodeOptions& node_options = rclcpp::NodeOptions());
|
||||||
~OBCameraNodeFactory() override ;
|
~OBCameraNodeFactory() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
@@ -49,6 +50,7 @@ class OBCameraNodeFactory : public rclcpp::Node {
|
|||||||
std::string usb_port_id_;
|
std::string usb_port_id_;
|
||||||
double reconnect_timeout_;
|
double reconnect_timeout_;
|
||||||
double wait_for_device_timeout_;
|
double wait_for_device_timeout_;
|
||||||
|
std::shared_ptr<Parameters> parameters_;
|
||||||
};
|
};
|
||||||
} // namespace orbbec_camera
|
} // namespace orbbec_camera
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2013-2022 Orbbec 3D Technology, Inc */
|
||||||
|
/* */
|
||||||
|
/* PROPRIETARY RIGHTS of Orbbec 3D Technology are involved in the */
|
||||||
|
/* subject matter of this material. All manufacturing, reproduction, use, */
|
||||||
|
/* and sales rights pertaining to this subject matter are governed by the */
|
||||||
|
/* license agreement. The recipient of this software implicitly accepts */
|
||||||
|
/* the terms of the license. */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <rclcpp/rclcpp.hpp>
|
||||||
|
|
||||||
|
namespace orbbec_camera {
|
||||||
|
class ParametersBackend {
|
||||||
|
public:
|
||||||
|
explicit ParametersBackend(rclcpp::Node* node);
|
||||||
|
~ParametersBackend();
|
||||||
|
void addOnSetParametersCallback(
|
||||||
|
rclcpp::node_interfaces::NodeParametersInterface::OnParametersSetCallbackType callback);
|
||||||
|
|
||||||
|
private:
|
||||||
|
rclcpp::Node* node_;
|
||||||
|
rclcpp::Logger logger_;
|
||||||
|
std::shared_ptr<void> ros_callback_;
|
||||||
|
};
|
||||||
|
} // namespace orbbec_camera
|
||||||
@@ -14,14 +14,14 @@
|
|||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <glog/logging.h>
|
#include <glog/logging.h>
|
||||||
#include <magic_enum.hpp>
|
#include <magic_enum.hpp>
|
||||||
#include "libobsensor/ObSensor.hpp"
|
|
||||||
#include <Eigen/Dense>
|
#include <Eigen/Dense>
|
||||||
#include <tf2/LinearMath/Quaternion.h>
|
#include <tf2/LinearMath/Quaternion.h>
|
||||||
#include <rclcpp/rclcpp.hpp>
|
#include <rclcpp/rclcpp.hpp>
|
||||||
|
|
||||||
|
#include "libobsensor/ObSensor.hpp"
|
||||||
#include "sensor_msgs/distortion_models.hpp"
|
#include "sensor_msgs/distortion_models.hpp"
|
||||||
#include "sensor_msgs/msg/camera_info.hpp"
|
#include "sensor_msgs/msg/camera_info.hpp"
|
||||||
#include <orbbec_camera_msgs/msg/extrinsics.hpp>
|
#include "orbbec_camera_msgs/msg/extrinsics.hpp"
|
||||||
|
|
||||||
namespace orbbec_camera {
|
namespace orbbec_camera {
|
||||||
sensor_msgs::msg::CameraInfo convertToCameraInfo(OBCameraIntrinsic intrinsic,
|
sensor_msgs::msg::CameraInfo convertToCameraInfo(OBCameraIntrinsic intrinsic,
|
||||||
|
|||||||
@@ -0,0 +1,148 @@
|
|||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2013-2022 Orbbec 3D Technology, Inc */
|
||||||
|
/* */
|
||||||
|
/* PROPRIETARY RIGHTS of Orbbec 3D Technology are involved in the */
|
||||||
|
/* subject matter of this material. All manufacturing, reproduction, use, */
|
||||||
|
/* and sales rights pertaining to this subject matter are governed by the */
|
||||||
|
/* license agreement. The recipient of this software implicitly accepts */
|
||||||
|
/* the terms of the license. */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
#include "orbbec_camera/dynamic_params.h"
|
||||||
|
|
||||||
|
namespace orbbec_camera {
|
||||||
|
|
||||||
|
Parameters::Parameters(rclcpp::Node *node)
|
||||||
|
: node_(node), logger_(node_->get_logger()), params_backend_(node) {
|
||||||
|
params_backend_.addOnSetParametersCallback(
|
||||||
|
[this](const std::vector<rclcpp::Parameter> ¶meters) {
|
||||||
|
for (const auto ¶meter : parameters) {
|
||||||
|
if (param_functions_.find(parameter.get_name()) != param_functions_.end()) {
|
||||||
|
auto functions = param_functions_[parameter.get_name()];
|
||||||
|
if (functions.empty()) {
|
||||||
|
RCLCPP_WARN_STREAM(logger_, "Parameter " << parameter.get_name()
|
||||||
|
<< " can not be changed in runtime.");
|
||||||
|
} else {
|
||||||
|
for (const auto &func : param_functions_[parameter.get_name()]) {
|
||||||
|
func(parameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rcl_interfaces::msg::SetParametersResult result;
|
||||||
|
result.successful = true;
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Parameters::~Parameters() {
|
||||||
|
for (auto const ¶m : param_functions_) {
|
||||||
|
node_->undeclare_parameter(param.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rclcpp::ParameterValue Parameters::setParam(
|
||||||
|
const std::string ¶m_name, rclcpp::ParameterValue initial_value,
|
||||||
|
const std::function<void(const rclcpp::Parameter &)> &func,
|
||||||
|
const rcl_interfaces::msg::ParameterDescriptor &descriptor) {
|
||||||
|
rclcpp::ParameterValue result_value(initial_value);
|
||||||
|
try {
|
||||||
|
if (!node_->has_parameter(param_name)) {
|
||||||
|
result_value = node_->declare_parameter(param_name, initial_value, descriptor);
|
||||||
|
} else {
|
||||||
|
result_value = node_->get_parameter(param_name).get_parameter_value();
|
||||||
|
}
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
std::stringstream range;
|
||||||
|
for (auto val : descriptor.floating_point_range) {
|
||||||
|
range << val.from_value << ", " << val.to_value;
|
||||||
|
}
|
||||||
|
for (auto val : descriptor.integer_range) {
|
||||||
|
range << val.from_value << ", " << val.to_value;
|
||||||
|
}
|
||||||
|
RCLCPP_WARN_STREAM(
|
||||||
|
logger_,
|
||||||
|
"Could not set param: " << param_name << " with "
|
||||||
|
<< rclcpp::Parameter(param_name, initial_value).value_to_string()
|
||||||
|
<< "Range: [" << range.str() << "]"
|
||||||
|
<< ": " << e.what());
|
||||||
|
return initial_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (func) {
|
||||||
|
param_functions_[param_name].push_back(func);
|
||||||
|
} else {
|
||||||
|
param_functions_[param_name] = std::vector<std::function<void(const rclcpp::Parameter &)>>();
|
||||||
|
}
|
||||||
|
if (result_value != initial_value && func) {
|
||||||
|
func(rclcpp::Parameter(param_name, result_value));
|
||||||
|
}
|
||||||
|
return result_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void Parameters::setParamT(std::string param_name, rclcpp::ParameterValue initial_value, T ¶m,
|
||||||
|
std::function<void(const rclcpp::Parameter &)> func,
|
||||||
|
rcl_interfaces::msg::ParameterDescriptor descriptor) {
|
||||||
|
// NOTICE: callback function is set AFTER the parameter is declared!!!
|
||||||
|
if (!node_->has_parameter(param_name))
|
||||||
|
param = node_->declare_parameter(param_name, initial_value, descriptor).get<T>();
|
||||||
|
else {
|
||||||
|
param = node_->get_parameter(param_name).get_parameter_value().get<T>();
|
||||||
|
}
|
||||||
|
param_functions_[param_name].push_back(
|
||||||
|
[¶m, func](const rclcpp::Parameter ¶meter) { param = parameter.get_value<T>(); });
|
||||||
|
if (func) {
|
||||||
|
param_functions_[param_name].push_back(func);
|
||||||
|
}
|
||||||
|
param_names_[¶m] = param_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void Parameters::setParamValue(T ¶m, const T &value) {
|
||||||
|
param = value;
|
||||||
|
try {
|
||||||
|
std::string param_name = param_names_.at(¶m);
|
||||||
|
|
||||||
|
rcl_interfaces::msg::SetParametersResult results =
|
||||||
|
node_->set_parameter(rclcpp::Parameter(param_name, value));
|
||||||
|
if (!results.successful) {
|
||||||
|
RCLCPP_WARN_STREAM(logger_, "Parameter: " << param_name << " was not set:" << results.reason);
|
||||||
|
}
|
||||||
|
} catch (const std::out_of_range &e) {
|
||||||
|
RCLCPP_WARN_STREAM(logger_, "Parameter was not internally declared.");
|
||||||
|
} catch (const rclcpp::exceptions::ParameterNotDeclaredException &e) {
|
||||||
|
std::string param_name = param_names_.at(¶m);
|
||||||
|
RCLCPP_WARN_STREAM(logger_, "Parameter: " << param_name << " was not declared:" << e.what());
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
RCLCPP_ERROR_STREAM(logger_, e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Parameters::removeParam(const std::string ¶m_name) {
|
||||||
|
node_->undeclare_parameter(param_name);
|
||||||
|
param_functions_.erase(param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
template void Parameters::setParamT<bool>(std::string param_name,
|
||||||
|
rclcpp::ParameterValue initial_value, bool ¶m,
|
||||||
|
std::function<void(const rclcpp::Parameter &)> func,
|
||||||
|
rcl_interfaces::msg::ParameterDescriptor descriptor);
|
||||||
|
|
||||||
|
template void Parameters::setParamT<int>(std::string param_name,
|
||||||
|
rclcpp::ParameterValue initial_value, int ¶m,
|
||||||
|
std::function<void(const rclcpp::Parameter &)> func,
|
||||||
|
rcl_interfaces::msg::ParameterDescriptor descriptor);
|
||||||
|
|
||||||
|
template void Parameters::setParamT<double>(std::string param_name,
|
||||||
|
rclcpp::ParameterValue initial_value, double ¶m,
|
||||||
|
std::function<void(const rclcpp::Parameter &)> func,
|
||||||
|
rcl_interfaces::msg::ParameterDescriptor descriptor);
|
||||||
|
|
||||||
|
template void Parameters::setParamValue<int>(int ¶m, const int &value);
|
||||||
|
|
||||||
|
template void Parameters::setParamValue<bool>(bool ¶m, const bool &value);
|
||||||
|
|
||||||
|
template void Parameters::setParamValue<double>(double ¶m, const double &value);
|
||||||
|
} // namespace orbbec_camera
|
||||||
@@ -1,3 +1,15 @@
|
|||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2013-2022 Orbbec 3D Technology, Inc */
|
||||||
|
/* */
|
||||||
|
/* PROPRIETARY RIGHTS of Orbbec 3D Technology are involved in the */
|
||||||
|
/* subject matter of this material. All manufacturing, reproduction, use, */
|
||||||
|
/* and sales rights pertaining to this subject matter are governed by the */
|
||||||
|
/* license agreement. The recipient of this software implicitly accepts */
|
||||||
|
/* the terms of the license. */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
#include "orbbec_camera/ob_camera_node.h"
|
#include "orbbec_camera/ob_camera_node.h"
|
||||||
#include <rclcpp/rclcpp.hpp>
|
#include <rclcpp/rclcpp.hpp>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -7,8 +19,9 @@
|
|||||||
namespace orbbec_camera {
|
namespace orbbec_camera {
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
OBCameraNode::OBCameraNode(rclcpp::Node* node, std::shared_ptr<ob::Device> device)
|
OBCameraNode::OBCameraNode(rclcpp::Node* node, std::shared_ptr<ob::Device> device,
|
||||||
: node_(node), device_(device), logger_(node->get_logger()) {
|
std::shared_ptr<Parameters> parameters)
|
||||||
|
: node_(node), device_(device), parameters_(parameters), logger_(node->get_logger()) {
|
||||||
static_tf_broadcaster_ = std::make_shared<tf2_ros::StaticTransformBroadcaster>(node);
|
static_tf_broadcaster_ = std::make_shared<tf2_ros::StaticTransformBroadcaster>(node);
|
||||||
dynamic_tf_broadcaster_ = std::make_shared<tf2_ros::TransformBroadcaster>(node);
|
dynamic_tf_broadcaster_ = std::make_shared<tf2_ros::TransformBroadcaster>(node);
|
||||||
// FIXME:
|
// FIXME:
|
||||||
@@ -38,6 +51,21 @@ OBCameraNode::OBCameraNode(rclcpp::Node* node, std::shared_ptr<ob::Device> devic
|
|||||||
startPipeline();
|
startPipeline();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void OBCameraNode::setNgetNodeParameter(
|
||||||
|
T& param, const std::string& param_name, const T& default_value,
|
||||||
|
const rcl_interfaces::msg::ParameterDescriptor& parameter_descriptor) {
|
||||||
|
try {
|
||||||
|
param = parameters_
|
||||||
|
->setParam(param_name, rclcpp::ParameterValue(default_value),
|
||||||
|
std::function<void(const rclcpp::Parameter&)>(), parameter_descriptor)
|
||||||
|
.get<T>();
|
||||||
|
} catch (const rclcpp::ParameterTypeException& ex) {
|
||||||
|
RCLCPP_ERROR_STREAM(logger_, "Failed to set parameter: " << param_name << ". " << ex.what());
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
OBCameraNode::~OBCameraNode() { clean(); }
|
OBCameraNode::~OBCameraNode() { clean(); }
|
||||||
|
|
||||||
void OBCameraNode::clean() {
|
void OBCameraNode::clean() {
|
||||||
@@ -136,26 +164,25 @@ void OBCameraNode::startPipeline() {
|
|||||||
void OBCameraNode::getParameters() {
|
void OBCameraNode::getParameters() {
|
||||||
for (auto stream_index : IMAGE_STREAMS) {
|
for (auto stream_index : IMAGE_STREAMS) {
|
||||||
std::string param_name = stream_name_[stream_index.first] + "_width";
|
std::string param_name = stream_name_[stream_index.first] + "_width";
|
||||||
width_[stream_index] = node_->declare_parameter<int>(param_name, IMAGE_WIDTH);
|
setNgetNodeParameter(width_[stream_index], param_name, IMAGE_WIDTH);
|
||||||
param_name = stream_name_[stream_index.first] + "_height";
|
param_name = stream_name_[stream_index.first] + "_height";
|
||||||
height_[stream_index] = node_->declare_parameter<int>(param_name, IMAGE_HEIGHT);
|
setNgetNodeParameter(height_[stream_index], param_name, IMAGE_HEIGHT);
|
||||||
param_name = stream_name_[stream_index.first] + "_fps";
|
param_name = stream_name_[stream_index.first] + "_fps";
|
||||||
fps_[stream_index] = node_->declare_parameter<int>(param_name, IMAGE_FPS);
|
setNgetNodeParameter(fps_[stream_index], param_name, IMAGE_FPS);
|
||||||
param_name = "enable_" + stream_name_[stream_index.first];
|
param_name = "enable_" + stream_name_[stream_index.first];
|
||||||
enable_[stream_index] = node_->declare_parameter<bool>(param_name, true);
|
setNgetNodeParameter(enable_[stream_index], param_name, true);
|
||||||
param_name = stream_name_[stream_index.first] + "_frame_id";
|
param_name = stream_name_[stream_index.first] + "_frame_id";
|
||||||
std::string default_frame_id = "camera_" + stream_name_[stream_index.first] + "_frame";
|
std::string default_frame_id = "camera_" + stream_name_[stream_index.first] + "_frame";
|
||||||
frame_id_[stream_index] = node_->declare_parameter<std::string>(param_name, default_frame_id);
|
setNgetNodeParameter(frame_id_[stream_index], param_name, default_frame_id);
|
||||||
std::string default_optical_frame_id =
|
std::string default_optical_frame_id =
|
||||||
"camera_" + stream_name_[stream_index.first] + "_optical_frame";
|
"camera_" + stream_name_[stream_index.first] + "_optical_frame";
|
||||||
param_name = stream_name_[stream_index.first] + "_optical_frame_id";
|
param_name = stream_name_[stream_index.first] + "_optical_frame_id";
|
||||||
optical_frame_id_[stream_index] =
|
setNgetNodeParameter(optical_frame_id_[stream_index], param_name, default_optical_frame_id);
|
||||||
node_->declare_parameter<std::string>(param_name, default_optical_frame_id);
|
|
||||||
depth_aligned_frame_id_[stream_index] = stream_name_[OB_STREAM_COLOR] + "_optical_frame";
|
depth_aligned_frame_id_[stream_index] = stream_name_[OB_STREAM_COLOR] + "_optical_frame";
|
||||||
}
|
}
|
||||||
publish_tf_ = node_->declare_parameter<bool>("publish_tf", true);
|
setNgetNodeParameter(publish_tf_, "publish_tf", true);
|
||||||
align_depth_ = node_->declare_parameter<bool>("align_depth", true);
|
setNgetNodeParameter(align_depth_, "align_depth", true);
|
||||||
tf_publish_rate_ = node_->declare_parameter<double>("tf_publish_rate", 10.0);
|
setNgetNodeParameter(tf_publish_rate_, "tf_publish_rate", 10.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBCameraNode::setupTopics() {
|
void OBCameraNode::setupTopics() {
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2013-2022 Orbbec 3D Technology, Inc */
|
||||||
|
/* */
|
||||||
|
/* PROPRIETARY RIGHTS of Orbbec 3D Technology are involved in the */
|
||||||
|
/* subject matter of this material. All manufacturing, reproduction, use, */
|
||||||
|
/* and sales rights pertaining to this subject matter are governed by the */
|
||||||
|
/* license agreement. The recipient of this software implicitly accepts */
|
||||||
|
/* the terms of the license. */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
#include "orbbec_camera/ob_camera_node_factory.h"
|
#include "orbbec_camera/ob_camera_node_factory.h"
|
||||||
namespace orbbec_camera {
|
namespace orbbec_camera {
|
||||||
OBCameraNodeFactory::OBCameraNodeFactory(const rclcpp::NodeOptions &node_options)
|
OBCameraNodeFactory::OBCameraNodeFactory(const rclcpp::NodeOptions &node_options)
|
||||||
@@ -23,6 +35,7 @@ OBCameraNodeFactory::~OBCameraNodeFactory() {
|
|||||||
void OBCameraNodeFactory::init() {
|
void OBCameraNodeFactory::init() {
|
||||||
ctx_->setLoggerSeverity(OB_LOG_SEVERITY_NONE);
|
ctx_->setLoggerSeverity(OB_LOG_SEVERITY_NONE);
|
||||||
is_alive_.store(true);
|
is_alive_.store(true);
|
||||||
|
parameters_ = std::make_shared<Parameters>(this);
|
||||||
serial_number_ = declare_parameter<std::string>("serial_number", "");
|
serial_number_ = declare_parameter<std::string>("serial_number", "");
|
||||||
query_thread_ = std::thread([=]() {
|
query_thread_ = std::thread([=]() {
|
||||||
std::chrono::milliseconds timespan(static_cast<int>(reconnect_timeout_ * 1e3));
|
std::chrono::milliseconds timespan(static_cast<int>(reconnect_timeout_ * 1e3));
|
||||||
@@ -85,20 +98,20 @@ void OBCameraNodeFactory::deviceDisconnectCallback(
|
|||||||
CHECK_NOTNULL(device_list);
|
CHECK_NOTNULL(device_list);
|
||||||
ob_camera_node_.reset(nullptr);
|
ob_camera_node_.reset(nullptr);
|
||||||
device_.reset();
|
device_.reset();
|
||||||
// try {
|
// try {
|
||||||
// for (size_t i = 0; i < device_list->deviceCount(); i++) {
|
// for (size_t i = 0; i < device_list->deviceCount(); i++) {
|
||||||
// auto dev = device_list->getDevice(i);
|
// auto dev = device_list->getDevice(i);
|
||||||
// std::string sn1 = dev->getDeviceInfo()->serialNumber();
|
// std::string sn1 = dev->getDeviceInfo()->serialNumber();
|
||||||
// std::string sn2 = device_->getDeviceInfo()->serialNumber();
|
// std::string sn2 = device_->getDeviceInfo()->serialNumber();
|
||||||
// if (sn1 == sn2) {
|
// if (sn1 == sn2) {
|
||||||
// RCLCPP_ERROR(logger_, "The device with SN %s was disconnected!", sn1.c_str());
|
// RCLCPP_ERROR(logger_, "The device with SN %s was disconnected!", sn1.c_str());
|
||||||
// ob_camera_node_.reset(nullptr);
|
// ob_camera_node_.reset(nullptr);
|
||||||
// device_.reset();
|
// device_.reset();
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// } catch (const ob::Error &e) {
|
// } catch (const ob::Error &e) {
|
||||||
// RCLCPP_ERROR_STREAM(logger_, e.getMessage());
|
// RCLCPP_ERROR_STREAM(logger_, e.getMessage());
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBCameraNodeFactory::printDeviceInfo(const std::shared_ptr<ob::DeviceInfo> &device_info) {
|
void OBCameraNodeFactory::printDeviceInfo(const std::shared_ptr<ob::DeviceInfo> &device_info) {
|
||||||
@@ -143,6 +156,6 @@ void OBCameraNodeFactory::startDevice() {
|
|||||||
ob_camera_node_.reset();
|
ob_camera_node_.reset();
|
||||||
}
|
}
|
||||||
CHECK_NOTNULL(device_);
|
CHECK_NOTNULL(device_);
|
||||||
ob_camera_node_ = std::make_unique<OBCameraNode>(this, device_);
|
ob_camera_node_ = std::make_unique<OBCameraNode>(this, device_, parameters_);
|
||||||
}
|
}
|
||||||
} // namespace orbbec_camera
|
} // namespace orbbec_camera
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2013-2022 Orbbec 3D Technology, Inc */
|
||||||
|
/* */
|
||||||
|
/* PROPRIETARY RIGHTS of Orbbec 3D Technology are involved in the */
|
||||||
|
/* subject matter of this material. All manufacturing, reproduction, use, */
|
||||||
|
/* and sales rights pertaining to this subject matter are governed by the */
|
||||||
|
/* license agreement. The recipient of this software implicitly accepts */
|
||||||
|
/* the terms of the license. */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
#include "orbbec_camera/ros_param_backend.h"
|
||||||
|
namespace orbbec_camera {
|
||||||
|
ParametersBackend::ParametersBackend(rclcpp::Node *node)
|
||||||
|
: node_(node), logger_(node_->get_logger()) {}
|
||||||
|
|
||||||
|
ParametersBackend::~ParametersBackend() {
|
||||||
|
if (ros_callback_) {
|
||||||
|
node_->remove_on_set_parameters_callback(
|
||||||
|
(rclcpp::node_interfaces::OnSetParametersCallbackHandle *)(ros_callback_.get()));
|
||||||
|
ros_callback_.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParametersBackend::addOnSetParametersCallback(
|
||||||
|
rclcpp::node_interfaces::NodeParametersInterface::OnParametersSetCallbackType callback) {
|
||||||
|
ros_callback_ = node_->add_on_set_parameters_callback(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace orbbec_camera
|
||||||
@@ -1,3 +1,15 @@
|
|||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2013-2022 Orbbec 3D Technology, Inc */
|
||||||
|
/* */
|
||||||
|
/* PROPRIETARY RIGHTS of Orbbec 3D Technology are involved in the */
|
||||||
|
/* subject matter of this material. All manufacturing, reproduction, use, */
|
||||||
|
/* and sales rights pertaining to this subject matter are governed by the */
|
||||||
|
/* license agreement. The recipient of this software implicitly accepts */
|
||||||
|
/* the terms of the license. */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
#include "orbbec_camera/ob_camera_node.h"
|
#include "orbbec_camera/ob_camera_node.h"
|
||||||
#include <rclcpp/rclcpp.hpp>
|
#include <rclcpp/rclcpp.hpp>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -1,3 +1,15 @@
|
|||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2013-2022 Orbbec 3D Technology, Inc */
|
||||||
|
/* */
|
||||||
|
/* PROPRIETARY RIGHTS of Orbbec 3D Technology are involved in the */
|
||||||
|
/* subject matter of this material. All manufacturing, reproduction, use, */
|
||||||
|
/* and sales rights pertaining to this subject matter are governed by the */
|
||||||
|
/* license agreement. The recipient of this software implicitly accepts */
|
||||||
|
/* the terms of the license. */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
#include "orbbec_camera/utils.h"
|
#include "orbbec_camera/utils.h"
|
||||||
namespace orbbec_camera {
|
namespace orbbec_camera {
|
||||||
sensor_msgs::msg::CameraInfo convertToCameraInfo(OBCameraIntrinsic intrinsic,
|
sensor_msgs::msg::CameraInfo convertToCameraInfo(OBCameraIntrinsic intrinsic,
|
||||||
|
|||||||
Reference in New Issue
Block a user