ROS 桥接
简介
可用的转换器
| 转换器 | 描述 |
|---|---|
| 视差转换器 | 转换立体视差消息 |
| 图像转换器 | 用于将各种类型的图像消息与 DAI/OpenCV 格式相互转换 |
| 图像检测转换器 | 转换 2D 检测结果 |
| IMU 转换器 | 转换 IMU 数据,可选择插值 IMU 读数 |
| 空间检测转换器 | 转换 3D 空间检 测结果 |
| 跟踪特征转换器 | 转换跟踪特征 |
| 跟踪检测转换器 | 转换 DAI 轨迹片段 |
| 变换发布器 | 用于转换 DAI 校准数据并以 ROS 变换数据形式发布 |
用法
depthai_examples 包,了解如何设置管道并使用 BridgePublisher 类和 ImageConverters 以 ROS 格式发布数据。 以下是一个简单的 RGB 发布示例:C++
1#include <cstdio>
2
3#include "depthai/device/Device.hpp"
4#include "depthai/pipeline/Pipeline.hpp"
5#include "depthai/pipeline/node/Camera.hpp"
6#include "depthai_bridge/BridgePublisher.hpp"
7#include "depthai_bridge/ImageConverter.hpp"
8#include "depthai_bridge/TFPublisher.hpp"
9#include "depthai_bridge/depthaiUtility.hpp"
10#include "rclcpp/node.hpp"
11
12int main(int argc, char** argv) {
13 int width = 1280;
14 int height = 720;
15 std::string tfPrefix = "oak";
16 rclcpp::init(argc, argv);
17 auto node = rclcpp::Node::make_shared("rgb_publisher");
18
19 auto device = std::make_shared<dai::Device>();
20 dai::Pipeline pipeline(device);
21
22 // Define sources and outputs 定义源和输出
23 auto rgbCamera = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_A);
24
25 // Create output queue 创建输出队列
26 auto rgbOutputQueue = rgbCamera->requestOutput({width, height})->createOutputQueue(8, false);
27
28 pipeline.start();
29
30 // Create a bridge publisher for RGB images 为RGB图像创建桥接发布器
31 auto rgbConverter = std::make_shared<depthai_bridge::ImageConverter>(
32 depthai_bridge::getOpticalFrameName(tfPrefix, depthai_bridge::getSocketName(dai::CameraBoardSocket::CAM_A, device->getDeviceName())), false);
33
34 auto calibrationHandler = device->readCalibration();
35 auto tfPub =
36 std::make_unique<depthai_bridge::TFPublisher>(node, calibrationHandler, device->getConnectedCameraFeatures(), tfPrefix, device->getDeviceName());
37 auto rgbCameraInfo = rgbConverter->calibrationToCameraInfo(calibrationHandler, dai::CameraBoardSocket::CAM_A, width, height);
38
39 auto rgbPub = std::make_unique<depthai_bridge::BridgePublisher<sensor_msgs::msg::Image, dai::ImgFrame>>(
40 rgbOutputQueue,
41 node,
42 "rgb/image",
43 [rgbConverter](std::shared_ptr<dai::ImgFrame> msg, std::deque<sensor_msgs::msg::Image>& rosMsgs) { rgbConverter->toRosMsg(msg, rosMsgs); },
44 30,
45 rgbCameraInfo,
46 "rgb");
47
48 rgbPub->addPublisherCallback();
49
50 while(rclcpp::ok() && pipeline.isRunning()) {
51 rclcpp::spin(node);
52 }
53
54 return 0;
55}