mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-04 12:07:46 +08:00
add get verion api
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
#include "orbbec_camera_msgs/msg/extrinsics.hpp"
|
#include "orbbec_camera_msgs/msg/extrinsics.hpp"
|
||||||
#include "orbbec_camera_msgs/msg/metadata.hpp"
|
#include "orbbec_camera_msgs/msg/metadata.hpp"
|
||||||
#include "orbbec_camera_msgs/srv/get_int32.hpp"
|
#include "orbbec_camera_msgs/srv/get_int32.hpp"
|
||||||
|
#include "orbbec_camera_msgs/srv/get_string.hpp"
|
||||||
#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"
|
||||||
@@ -75,6 +76,7 @@ using GetDeviceInfo = orbbec_camera_msgs::srv::GetDeviceInfo;
|
|||||||
using Extrinsics = orbbec_camera_msgs::msg::Extrinsics;
|
using Extrinsics = orbbec_camera_msgs::msg::Extrinsics;
|
||||||
using SetInt32 = orbbec_camera_msgs::srv::SetInt32;
|
using SetInt32 = orbbec_camera_msgs::srv::SetInt32;
|
||||||
using GetInt32 = orbbec_camera_msgs::srv::GetInt32;
|
using GetInt32 = orbbec_camera_msgs::srv::GetInt32;
|
||||||
|
using GetString = orbbec_camera_msgs::srv::GetString;
|
||||||
|
|
||||||
typedef std::pair<ob_stream_type, int> stream_index_pair;
|
typedef std::pair<ob_stream_type, int> stream_index_pair;
|
||||||
|
|
||||||
@@ -190,6 +192,10 @@ class OBCameraNode {
|
|||||||
const std::shared_ptr<GetDeviceInfo::Request>& request,
|
const std::shared_ptr<GetDeviceInfo::Request>& request,
|
||||||
std::shared_ptr<GetDeviceInfo::Response>& response);
|
std::shared_ptr<GetDeviceInfo::Response>& response);
|
||||||
|
|
||||||
|
void getApiVersion(const std::shared_ptr<rmw_request_id_t>& request_header,
|
||||||
|
const std::shared_ptr<GetString::Request>& request,
|
||||||
|
std::shared_ptr<GetString::Response>& response);
|
||||||
|
|
||||||
void publishPointCloud(std::shared_ptr<ob::FrameSet> frame_set);
|
void publishPointCloud(std::shared_ptr<ob::FrameSet> frame_set);
|
||||||
|
|
||||||
void publishDepthPointCloud(std::shared_ptr<ob::FrameSet> frame_set);
|
void publishDepthPointCloud(std::shared_ptr<ob::FrameSet> frame_set);
|
||||||
@@ -253,6 +259,7 @@ class OBCameraNode {
|
|||||||
std::map<stream_index_pair, rclcpp::Service<SetInt32>::SharedPtr> set_gain_srv_;
|
std::map<stream_index_pair, rclcpp::Service<SetInt32>::SharedPtr> set_gain_srv_;
|
||||||
rclcpp::Service<GetInt32>::SharedPtr get_white_balance_srv_; // only rgb
|
rclcpp::Service<GetInt32>::SharedPtr get_white_balance_srv_; // only rgb
|
||||||
rclcpp::Service<SetInt32>::SharedPtr set_white_balance_srv_;
|
rclcpp::Service<SetInt32>::SharedPtr set_white_balance_srv_;
|
||||||
|
rclcpp::Service<GetString>::SharedPtr get_api_version_srv_;
|
||||||
std::map<stream_index_pair, rclcpp::Service<std_srvs::srv::SetBool>::SharedPtr>
|
std::map<stream_index_pair, rclcpp::Service<std_srvs::srv::SetBool>::SharedPtr>
|
||||||
set_auto_exposure_srv_; // only rgb color
|
set_auto_exposure_srv_; // only rgb color
|
||||||
|
|
||||||
|
|||||||
@@ -40,4 +40,6 @@ orbbec_camera_msgs::msg::Extrinsics obExtrinsicsToMsg(const OBD2CTransform& extr
|
|||||||
|
|
||||||
rclcpp::Time frameTimeStampToROSTime(uint64_t ms);
|
rclcpp::Time frameTimeStampToROSTime(uint64_t ms);
|
||||||
|
|
||||||
|
std::string getObSDKVersion();
|
||||||
|
|
||||||
} // namespace orbbec_camera
|
} // namespace orbbec_camera
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "orbbec_camera/ob_camera_node.h"
|
#include "orbbec_camera/ob_camera_node.h"
|
||||||
#include <rclcpp/rclcpp.hpp>
|
#include <rclcpp/rclcpp.hpp>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "orbbec_camera/utils.h"
|
#include "orbbec_camera/utils.h"
|
||||||
@@ -111,6 +112,12 @@ void OBCameraNode::setupCameraCtrlServices() {
|
|||||||
std::shared_ptr<GetDeviceInfo::Response> response) {
|
std::shared_ptr<GetDeviceInfo::Response> response) {
|
||||||
getDeviceInfoCallback(request_header, request, response);
|
getDeviceInfoCallback(request_header, request, response);
|
||||||
});
|
});
|
||||||
|
get_api_version_srv_ = node_->create_service<GetString>(
|
||||||
|
"get_api_version", [this](const std::shared_ptr<rmw_request_id_t> request_header,
|
||||||
|
const std::shared_ptr<GetString::Request> request,
|
||||||
|
std::shared_ptr<GetString::Response> response) {
|
||||||
|
getApiVersion(request_header, request, response);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBCameraNode::setExposureCallback(const std::shared_ptr<SetInt32::Request>& request,
|
void OBCameraNode::setExposureCallback(const std::shared_ptr<SetInt32::Request>& request,
|
||||||
@@ -405,4 +412,27 @@ void OBCameraNode::getDeviceInfoCallback(const std::shared_ptr<rmw_request_id_t>
|
|||||||
response->message = "unknown error";
|
response->message = "unknown error";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void OBCameraNode::getApiVersion(const std::shared_ptr<rmw_request_id_t>& request_header,
|
||||||
|
const std::shared_ptr<GetString::Request>& request,
|
||||||
|
std::shared_ptr<GetString::Response>& response) {
|
||||||
|
try {
|
||||||
|
auto device_info = device_->getDeviceInfo();
|
||||||
|
nlohmann::json data;
|
||||||
|
data["firmware_version"] = device_info->firmwareVersion();
|
||||||
|
data["supported_min_sdk_version"] = device_info->supportedMinSdkVersion();
|
||||||
|
data["ros_sdk_version"] = OB_ROS_VERSION_STR;
|
||||||
|
data["ob_sdk_version"] = getObSDKVersion();
|
||||||
|
response->data = data.dump(2);
|
||||||
|
response->success = true;
|
||||||
|
} catch (const ob::Error& e) {
|
||||||
|
response->success = false;
|
||||||
|
response->message = e.getMessage();
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
response->success = false;
|
||||||
|
response->message = e.what();
|
||||||
|
} catch (...) {
|
||||||
|
response->success = false;
|
||||||
|
response->message = "unknown error";
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace orbbec_camera
|
} // namespace orbbec_camera
|
||||||
|
|||||||
@@ -139,8 +139,16 @@ orbbec_camera_msgs::msg::Extrinsics obExtrinsicsToMsg(const OBD2CTransform &extr
|
|||||||
rclcpp::Time frameTimeStampToROSTime(uint64_t ms) {
|
rclcpp::Time frameTimeStampToROSTime(uint64_t ms) {
|
||||||
auto total = static_cast<uint64_t>(ms * 1e6);
|
auto total = static_cast<uint64_t>(ms * 1e6);
|
||||||
uint64_t sec = total / 1000000000;
|
uint64_t sec = total / 1000000000;
|
||||||
uint64_t nano_sec = total % 1000000000;
|
uint64_t nano_sec = total % 1000000000;
|
||||||
rclcpp::Time stamp(sec, nano_sec);
|
rclcpp::Time stamp(sec, nano_sec);
|
||||||
return stamp;
|
return stamp;
|
||||||
}
|
}
|
||||||
|
std::string getObSDKVersion() {
|
||||||
|
int major = ob::Version::getMajor();
|
||||||
|
int minor = ob::Version::getMinor();
|
||||||
|
int patch = ob::Version::getPatch();
|
||||||
|
std::string version = std::to_string(major) + std::to_string(minor) + std::to_string(patch);
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace orbbec_camera
|
} // namespace orbbec_camera
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ rosidl_generate_interfaces(${PROJECT_NAME}
|
|||||||
"srv/GetDeviceInfo.srv"
|
"srv/GetDeviceInfo.srv"
|
||||||
"srv/GetCameraInfo.srv"
|
"srv/GetCameraInfo.srv"
|
||||||
"srv/GetInt32.srv"
|
"srv/GetInt32.srv"
|
||||||
|
"srv/GetString.srv"
|
||||||
"srv/SetInt32.srv"
|
"srv/SetInt32.srv"
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
sensor_msgs
|
sensor_msgs
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
---
|
---
|
||||||
int32 data
|
int32 data
|
||||||
string message
|
bool success
|
||||||
|
string message
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
string data
|
||||||
|
bool success
|
||||||
|
string message
|
||||||
Reference in New Issue
Block a user