CARLA
 
载入中...
搜索中...
未找到
CarlaDepthCameraPublisher.cpp
浏览该文件的文档.
1#define _GLIBCXX_USE_CXX11_ABI 0
2
3#include "CarlaDepthCameraPublisher.h"// 引入Carla深度相机发布者类的声明
4
5#include <string>// 引入字符串处理相关的功能
6// 引入CARLA ROS 2桥接器中定义的图像和相机信息类型支持
9// 引入CARLA ROS 2桥接器中定义的监听器类,用于处理CARLA仿真环境中的事件
11// 引入Fast-DDS库中的相关类和类型定义
12#include <fastdds/dds/domain/DomainParticipant.hpp>// 引入域参与者类
13#include <fastdds/dds/publisher/Publisher.hpp>// 引入发布者类
14#include <fastdds/dds/topic/Topic.hpp>// 引入主题类
15#include <fastdds/dds/publisher/DataWriter.hpp>// 引入数据写入器类
16#include <fastdds/dds/topic/TypeSupport.hpp>// 引入类型支持类
17// 引入Fast-DDS库中的QoS配置相关的类和类型定义
18#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>// 引入域参与者QoS配置类
19#include <fastdds/dds/domain/DomainParticipantFactory.hpp>// 引入域参与者工厂类
20#include <fastdds/dds/publisher/qos/PublisherQos.hpp>// 引入发布者QoS配置类
21#include <fastdds/dds/topic/qos/TopicQos.hpp>// 引入主题QoS配置类
22// 引入Fast-RTPS库中的参与者属性和QoS策略相关的类和类型定义
23#include <fastrtps/attributes/ParticipantAttributes.h>
24#include <fastrtps/qos/QosPolicies.h>
25#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>// 引入数据写入器QoS配置类
26#include <fastdds/dds/publisher/DataWriterListener.hpp>// 引入数据写入器监听器类
27
28/**
29 * @namespace carla::ros2
30 * @brief 命名空间,用于封装CARLA与ROS 2之间的集成代码。
31 */
32
33 /**
34 * @brief 命名空间别名定义,简化eprosima::fastdds::dds的引用。
35 */
36namespace carla {
37namespace ros2 {
38
39 namespace efd = eprosima::fastdds::dds;
40 /**
41 * @brief 类型别名定义,简化eprosima::fastrtps::types::ReturnCode_t的引用。
42 */
43 using erc = eprosima::fastrtps::types::ReturnCode_t;
44 /**
45 * @struct CarlaDepthCameraPublisherImpl
46 * @brief CARLA深度相机发布者实现结构体。
47 *
48 * 该结构体包含了与DDS(Data Distribution Service)相关的成员变量,用于发布深度图像数据。
49 */
51 /**
52 * @brief DDS域参与者指针。
53 */
54 efd::DomainParticipant* _participant { nullptr };
55 /**
56 * @brief DDS发布者指针。
57 */
58 efd::Publisher* _publisher { nullptr };
59 /**
60 * @brief DDS主题指针。
61 */
62 efd::Topic* _topic { nullptr };
63 /**
64 * @brief DDS数据写入器指针。
65 */
66 efd::DataWriter* _datawriter { nullptr };
67 /**
68 * @brief DDS类型支持,用于深度图像消息。
69 */
70 efd::TypeSupport _type { new sensor_msgs::msg::ImagePubSubType() };
71 /**
72 * @brief CARLA监听器实例。
73 */
74 CarlaListener _listener {};
75 /**
76 * @brief 深度图像消息实例。
77 */
79 };
80 /**
81 * @struct CarlaCameraInfoPublisherImpl
82 * @brief CARLA相机信息发布者实现结构体。
83 *
84 * 该结构体包含了与DDS相关的成员变量,用于发布相机信息数据。
85 */
87 /**
88 * @brief DDS域参与者指针。
89 */
90 efd::DomainParticipant* _participant { nullptr };
91 /**
92 * @brief DDS发布者指针。
93 */
94 efd::Publisher* _publisher { nullptr };
95 /**
96 * @brief DDS主题指针。
97 */
98 efd::Topic* _topic { nullptr };
99 /**
100 * @brief DDS数据写入器指针。
101 */
102 efd::DataWriter* _datawriter { nullptr };
103 /**
104 * @brief DDS类型支持,用于相机信息消息。
105 */
107 /**
108 * @brief CARLA监听器实例。
109 */
110 CarlaListener _listener {};
111 /**
112 * @brief 初始化标志。
113 */
114 bool _init {false};
115 /**
116 * @brief 相机信息消息实例。
117 */
119 };
120 /**
121 * @brief 检查深度相机发布者是否已初始化。
122 *
123 * @return true 如果已初始化,否则返回false。
124 */
126 return _impl_info->_init;
127 }
128 /**
129 * @brief 初始化深度相机信息数据。
130 *
131 * @param x_offset X轴偏移量。
132 * @param y_offset Y轴偏移量。
133 * @param height 图像高度。
134 * @param width 图像宽度。
135 * @param fov 视野角度。
136 * @param do_rectify 是否进行校正。
137 */
138 void CarlaDepthCameraPublisher::InitInfoData(uint32_t x_offset, uint32_t y_offset, uint32_t height, uint32_t width, float fov, bool do_rectify) {
139 _impl_info->_info = std::move(sensor_msgs::msg::CameraInfo(height, width, fov));
140 SetInfoRegionOfInterest(x_offset, y_offset, height, width, do_rectify);
141 _impl_info->_init = true;
142 }
143 /**
144 * @brief 初始化深度相机发布者。
145 *
146 * @return true 如果初始化成功,否则返回false。
147 */
149 return InitImage() && InitInfo();
150 }
151 /**
152 * @brief 初始化深度图像数据。
153 *
154 * @return true 如果初始化成功,否则返回false。
155 */
157 if (_impl->_type == nullptr) {
158 /**
159 * @brief 输出错误信息,表示类型支持无效。
160 */
161 std::cerr << "Invalid TypeSupport" << std::endl;
162 return false;
163 }
164 // 设置域参与者的QoS策略,并为其命名
165 efd::DomainParticipantQos pqos = efd::PARTICIPANT_QOS_DEFAULT;
166 pqos.name(_name);
167 auto factory = efd::DomainParticipantFactory::get_instance();
168 _impl->_participant = factory->create_participant(0, pqos);
169 if (_impl->_participant == nullptr) {
170 std::cerr << "Failed to create DomainParticipant" << std::endl;
171 return false;
172 }
173 // 在域参与者中注册类型
174 _impl->_type.register_type(_impl->_participant);
175 // 设置发布者的QoS策略,并创建发布者
176 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
177 _impl->_publisher = _impl->_participant->create_publisher(pubqos, nullptr);
178 if (_impl->_publisher == nullptr) {
179 std::cerr << "Failed to create Publisher" << std::endl;
180 return false;
181 }
182 // 设置主题的QoS策略,并创建主题
183 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
184 const std::string publisher_type {"/image"};
185 const std::string base { "rt/carla/" };
186 std::string topic_name = base;
187 if (!_parent.empty())
188 topic_name += _parent + "/";
189 topic_name += _name;
190 topic_name += publisher_type;
191 _impl->_topic = _impl->_participant->create_topic(topic_name, _impl->_type->getName(), tqos);
192 if (_impl->_topic == nullptr) {
193 std::cerr << "Failed to create Topic" << std::endl;
194 return false;
195 }
196 // 设置数据写入器的QoS策略,并创建数据写入器
197 efd::DataWriterQos wqos = efd::DATAWRITER_QOS_DEFAULT;
198 wqos.endpoint().history_memory_policy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
199 efd::DataWriterListener* listener = (efd::DataWriterListener*)_impl->_listener._impl.get();
200 _impl->_datawriter = _impl->_publisher->create_datawriter(_impl->_topic, wqos, listener);
201 if (_impl->_datawriter == nullptr) {
202 std::cerr << "Failed to create DataWriter" << std::endl;
203 return false;
204 }
205 // 设置帧ID
207 return true;
208 }
209 /**
210 * @brief 初始化相机信息发布者的DDS相关组件。
211 *
212 * 该函数负责为相机信息创建DDS域参与者、发布者、主题和数据写入器,并处理可能出现的错误。
213 *
214 * @return true 如果所有组件都成功创建,否则返回false。
215 */
217 // 检查类型支持是否有效
218 if (_impl_info->_type == nullptr) {
219 std::cerr << "Invalid TypeSupport" << std::endl;
220 return false;
221 }
222 // 设置域参与者的QoS策略,并为其命名
223 efd::DomainParticipantQos pqos = efd::PARTICIPANT_QOS_DEFAULT;
224 pqos.name(_name);
225 auto factory = efd::DomainParticipantFactory::get_instance();
226 _impl_info->_participant = factory->create_participant(0, pqos);
227 if (_impl_info->_participant == nullptr) {
228 std::cerr << "Failed to create DomainParticipant" << std::endl;
229 return false;
230 }
231 // 在域参与者中注册类型
232 _impl_info->_type.register_type(_impl_info->_participant);
233 // 设置发布者的QoS策略,并创建发布者
234 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
235 _impl_info->_publisher = _impl_info->_participant->create_publisher(pubqos, nullptr);
236 if (_impl_info->_publisher == nullptr) {
237 std::cerr << "Failed to create Publisher" << std::endl;
238 return false;
239 }
240 // 设置主题的QoS策略,并创建主题
241 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
242 const std::string publisher_type {"/camera_info"};
243 const std::string base { "rt/carla/" };
244 std::string topic_name = base;
245 if (!_parent.empty())
246 topic_name += _parent + "/";
247 topic_name += _name;
248 topic_name += publisher_type;
249 _impl_info->_topic = _impl_info->_participant->create_topic(topic_name, _impl_info->_type->getName(), tqos);
250 if (_impl_info->_topic == nullptr) {
251 std::cerr << "Failed to create Topic" << std::endl;
252 return false;
253 }
254 // 设置数据写入器的QoS策略(使用默认值),并创建数据写入器
255 efd::DataWriterQos wqos = efd::DATAWRITER_QOS_DEFAULT;
256 efd::DataWriterListener* listener = (efd::DataWriterListener*)_impl_info->_listener._impl.get();
257 _impl_info->_datawriter = _impl_info->_publisher->create_datawriter(_impl_info->_topic, wqos, listener);
258 if (_impl_info->_datawriter == nullptr) {
259 std::cerr << "Failed to create DataWriter" << std::endl;
260 return false;
261 }
262 // 设置帧ID
264 return true;
265 }
266 /**
267 * @brief 发布深度图像和相机信息。
268 *
269 * 该函数负责调用其他函数来发布深度图像和相机信息。
270 *
271 * @return true 如果深度图像和相机信息都成功发布,否则返回false。
272 */
274 // 发布深度图像和相机信息,并返回结果
275 return PublishImage() && PublishInfo();
276 }
277 /**
278 * @brief 发布深度图像
279 *
280 * 该函数尝试通过FastRTPS发布深度图像数据。
281 * 如果发布成功,返回true;否则根据返回的错误码输出相应的错误信息,并返回false。
282 *
283 * @return bool 如果图像成功发布,则返回true;否则返回false。
284 */
286 /// @var instance_handle
287 /// 用于存储FastRTPS实例句柄的变量。
288 eprosima::fastrtps::rtps::InstanceHandle_t instance_handle;
289 /// @var rcode
290 /// 存储_datawriter->write方法返回的结果码。
291 eprosima::fastrtps::types::ReturnCode_t rcode = _impl->_datawriter->write(&_impl->_image, instance_handle);
292 // 检查返回码,并根据不同的返回码进行相应处理
293 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
294 /// @return 如果返回码为RETCODE_OK,表示发布成功,返回true。
295 return true;
296 }
297 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
298 /// @todo 输出错误信息,并返回false。
299 std::cerr << "RETCODE_ERROR" << std::endl;
300 return false;
301 }
302 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
303 /// @todo 输出错误信息,并返回false。
304 std::cerr << "RETCODE_UNSUPPORTED" << std::endl;
305 return false;
306 }
307 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
308 /// @todo 输出错误信息,并返回false。
309 std::cerr << "RETCODE_BAD_PARAMETER" << std::endl;
310 return false;
311 }
312 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
313 /// @todo 输出错误信息,并返回false。
314 std::cerr << "RETCODE_PRECONDITION_NOT_MET" << std::endl;
315 return false;
316 }
317 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
318 /// @todo 输出错误信息,并返回false。
319 std::cerr << "RETCODE_OUT_OF_RESOURCES" << std::endl;
320 return false;
321 }
322 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
323 /// @todo 输出错误信息,并返回false。
324 std::cerr << "RETCODE_NOT_ENABLED" << std::endl;
325 return false;
326 }
327 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
328 /// @todo 输出错误信息,并返回false。
329 std::cerr << "RETCODE_IMMUTABLE_POLICY" << std::endl;
330 return false;
331 }
332 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
333 /// @todo 输出错误信息,并返回false。
334 std::cerr << "RETCODE_INCONSISTENT_POLICY" << std::endl;
335 return false;
336 }
337 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
338 /// @todo 输出错误信息,并返回false。
339 std::cerr << "RETCODE_ALREADY_DELETED" << std::endl;
340 return false;
341 }
342 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
343 /// @todo 输出错误信息,并返回false。
344 std::cerr << "RETCODE_TIMEOUT" << std::endl;
345 return false;
346 }
347 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
348 /// @todo 输出错误信息,并返回false。
349 std::cerr << "RETCODE_NO_DATA" << std::endl;
350 return false;
351 }
352 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
353 /// @todo 输出错误信息,并返回false。
354 std::cerr << "RETCODE_ILLEGAL_OPERATION" << std::endl;
355 return false;
356 }
357 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
358 /// @todo 输出错误信息,并返回false。
359 std::cerr << "RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
360 return false;
361 }
362 /// @todo 输出未知错误码信息,并返回false。
363 std::cerr << "UNKNOWN" << std::endl;
364 return false;
365 }
366 /**
367 * @brief 发布深度相机信息
368 *
369 * 此函数尝试通过Fast RTPS发布深度相机的信息。
370 * 如果发布成功,则返回true;否则,根据返回码输出相应的错误信息并返回false。
371 *
372 * @return bool 发布成功返回true,否则返回false。
373 */
375 /// @brief Fast RTPS实例句柄
376 eprosima::fastrtps::rtps::InstanceHandle_t instance_handle;
377 /// @brief 调用数据写入函数并获取返回码
378 eprosima::fastrtps::types::ReturnCode_t rcode = _impl_info->_datawriter->write(&_impl_info->_info, instance_handle);
379 /// @brief 检查返回码,并处理各种可能的错误情况
380 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
381 /// @brief 发布成功
382 return true;
383 }
384 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
385 /// @brief 发生一般错误
386 std::cerr << "RETCODE_ERROR" << std::endl;
387 return false;
388 }
389 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
390 /// @brief 请求的操作不被支持
391 std::cerr << "RETCODE_UNSUPPORTED" << std::endl;
392 return false;
393 }
394 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
395 /// @brief 提供了错误的参数
396 std::cerr << "RETCODE_BAD_PARAMETER" << std::endl;
397 return false;
398 }
399 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
400 /// @brief 调用前的条件未满足
401 std::cerr << "RETCODE_PRECONDITION_NOT_MET" << std::endl;
402 return false;
403 }
404 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
405 /// @brief 资源不足
406 std::cerr << "RETCODE_OUT_OF_RESOURCES" << std::endl;
407 return false;
408 }
409 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
410 /// @brief 实体未启用
411 std::cerr << "RETCODE_NOT_ENABLED" << std::endl;
412 return false;
413 }
414 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
415 /// @brief 试图修改不可变的策略
416 std::cerr << "RETCODE_IMMUTABLE_POLICY" << std::endl;
417 return false;
418 }
419 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
420 /// @brief 策略不一致
421 std::cerr << "RETCODE_INCONSISTENT_POLICY" << std::endl;
422 return false;
423 }
424 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
425 /// @brief 实体已被删除
426 std::cerr << "RETCODE_ALREADY_DELETED" << std::endl;
427 return false;
428 }
429 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
430 /// @brief 操作超时
431 std::cerr << "RETCODE_TIMEOUT" << std::endl;
432 return false;
433 }
434 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
435 /// @brief 没有数据
436 std::cerr << "RETCODE_NO_DATA" << std::endl;
437 return false;
438 }
439 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
440 /// @brief 非法操作
441 std::cerr << "RETCODE_ILLEGAL_OPERATION" << std::endl;
442 return false;
443 }
444 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
445 /// @brief 安全策略不允许的操作
446 std::cerr << "RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
447 return false;
448 }
449 /// @brief 未知错误
450 std::cerr << "UNKNOWN" << std::endl;
451 return false;
452 }
453 /**
454 * @brief 设置图像数据
455 *
456 * 将传入的图像数据复制到一个新的vector中,并调用SetData函数来设置图像数据。
457 *
458 * @param seconds 时间戳的秒部分
459 * @param nanoseconds 时间戳的纳秒部分
460 * @param height 图像的高度
461 * @param width 图像的宽度
462 * @param data 指向图像数据的指针,数据格式为BGRA,每个像素4个字节
463 */
464 void CarlaDepthCameraPublisher::SetImageData(int32_t seconds, uint32_t nanoseconds, size_t height, size_t width, const uint8_t* data) { std::vector<uint8_t> vector_data;
465 const size_t size = height * width * 4;
466 vector_data.resize(size);
467 std::memcpy(&vector_data[0], &data[0], size);
468 SetData(seconds, nanoseconds,height, width, std::move(vector_data));
469 }
470 /**
471 * @brief 设置感兴趣区域(ROI)信息
472 *
473 * 设置图像的感兴趣区域(ROI),包括偏移量、高度、宽度以及是否进行校正。
474 *
475 * @param x_offset ROI的X轴偏移量
476 * @param y_offset ROI的Y轴偏移量
477 * @param height ROI的高度
478 * @param width ROI的宽度
479 * @param do_rectify 是否对ROI进行校正
480 */
481 void CarlaDepthCameraPublisher::SetInfoRegionOfInterest( uint32_t x_offset, uint32_t y_offset, uint32_t height, uint32_t width, bool do_rectify) {
483 roi.x_offset(x_offset);
484 roi.y_offset(y_offset);
485 roi.height(height);
486 roi.width(width);
487 roi.do_rectify(do_rectify);
488 _impl_info->_info.roi(roi);
489 }
490 /**
491 * @brief 设置图像数据及其元数据
492 *
493 * 设置图像的时间戳、帧ID、宽度、高度、编码方式、字节序、步长以及图像数据。
494 *
495 * @param seconds 时间戳的秒部分
496 * @param nanoseconds 时间戳的纳秒部分
497 * @param height 图像的高度
498 * @param width 图像的宽度
499 * @param data 包含图像数据的vector,数据格式为BGRA,每个像素4个字节
500 */
501 void CarlaDepthCameraPublisher::SetData(int32_t seconds, uint32_t nanoseconds, size_t height, size_t width, std::vector<uint8_t>&& data) {
503 time.sec(seconds);
504 time.nanosec(nanoseconds);
505
506 std_msgs::msg::Header header;
507 header.stamp(std::move(time));
508 header.frame_id(_frame_id);
509
510 _impl->_image.header(std::move(header));
511 _impl->_image.width(width);
512 _impl->_image.height(height);
513 _impl->_image.encoding("bgra8");
514 _impl->_image.is_bigendian(0);
515 _impl->_image.step(_impl->_image.width() * sizeof(uint8_t) * 4);
516 _impl->_image.data(std::move(data)); //https://github.com/eProsima/Fast-DDS/issues/2330
517 }
518 /**
519 * @brief 设置相机信息数据的时间戳
520 *
521 * 设置相机信息的时间戳和帧ID。
522 *
523 * @param seconds 时间戳的秒部分
524 * @param nanoseconds 时间戳的纳秒部分
525 */
526 void CarlaDepthCameraPublisher::SetCameraInfoData(int32_t seconds, uint32_t nanoseconds) {
528 time.sec(seconds);
529 time.nanosec(nanoseconds);
530
531 std_msgs::msg::Header header;
532 header.stamp(std::move(time));
533 header.frame_id(_frame_id);
534 _impl_info->_info.header(header);
535 }
536 /**
537 * @brief CarlaDepthCameraPublisher类的构造函数
538 *
539 * 初始化CarlaDepthCameraPublisher对象,创建_impl和_impl_info智能指针成员变量,并设置ROS节点名和父节点名。
540 *
541 * @param ros_name ROS节点名
542 * @param parent 父节点名
543 */
544 CarlaDepthCameraPublisher::CarlaDepthCameraPublisher(const char* ros_name, const char* parent) :
545 _impl(std::make_shared<CarlaDepthCameraPublisherImpl>()),
546 _impl_info(std::make_shared<CarlaCameraInfoPublisherImpl>()) {
547 _name = ros_name;
548 _parent = parent;
549 }
550 /**
551 * @brief CarlaDepthCameraPublisher类的析构函数
552 *
553 * 清理CarlaDepthCameraPublisher对象,释放_impl和_impl_info成员变量所占用的资源。
554 */
556 if (!_impl)
557 return;
558 // 清理_impl相关的资源
559 if (_impl->_datawriter)
560 _impl->_publisher->delete_datawriter(_impl->_datawriter);
561
562 if (_impl->_publisher)
563 _impl->_participant->delete_publisher(_impl->_publisher);
564
565 if (_impl->_topic)
566 _impl->_participant->delete_topic(_impl->_topic);
567
568 if (_impl->_participant)
569 efd::DomainParticipantFactory::get_instance()->delete_participant(_impl->_participant);
570
571 if (!_impl_info)
572 return;
573 // 清理_impl_info相关的资源
574 if (_impl_info->_datawriter)
575 _impl_info->_publisher->delete_datawriter(_impl_info->_datawriter);
576
577 if (_impl_info->_publisher)
578 _impl_info->_participant->delete_publisher(_impl_info->_publisher);
579
580 if (_impl_info->_topic)
581 _impl_info->_participant->delete_topic(_impl_info->_topic);
582
583 if (_impl_info->_participant)
584 efd::DomainParticipantFactory::get_instance()->delete_participant(_impl_info->_participant);
585 }
586 /**
587 * @brief CarlaDepthCameraPublisher类的拷贝构造函数
588 *
589 * 创建一个新的CarlaDepthCameraPublisher对象,作为另一个CarlaDepthCameraPublisher对象的副本。
590 *
591 * @param other 要拷贝的CarlaDepthCameraPublisher对象
592 */
600 /**
601 * @brief 赋值运算符重载
602 *
603 * 将另一个CarlaDepthCameraPublisher对象的值赋给当前对象。
604 *
605 * @param other 要赋值的CarlaDepthCameraPublisher对象
606 * @return 引用当前对象
607 */
609 _frame_id = other._frame_id;
610 _name = other._name;
611 _parent = other._parent;
612 _impl = other._impl;
613 _impl_info = other._impl_info;
614
615 return *this;
616 }
617 /**
618 * @brief CarlaDepthCameraPublisher类的移动构造函数
619 *
620 * 创建一个新的CarlaDepthCameraPublisher对象,通过移动另一个CarlaDepthCameraPublisher对象的资源来初始化。
621 *
622 * @param other 要移动的CarlaDepthCameraPublisher对象
623 */
625 _frame_id = std::move(other._frame_id);
626 _name = std::move(other._name);
627 _parent = std::move(other._parent);
628 _impl = std::move(other._impl);
629 _impl_info = std::move(other._impl_info);
630
631 }
632 /**
633 * @brief 移动赋值运算符重载
634 *
635 * 将另一个CarlaDepthCameraPublisher对象的资源移动到当前对象。
636 *
637 * @param other 要移动的CarlaDepthCameraPublisher对象
638 * @return 引用当前对象
639 */
641 _frame_id = std::move(other._frame_id);
642 _name = std::move(other._name);
643 _parent = std::move(other._parent);
644 _impl = std::move(other._impl);
645 _impl_info = std::move(other._impl_info);
646
647 return *this;
648 }
649}
650}
此类表示用户在IDL文件中定义的Time结构。
eProsima_user_DllExport void nanosec(uint32_t _nanosec)
此函数设置成员nanosec的值。
Definition Time.cpp:183
eProsima_user_DllExport void sec(int32_t _sec)
此函数设置成员sec的值。
Definition Time.cpp:152
用于在ROS 2中发布CARLA深度相机数据的类。 这个类继承自CarlaPublisher,专门用于初始化、设置和发布深度相机数据。
bool Publish()
发布深度图像和相机信息。
bool InitInfo()
初始化相机信息发布者的DDS相关组件。
~CarlaDepthCameraPublisher()
析构函数,用于销毁CarlaDepthCameraPublisher对象。
CarlaDepthCameraPublisher & operator=(const CarlaDepthCameraPublisher &)
拷贝赋值运算符。
void SetInfoRegionOfInterest(uint32_t x_offset, uint32_t y_offset, uint32_t height, uint32_t width, bool do_rectify)
设置感兴趣区域(ROI)信息
CarlaDepthCameraPublisher(const char *ros_name="", const char *parent="")
构造函数,用于创建CarlaDepthCameraPublisher对象。
bool InitImage()
初始化深度图像数据。
void SetImageData(int32_t seconds, uint32_t nanoseconds, size_t height, size_t width, const uint8_t *data)
设置图像数据
bool Init()
初始化函数,用于设置ROS节点和发布者。
void SetData(int32_t seconds, uint32_t nanoseconds, size_t height, size_t width, std::vector< uint8_t > &&data)
设置图像数据及其元数据
std::shared_ptr< CarlaDepthCameraPublisherImpl > _impl
void InitInfoData(uint32_t x_offset, uint32_t y_offset, uint32_t height, uint32_t width, float fov, bool do_rectify)
初始化深度相机信息数据。
std::shared_ptr< CarlaCameraInfoPublisherImpl > _impl_info
bool HasBeenInitialized() const
检查深度相机发布者是否已初始化。
void SetCameraInfoData(int32_t seconds, uint32_t nanoseconds)
设置相机信息数据的时间戳
const std::string & parent() const
此类表示用户在 IDL 文件中定义的 CameraInfo 类型的 TopicDataType。 <>
This class represents the structure CameraInfo defined by the user in the IDL file....
Definition CameraInfo.h:75
此类表示用户在IDL文件中定义的Image类型的主题数据类型。
This class represents the structure Image defined by the user in the IDL file.这个类表示在 IDL(接口定义语言)文件中由用...
This class represents the structure RegionOfInterest defined by the user in the IDL file.
eProsima_user_DllExport void y_offset(uint32_t _y_offset)
This function sets a value in member y_offset
eProsima_user_DllExport void width(uint32_t _width)
This function sets a value in member width
eProsima_user_DllExport void height(uint32_t _height)
This function sets a value in member height
eProsima_user_DllExport void x_offset(uint32_t _x_offset)
This function sets a value in member x_offset
eProsima_user_DllExport void do_rectify(bool _do_rectify)
This function sets a value in member do_rectify
eprosima::fastrtps::types::ReturnCode_t erc
@using erc
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
Carla相机信息发布者内部实现的结构体。
sensor_msgs::msg::CameraInfo _info
相机信息消息实例。
efd::DomainParticipant * _participant
DDS域参与者指针。
efd::TypeSupport _type
DDS类型支持,用于相机信息消息。
efd::DataWriter * _datawriter
DDS数据写入器指针。
efd::Publisher * _publisher
DDS发布者指针。
CarlaListener _listener
CARLA监听器实例。
CARLA深度相机发布者实现结构体。
efd::TypeSupport _type
DDS类型支持,用于深度图像消息。
efd::DataWriter * _datawriter
DDS数据写入器指针。
efd::Publisher * _publisher
DDS发布者指针。
sensor_msgs::msg::Image _image
深度图像消息实例。
efd::DomainParticipant * _participant
DDS域参与者指针。
CarlaListener _listener
CARLA监听器实例。