CARLA
 
载入中...
搜索中...
未找到
CarlaNormalsCameraPublisher.cpp
浏览该文件的文档.
1#define _GLIBCXX_USE_CXX11_ABI 0
2
3#include "CarlaNormalsCameraPublisher.h"// 包含CarlaNormalsCameraPublisher类的声明
4
5#include <string>// 包含字符串类
6// 包含Carla ROS2类型定义
9#include "carla/ros2/listeners/CarlaListener.h"// 包含Carla监听器类
10// 包含Fast-DDS相关头文件
11#include <fastdds/dds/domain/DomainParticipant.hpp>// 域参与者类
12#include <fastdds/dds/publisher/Publisher.hpp> // 发布者类
13#include <fastdds/dds/topic/Topic.hpp>// 主题类
14#include <fastdds/dds/publisher/DataWriter.hpp>// 数据写入器类
15#include <fastdds/dds/topic/TypeSupport.hpp>// 类型支持类
16// 包含Fast-DDS QOS策略相关头文件
17#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>// 域参与者QOS策略
18#include <fastdds/dds/domain/DomainParticipantFactory.hpp>// 域参与者工厂类
19#include <fastdds/dds/publisher/qos/PublisherQos.hpp>// 发布者QOS策略
20#include <fastdds/dds/topic/qos/TopicQos.hpp>// 主题QOS策略
21// 包含RTPS属性与QOS策略的头文件
22#include <fastrtps/attributes/ParticipantAttributes.h>
23#include <fastrtps/qos/QosPolicies.h>
24#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>// 数据写入器QOS策略
25#include <fastdds/dds/publisher/DataWriterListener.hpp>// 数据写入器监听器类
26
27/**
28 * @namespace carla::ros2
29 * @brief 命名空间,包含CARLA与ROS2集成的相关功能。
30 */
31
32 /**
33 * @brief 别名定义,简化eprosima::fastdds::dds命名空间的引用。
34 */
35namespace carla {
36namespace ros2 {
37
38 namespace efd = eprosima::fastdds::dds;
39 /**
40 * @brief 类型别名,简化eprosima::fastrtps::types::ReturnCode_t的引用。
41 */
42 using erc = eprosima::fastrtps::types::ReturnCode_t;
43 /**
44 * @struct CarlaNormalsCameraPublisherImpl
45 * @brief CarlaNormalsCameraPublisher的内部实现结构体。
46 */
48 /**
49 * @brief DDS域参与者指针。
50 */
51 efd::DomainParticipant* _participant { nullptr };
52 /**
53 * @brief DDS发布者指针。
54 */
55 efd::Publisher* _publisher { nullptr };
56 /**
57 * @brief DDS主题指针。
58 */
59 efd::Topic* _topic { nullptr };
60 /**
61 * @brief DDS数据写入器指针。
62 */
63 efd::DataWriter* _datawriter { nullptr };
64 /**
65 * @brief DDS类型支持,用于Image消息。
66 */
67 efd::TypeSupport _type { new sensor_msgs::msg::ImagePubSubType() };
68 /**
69 * @brief CarlaListener实例,用于监听DDS事件。
70 */
71 CarlaListener _listener {};
72 /**
73 * @brief 存储的Image消息。
74 */
76 };
77 /**
78 * @struct CarlaCameraInfoPublisherImpl
79 * @brief CarlaCameraInfoPublisher的内部实现结构体。
80 */
81 struct CarlaCameraInfoPublisherImpl {
82 /**
83 * @brief DDS域参与者指针。
84 */
85 efd::DomainParticipant* _participant { nullptr };
86 /**
87 * @brief DDS发布者指针。
88 */
89 efd::Publisher* _publisher { nullptr };
90 /**
91 * @brief DDS主题指针。
92 */
93 efd::Topic* _topic { nullptr };
94 /**
95 * @brief DDS数据写入器指针。
96 */
97 efd::DataWriter* _datawriter { nullptr };
98 /**
99 * @brief DDS类型支持,用于CameraInfo消息。
100 */
101 efd::TypeSupport _type { new sensor_msgs::msg::CameraInfoPubSubType() };
102 /**
103 * @brief CarlaListener实例,用于监听DDS事件。
104 */
105 CarlaListener _listener {};
106 /**
107 * @brief 初始化标志。
108 */
109 bool _init {false};
110 /**
111 * @brief 存储的CameraInfo消息。
112 */
114 };
115 /**
116 * @brief 检查CarlaNormalsCameraPublisher是否已初始化。
117 *
118 * @return true 如果已初始化,否则返回false。
119 */
121 return _impl_info->_init;
122 }
123 /**
124 * @brief 初始化CameraInfo数据。
125 *
126 * @param x_offset X轴偏移量。
127 * @param y_offset Y轴偏移量。
128 * @param height 图像高度。
129 * @param width 图像宽度。
130 * @param fov 视野角度。
131 * @param do_rectify 是否进行校正。
132 */
133 void CarlaNormalsCameraPublisher::InitInfoData(uint32_t x_offset, uint32_t y_offset, uint32_t height, uint32_t width, float fov, bool do_rectify) {
134 _impl_info->_info = std::move(sensor_msgs::msg::CameraInfo(height, width, fov));
135 SetInfoRegionOfInterest(x_offset, y_offset, height, width, do_rectify);
136 _impl_info->_init = true;
137 }
138 /**
139 * @brief 初始化CarlaNormalsCameraPublisher。
140 *
141 * @return true 如果初始化成功,否则返回false。
142 */
144 return InitImage() && InitInfo();
145 }
146 /**
147 * @brief 初始化图像发布者。
148 *
149 * @return true 如果初始化成功,否则返回false。
150 */
152 // 检查类型支持是否有效
153 if (_impl->_type == nullptr) {
154 std::cerr << "Invalid TypeSupport" << std::endl;// 打印错误信息:无效的类型支持
155 return false;// 返回false表示初始化失败
156 }
157 // 设置DomainParticipant的QoS策略,并创建DomainParticipant
158 efd::DomainParticipantQos pqos = efd::PARTICIPANT_QOS_DEFAULT;
159 pqos.name(_name);// 设置DomainParticipant的名称
160 auto factory = efd::DomainParticipantFactory::get_instance();
161 _impl->_participant = factory->create_participant(0, pqos);// 创建DomainParticipant
162 if (_impl->_participant == nullptr) {
163 std::cerr << "Failed to create DomainParticipant" << std::endl;// 打印错误信息:创建DomainParticipant失败
164 return false;// 返回false表示初始化失败
165 }
166 _impl->_type.register_type(_impl->_participant);// 注册类型到DomainParticipant
167 // 设置Publisher的QoS策略,并创建Publisher
168 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
169 _impl->_publisher = _impl->_participant->create_publisher(pubqos, nullptr);// 创建Publisher
170 if (_impl->_publisher == nullptr) {
171 std::cerr << "Failed to create Publisher" << std::endl;// 打印错误信息:创建Publisher失败
172 return false;// 返回false表示初始化失败
173 }
174 // 设置Topic的QoS策略,并创建Topic
175 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
176 const std::string publisher_type {"/image"};// 定义Topic的类型后缀,表示这是一个图像发布者
177 const std::string base { "rt/carla/" };// 定义Topic的基础路径
178 std::string topic_name = base;// 初始化Topic名称
179 if (!_parent.empty())// 如果父路径不为空
180 topic_name += _parent + "/";// 添加父路径到Topic名称
181 topic_name += _name;// 添加名称到Topic名称
182 topic_name += publisher_type;// 添加类型后缀到Topic名称
183 _impl->_topic = _impl->_participant->create_topic(topic_name, _impl->_type->getName(), tqos);
184 if (_impl->_topic == nullptr) {
185 std::cerr << "Failed to create Topic" << std::endl;// 打印错误信息:创建Topic失败
186 return false;// 返回false表示初始化失败
187 }
188 // 设置DataWriter的QoS策略,并创建DataWriter
189 efd::DataWriterQos wqos = efd::DATAWRITER_QOS_DEFAULT;
190 wqos.endpoint().history_memory_policy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;// 设置历史内存策略为预分配并允许重新分配
191 efd::DataWriterListener* listener = (efd::DataWriterListener*)_impl->_listener._impl.get();// 获取DataWriter监听器
192 _impl->_datawriter = _impl->_publisher->create_datawriter(_impl->_topic, wqos, listener);// 创建DataWriter
193 if (_impl->_datawriter == nullptr) {
194 std::cerr << "Failed to create DataWriter" << std::endl;// 打印错误信息:创建DataWriter失败
195 return false;// 返回false表示初始化失败
196 }
197 // 设置帧ID为名称
199 return true;// 返回true表示初始化成功
200 }
201 /**
202 * @brief 初始化CameraInfo发布者。
203 *
204 * @return true 如果初始化成功,否则返回false。
205 */
207 // 检查类型支持是否有效
208 if (_impl_info->_type == nullptr) {
209 std::cerr << "Invalid TypeSupport" << std::endl;// 打印错误信息
210 return false;// 返回false表示初始化失败
211 }
212 // 设置DomainParticipant的QoS策略,并创建DomainParticipant
213 efd::DomainParticipantQos pqos = efd::PARTICIPANT_QOS_DEFAULT;
214 pqos.name(_name);// 设置DomainParticipant的名称
215 auto factory = efd::DomainParticipantFactory::get_instance();
216 _impl_info->_participant = factory->create_participant(0, pqos);// 创建DomainParticipant
217 if (_impl_info->_participant == nullptr) {
218 std::cerr << "Failed to create DomainParticipant" << std::endl;// 打印错误信息:创建DomainParticipant失败
219 return false;// 返回false表示初始化失败
220 }
221 _impl_info->_type.register_type(_impl_info->_participant);// 注册类型到DomainParticipant
222 // 设置Publisher的QoS策略,并创建Publisher
223 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
224 _impl_info->_publisher = _impl_info->_participant->create_publisher(pubqos, nullptr);// 创建Publisher
225 if (_impl_info->_publisher == nullptr) {
226 std::cerr << "Failed to create Publisher" << std::endl;// 打印错误信息:创建Publisher失败
227 return false;// 返回false表示初始化失败
228 }
229 // 设置Topic的QoS策略,并创建Topic
230 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
231 const std::string publisher_type {"/camera_info"};// 定义Topic类型后缀
232 const std::string base { "rt/carla/" };// 定义Topic的基础路径
233 std::string topic_name = base;// 初始化Topic名称
234 if (!_parent.empty())// 如果父路径不为空
235 topic_name += _parent + "/"; // 添加父路径到Topic名称
236 topic_name += _name;// 添加名称到Topic名称
237 topic_name += publisher_type;// 添加类型后缀到Topic名称
238 _impl_info->_topic = _impl_info->_participant->create_topic(topic_name, _impl_info->_type->getName(), tqos);// 创建Topic
239 if (_impl_info->_topic == nullptr) {
240 std::cerr << "Failed to create Topic" << std::endl;// 打印错误信息:创建Topic失败
241 return false;// 返回false表示初始化失败
242 }// 设置DataWriter的QoS策略,并创建DataWriter
243 efd::DataWriterQos wqos = efd::DATAWRITER_QOS_DEFAULT;
244 efd::DataWriterListener* listener = (efd::DataWriterListener*)_impl_info->_listener._impl.get();// 获取DataWriter监听器
245 _impl_info->_datawriter = _impl_info->_publisher->create_datawriter(_impl_info->_topic, wqos, listener);// 创建DataWriter
246 if (_impl_info->_datawriter == nullptr) {
247 std::cerr << "Failed to create DataWriter" << std::endl;// 打印错误信息:创建DataWriter失败
248 return false;// 返回false表示初始化失败
249 }
250 // 设置帧ID为名称
252 return true;// 返回true表示初始化成功
253 }
254 /**
255 * @brief 发布图像和相关信息
256 *
257 * 该函数负责发布图像数据以及相关的图像信息。它首先尝试发布图像数据,
258 * 然后尝试发布图像信息。如果两者都成功发布,则返回true;否则返回false。
259 *
260 * @return bool 如果图像和相关信息都成功发布,则返回true;否则返回false。
261 */
265 /**
266 * @brief 发布图像数据
267 *
268 * 该函数尝试通过Fast-RTPS发布图像数据。根据返回码(rcode)判断发布是否成功,
269 * 并输出相应的错误信息。如果发布成功,返回true;否则返回false。
270 *
271 * @return bool 如果图像数据成功发布,则返回true;否则返回false。
272 */
274 eprosima::fastrtps::rtps::InstanceHandle_t instance_handle;
275 eprosima::fastrtps::types::ReturnCode_t rcode = _impl->_datawriter->write(&_impl->_image, instance_handle);
276 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
277 return true;
278 }// 根据返回码判断发布结果,并输出相应的错误信息
279 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
280 std::cerr << "RETCODE_ERROR" << std::endl;
281 return false;
282 }
283 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
284 std::cerr << "RETCODE_UNSUPPORTED" << std::endl;
285 return false;
286 }
287 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
288 std::cerr << "RETCODE_BAD_PARAMETER" << std::endl;
289 return false;
290 }
291 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
292 std::cerr << "RETCODE_PRECONDITION_NOT_MET" << std::endl;
293 return false;
294 }
295 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
296 std::cerr << "RETCODE_OUT_OF_RESOURCES" << std::endl;
297 return false;
298 }
299 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
300 std::cerr << "RETCODE_NOT_ENABLED" << std::endl;
301 return false;
302 }
303 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
304 std::cerr << "RETCODE_IMMUTABLE_POLICY" << std::endl;
305 return false;
306 }
307 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
308 std::cerr << "RETCODE_INCONSISTENT_POLICY" << std::endl;
309 return false;
310 }
311 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
312 std::cerr << "RETCODE_ALREADY_DELETED" << std::endl;
313 return false;
314 }
315 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
316 std::cerr << "RETCODE_TIMEOUT" << std::endl;
317 return false;
318 }
319 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
320 std::cerr << "RETCODE_NO_DATA" << std::endl;
321 return false;
322 }
323 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
324 std::cerr << "RETCODE_ILLEGAL_OPERATION" << std::endl;
325 return false;
326 }
327 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
328 std::cerr << "RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
329 return false;
330 }
331 std::cerr << "UNKNOWN" << std::endl;
332 return false;
333 }
334 /**
335 * @brief 发布图像信息
336 *
337 * 该函数尝试通过Fast-RTPS发布图像信息。根据返回码(rcode)判断发布是否成功,
338 * 并输出相应的错误信息。如果发布成功,返回true;否则返回false。
339 *
340 * @return bool 如果图像信息成功发布,则返回true;否则返回false。
341 */
343 eprosima::fastrtps::rtps::InstanceHandle_t instance_handle;
344 eprosima::fastrtps::types::ReturnCode_t rcode = _impl_info->_datawriter->write(&_impl_info->_info, instance_handle);
345 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
346 return true;
347 }// 根据返回码判断发布结果,并输出相应的错误信息
348 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
349 std::cerr << "RETCODE_ERROR" << std::endl;
350 return false;
351 }
352 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
353 std::cerr << "RETCODE_UNSUPPORTED" << std::endl;
354 return false;
355 }
356 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
357 std::cerr << "RETCODE_BAD_PARAMETER" << std::endl;
358 return false;
359 }
360 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
361 std::cerr << "RETCODE_PRECONDITION_NOT_MET" << std::endl;
362 return false;
363 }
364 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
365 std::cerr << "RETCODE_OUT_OF_RESOURCES" << std::endl;
366 return false;
367 }
368 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
369 std::cerr << "RETCODE_NOT_ENABLED" << std::endl;
370 return false;
371 }
372 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
373 std::cerr << "RETCODE_IMMUTABLE_POLICY" << std::endl;
374 return false;
375 }
376 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
377 std::cerr << "RETCODE_INCONSISTENT_POLICY" << std::endl;
378 return false;
379 }
380 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
381 std::cerr << "RETCODE_ALREADY_DELETED" << std::endl;
382 return false;
383 }
384 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
385 std::cerr << "RETCODE_TIMEOUT" << std::endl;
386 return false;
387 }
388 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
389 std::cerr << "RETCODE_NO_DATA" << std::endl;
390 return false;
391 }
392 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
393 std::cerr << "RETCODE_ILLEGAL_OPERATION" << std::endl;
394 return false;
395 }
396 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
397 std::cerr << "RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
398 return false;
399 }
400 std::cerr << "UNKNOWN" << std::endl;
401 return false;
402 }
403 /**
404 * @brief 设置图像数据
405 *
406 * 将传入的图像数据复制到内部存储,并调用SetData方法设置图像数据。
407 *
408 * @param seconds 时间戳的秒部分
409 * @param nanoseconds 时间戳的纳秒部分
410 * @param height 图像的高度
411 * @param width 图像的宽度
412 * @param data 指向图像数据的指针
413 */
414 void CarlaNormalsCameraPublisher::SetImageData(int32_t seconds, uint32_t nanoseconds, size_t height, size_t width, const uint8_t* data) { std::vector<uint8_t> vector_data;
415 const size_t size = height * width * 4;
416 vector_data.resize(size);
417 std::memcpy(&vector_data[0], &data[0], size);
418 SetData(seconds, nanoseconds,height, width, std::move(vector_data));
419 }
420 /**
421 * @brief 设置感兴趣区域(Region of Interest, ROI)
422 *
423 * 设置图像的感兴趣区域,包括偏移量和尺寸,以及是否进行校正。
424 *
425 * @param x_offset ROI的X轴偏移量
426 * @param y_offset ROI的Y轴偏移量
427 * @param height ROI的高度
428 * @param width ROI的宽度
429 * @param do_rectify 是否对ROI进行校正
430 */
431 void CarlaNormalsCameraPublisher::SetInfoRegionOfInterest( uint32_t x_offset, uint32_t y_offset, uint32_t height, uint32_t width, bool do_rectify) {
433 roi.x_offset(x_offset);
434 roi.y_offset(y_offset);
435 roi.height(height);
436 roi.width(width);
437 roi.do_rectify(do_rectify);
438 _impl_info->_info.roi(roi);
439 }
440 /**
441 * @brief 设置图像数据
442 *
443 * 设置图像的时间戳、帧ID、尺寸、编码和数据。
444 *
445 * @param seconds 时间戳的秒部分
446 * @param nanoseconds 时间戳的纳秒部分
447 * @param height 图像的高度
448 * @param width 图像的宽度
449 * @param data 图像数据的vector
450 */
451 void CarlaNormalsCameraPublisher::SetData(int32_t seconds, uint32_t nanoseconds, size_t height, size_t width, std::vector<uint8_t>&& data) {
453 time.sec(seconds);
454 time.nanosec(nanoseconds);
455
456 std_msgs::msg::Header header;
457 header.stamp(std::move(time));
458 header.frame_id(_frame_id);
459
460 _impl->_image.header(std::move(header));
461 _impl->_image.width(width);
462 _impl->_image.height(height);
463 _impl->_image.encoding("bgra8");
464 _impl->_image.is_bigendian(0);
465 _impl->_image.step(_impl->_image.width() * sizeof(uint8_t) * 4);
466 _impl->_image.data(std::move(data)); //https://github.com/eProsima/Fast-DDS/issues/2330
467 }
468 /**
469 * @brief 设置相机信息数据的时间戳
470 *
471 * 设置相机信息的时间戳和帧ID。
472 *
473 * @param seconds 时间戳的秒部分
474 * @param nanoseconds 时间戳的纳秒部分
475 */
476 void CarlaNormalsCameraPublisher::SetCameraInfoData(int32_t seconds, uint32_t nanoseconds) {
478 time.sec(seconds);
479 time.nanosec(nanoseconds);
480
481 std_msgs::msg::Header header;
482 header.stamp(std::move(time));
483 header.frame_id(_frame_id);
484 _impl_info->_info.header(header);
485 }
486 /**
487 * @brief CarlaNormalsCameraPublisher的构造函数
488 *
489 * 初始化CarlaNormalsCameraPublisher对象,包括内部实现对象和相机信息对象。
490 *
491 * @param ros_name ROS节点名称
492 * @param parent 父节点名称
493 */
494 CarlaNormalsCameraPublisher::CarlaNormalsCameraPublisher(const char* ros_name, const char* parent) :
495 _impl(std::make_shared<CarlaNormalsCameraPublisherImpl>()),
496 _impl_info(std::make_shared<CarlaCameraInfoPublisherImpl>()) {
497 _name = ros_name;
498 _parent = parent;
499 }
500 /**
501 * @brief CarlaNormalsCameraPublisher的析构函数
502 *
503 * 清理资源,包括删除数据写入器、发布者、主题和参与者。
504 */
506 if (!_impl)
507 return;
508
509 if (_impl->_datawriter)
510 _impl->_publisher->delete_datawriter(_impl->_datawriter);
511
512 if (_impl->_publisher)
513 _impl->_participant->delete_publisher(_impl->_publisher);
514
515 if (_impl->_topic)
516 _impl->_participant->delete_topic(_impl->_topic);
517
518 if (_impl->_participant)
519 efd::DomainParticipantFactory::get_instance()->delete_participant(_impl->_participant);
520
521 if (!_impl_info)
522 return;
523
524 if (_impl_info->_datawriter)
525 _impl_info->_publisher->delete_datawriter(_impl_info->_datawriter);
526
527 if (_impl_info->_publisher)
528 _impl_info->_participant->delete_publisher(_impl_info->_publisher);
529
530 if (_impl_info->_topic)
531 _impl_info->_participant->delete_topic(_impl_info->_topic);
532
533 if (_impl_info->_participant)
534 efd::DomainParticipantFactory::get_instance()->delete_participant(_impl_info->_participant);
535 }
536 /**
537 * @brief CarlaNormalsCameraPublisher的拷贝构造函数
538 *
539 * 创建一个新的CarlaNormalsCameraPublisher对象,并复制另一个对象的数据。
540 *
541 * @param other 要复制的CarlaNormalsCameraPublisher对象
542 */
550 /**
551 * @brief 赋值运算符重载
552 *
553 * 将另一个CarlaNormalsCameraPublisher对象的数据复制到当前对象。
554 *
555 * @param other 要复制的CarlaNormalsCameraPublisher对象
556 * @return 引用当前对象
557 */
559 _frame_id = other._frame_id;
560 _name = other._name;
561 _parent = other._parent;
562 _impl = other._impl;
563 _impl_info = other._impl_info;
564
565 return *this;
566 }
567 /**
568 * @brief CarlaNormalsCameraPublisher的移动构造函数
569 *
570 * 创建一个新的CarlaNormalsCameraPublisher对象,并移动另一个对象的数据。
571 *
572 * @param other 要移动的CarlaNormalsCameraPublisher对象
573 */
575 _frame_id = std::move(other._frame_id);
576 _name = std::move(other._name);
577 _parent = std::move(other._parent);
578 _impl = std::move(other._impl);
579 _impl_info = std::move(other._impl_info);
580
581 }
582 /**
583 * @brief 移动赋值运算符重载
584 *
585 * 将另一个CarlaNormalsCameraPublisher对象的数据移动到当前对象。
586 *
587 * @param other 要移动的CarlaNormalsCameraPublisher对象
588 * @return 引用当前对象
589 */
591 _frame_id = std::move(other._frame_id);
592 _name = std::move(other._name);
593 _parent = std::move(other._parent);
594 _impl = std::move(other._impl);
595 _impl_info = std::move(other._impl_info);
596
597 return *this;
598 }
599}
600}
此类表示用户在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
void InitInfoData(uint32_t x_offset, uint32_t y_offset, uint32_t height, uint32_t width, float fov, bool do_rectify)
初始化CameraInfo数据。
void SetImageData(int32_t seconds, uint32_t nanoseconds, size_t height, size_t width, const uint8_t *data)
设置图像数据
CarlaNormalsCameraPublisher(const char *ros_name="", const char *parent="")
CarlaNormalsCameraPublisher的构造函数
void SetInfoRegionOfInterest(uint32_t x_offset, uint32_t y_offset, uint32_t height, uint32_t width, bool do_rectify)
设置感兴趣区域(Region of Interest, ROI)
bool HasBeenInitialized() const
检查CarlaNormalsCameraPublisher是否已初始化。
CarlaNormalsCameraPublisher & operator=(const CarlaNormalsCameraPublisher &)
赋值运算符重载
bool Init()
初始化CarlaNormalsCameraPublisher。
void SetCameraInfoData(int32_t seconds, uint32_t nanoseconds)
设置相机信息数据的时间戳
bool InitInfo()
初始化CameraInfo发布者。
void SetData(int32_t seconds, uint32_t nanoseconds, size_t height, size_t width, std::vector< uint8_t > &&data)
设置图像数据
std::shared_ptr< CarlaNormalsCameraPublisherImpl > _impl
~CarlaNormalsCameraPublisher()
CarlaNormalsCameraPublisher的析构函数
std::shared_ptr< CarlaCameraInfoPublisherImpl > _impl_info
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监听器实例。
CarlaNormalsCameraPublisher的内部实现结构体。
efd::DataWriter * _datawriter
DDS数据写入器指针。
CarlaListener _listener
CarlaListener实例,用于监听DDS事件。
sensor_msgs::msg::Image _image
存储的Image消息。
efd::TypeSupport _type
DDS类型支持,用于Image消息。
efd::DomainParticipant * _participant
DDS域参与者指针。