1#define _GLIBCXX_USE_CXX11_ABI 0
10#include <fastdds/dds/domain/DomainParticipant.hpp>
11#include <fastdds/dds/publisher/Publisher.hpp>
12#include <fastdds/dds/topic/Topic.hpp>
13#include <fastdds/dds/publisher/DataWriter.hpp>
14#include <fastdds/dds/topic/TypeSupport.hpp>
16#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
17#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
18#include <fastdds/dds/publisher/qos/PublisherQos.hpp>
19#include <fastdds/dds/topic/qos/TopicQos.hpp>
21#include <fastrtps/attributes/ParticipantAttributes.h>
22#include <fastrtps/qos/QosPolicies.h>
23#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
24#include <fastdds/dds/publisher/DataWriterListener.hpp>
35 namespace efd = eprosima::fastdds::dds;
39 using erc = eprosima::fastrtps::types::ReturnCode_t;
64 if (
_impl->_type ==
nullptr) {
65 std::cerr <<
"Invalid TypeSupport" << std::endl;
69 efd::DomainParticipantQos pqos = efd::PARTICIPANT_QOS_DEFAULT;
71 auto factory = efd::DomainParticipantFactory::get_instance();
72 _impl->_participant = factory->create_participant(0, pqos);
73 if (
_impl->_participant ==
nullptr) {
74 std::cerr <<
"Failed to create DomainParticipant" << std::endl;
78 _impl->_type.register_type(
_impl->_participant);
80 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
81 _impl->_publisher =
_impl->_participant->create_publisher(pubqos,
nullptr);
82 if (
_impl->_publisher ==
nullptr) {
83 std::cerr <<
"Failed to create Publisher" << std::endl;
87 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
88 const std::string base {
"rt/carla/" };
89 std::string topic_name = base;
93 _impl->_topic =
_impl->_participant->create_topic(topic_name,
_impl->_type->getName(), tqos);
94 if (
_impl->_topic ==
nullptr) {
95 std::cerr <<
"Failed to create Topic" << std::endl;
99 efd::DataWriterQos wqos = efd::DATAWRITER_QOS_DEFAULT;
100 wqos.endpoint().history_memory_policy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
102 _impl->_datawriter =
_impl->_publisher->create_datawriter(
_impl->_topic, wqos, listener);
103 if (
_impl->_datawriter ==
nullptr) {
104 std::cerr <<
"Failed to create DataWriter" << std::endl;
116 eprosima::fastrtps::rtps::InstanceHandle_t instance_handle;
119 eprosima::fastrtps::types::ReturnCode_t rcode =
_impl->_datawriter->write(&
_impl->_lidar, instance_handle);
121 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
125 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
126 std::cerr <<
"RETCODE_ERROR" << std::endl;
130 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
131 std::cerr <<
"RETCODE_UNSUPPORTED" << std::endl;
135 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
136 std::cerr <<
"RETCODE_BAD_PARAMETER" << std::endl;
140 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
141 std::cerr <<
"RETCODE_PRECONDITION_NOT_MET" << std::endl;
145 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
146 std::cerr <<
"RETCODE_OUT_OF_RESOURCES" << std::endl;
150 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
151 std::cerr <<
"RETCODE_NOT_ENABLED" << std::endl;
155 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
156 std::cerr <<
"RETCODE_IMMUTABLE_POLICY" << std::endl;
160 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
161 std::cerr <<
"RETCODE_INCONSISTENT_POLICY" << std::endl;
165 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
166 std::cerr <<
"RETCODE_ALREADY_DELETED" << std::endl;
170 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
171 std::cerr <<
"RETCODE_TIMEOUT" << std::endl;
175 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
176 std::cerr <<
"RETCODE_NO_DATA" << std::endl;
180 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
181 std::cerr <<
"RETCODE_ILLEGAL_OPERATION" << std::endl;
185 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
186 std::cerr <<
"RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
190 std::cerr <<
"UNKNOWN" << std::endl;
210 float*
end = &data[height * width * elements];
212 for (++it; it <
end; it += elements) {
216 std::vector<uint8_t> vector_data;
218 const size_t size = height * width *
sizeof(float) * elements;
220 vector_data.resize(size);
222 std::memcpy(&vector_data[0], &data[0], size);
224 SetData(seconds, nanoseconds, height, width, std::move(vector_data));
244 std_msgs::msg::Header header;
245 header.stamp(std::move(time));
249 descriptor1.
name(
"x");
252 descriptor1.
count(1);
254 descriptor2.
name(
"y");
257 descriptor2.
count(1);
259 descriptor3.
name(
"z");
262 descriptor3.
count(1);
264 descriptor4.
name(
"cos_inc_angle");
267 descriptor4.
count(1);
269 descriptor5.
name(
"object_idx");
272 descriptor5.
count(1);
274 descriptor6.
name(
"object_tag");
277 descriptor6.
count(1);
279 const size_t point_size = 6 *
sizeof(float);
281 _impl->_lidar.header(std::move(header));
282 _impl->_lidar.width(width);
283 _impl->_lidar.height(height);
284 _impl->_lidar.is_bigendian(
false);
285 _impl->_lidar.fields({descriptor1, descriptor2, descriptor3, descriptor4, descriptor5, descriptor6});
286 _impl->_lidar.point_step(point_size);
287 _impl->_lidar.row_step(width * point_size);
288 _impl->_lidar.is_dense(
false);
289 _impl->_lidar.data(std::move(data));
315 if (
_impl->_datawriter)
316 _impl->_publisher->delete_datawriter(
_impl->_datawriter);
318 if (
_impl->_publisher)
319 _impl->_participant->delete_publisher(
_impl->_publisher);
322 _impl->_participant->delete_topic(
_impl->_topic);
324 if (
_impl->_participant)
325 efd::DomainParticipantFactory::get_instance()->delete_participant(
_impl->_participant);
365 _name = std::move(other._name);
366 _parent = std::move(other._parent);
367 _impl = std::move(other._impl);
379 _name = std::move(other._name);
380 _parent = std::move(other._parent);
381 _impl = std::move(other._impl);
auto end() const noexcept
eProsima_user_DllExport void nanosec(uint32_t _nanosec)
此函数设置成员nanosec的值。
eProsima_user_DllExport void sec(int32_t _sec)
此函数设置成员sec的值。
const std::string & parent() const
std::shared_ptr< CarlaSemanticLidarPublisherImpl > _impl
void SetData(int32_t seconds, uint32_t nanoseconds, size_t elements, size_t height, size_t width, float *data)
设置激光雷达数据,包括时间戳、数据尺寸以及浮点数据数组,并对数据进行预处理。
bool Init()
初始化Carla语义激光雷达数据发布者。
CarlaSemanticLidarPublisher(const char *ros_name="", const char *parent="")
CarlaSemanticLidarPublisher类的构造函数。
CarlaSemanticLidarPublisher & operator=(const CarlaSemanticLidarPublisher &)
拷贝赋值运算符重载。
~CarlaSemanticLidarPublisher()
CarlaSemanticLidarPublisher类的析构函数。
This class represents the TopicDataType of the type PointCloud2 defined by the user in the IDL file.
This class represents the structure PointCloud2 defined by the user in the IDL file.
此类表示用户在 IDL 文件中定义的结构 PointField。 <>
eProsima_user_DllExport void count(uint32_t _count)
此函数设置成员 count 的值
eProsima_user_DllExport void offset(uint32_t _offset)
此函数设置成员 offset 的值
eProsima_user_DllExport void name(const std::string &_name)
此函数复制成员 name 的值
eProsima_user_DllExport void datatype(uint8_t _datatype)
此函数设置成员 datatype 的值
eprosima::fastrtps::types::ReturnCode_t erc
@using erc
const uint8_t PointField__FLOAT32
const uint8_t PointField__UINT32
CarlaListener _listener
CARLA监听器
sensor_msgs::msg::PointCloud2 _lidar
存储点云数据的成员变量
efd::DomainParticipant * _participant
域参与者指针
efd::Publisher * _publisher
发布者指针
efd::DataWriter * _datawriter
数据写入器指针
efd::TypeSupport _type
类型支持,用于点云数据