1#define _GLIBCXX_USE_CXX11_ABI 0
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>
17#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
18#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
19#include <fastdds/dds/publisher/qos/PublisherQos.hpp>
20#include <fastdds/dds/topic/qos/TopicQos.hpp>
22#include <fastrtps/attributes/ParticipantAttributes.h>
23#include <fastrtps/qos/QosPolicies.h>
24#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
25#include <fastdds/dds/publisher/DataWriterListener.hpp>
31 namespace efd = eprosima::fastdds::dds;
32 using erc = eprosima::fastrtps::types::ReturnCode_t;
52 if (
_impl->_type ==
nullptr) {
53 std::cerr <<
"Invalid TypeSupport" << std::endl;
57 efd::DomainParticipantQos pqos = efd::PARTICIPANT_QOS_DEFAULT;
59 auto factory = efd::DomainParticipantFactory::get_instance();
60 _impl->_participant = factory->create_participant(0, pqos);
61 if (
_impl->_participant ==
nullptr) {
62 std::cerr <<
"Failed to create DomainParticipant" << std::endl;
65 _impl->_type.register_type(
_impl->_participant);
67 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
68 _impl->_publisher =
_impl->_participant->create_publisher(pubqos,
nullptr);
69 if (
_impl->_publisher ==
nullptr) {
70 std::cerr <<
"Failed to create Publisher" << std::endl;
74 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
75 const std::string base {
"rt/carla/" };
76 std::string topic_name = base;
80 _impl->_topic =
_impl->_participant->create_topic(topic_name,
_impl->_type->getName(), tqos);
81 if (
_impl->_topic ==
nullptr) {
82 std::cerr <<
"Failed to create Topic" << std::endl;
86 efd::DataWriterQos wqos = efd::DATAWRITER_QOS_DEFAULT;
87 wqos.endpoint().history_memory_policy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
89 _impl->_datawriter =
_impl->_publisher->create_datawriter(
_impl->_topic, wqos, listener);
90 if (
_impl->_datawriter ==
nullptr) {
91 std::cerr <<
"Failed to create DataWriter" << std::endl;
99 eprosima::fastrtps::rtps::InstanceHandle_t instance_handle;
100 eprosima::fastrtps::types::ReturnCode_t rcode =
_impl->_datawriter->write(&
_impl->_radar, instance_handle);
101 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
104 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
105 std::cerr <<
"RETCODE_ERROR" << std::endl;
108 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
109 std::cerr <<
"RETCODE_UNSUPPORTED" << std::endl;
112 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
113 std::cerr <<
"RETCODE_BAD_PARAMETER" << std::endl;
116 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
117 std::cerr <<
"RETCODE_PRECONDITION_NOT_MET" << std::endl;
120 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
121 std::cerr <<
"RETCODE_OUT_OF_RESOURCES" << std::endl;
124 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
125 std::cerr <<
"RETCODE_NOT_ENABLED" << std::endl;
128 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
129 std::cerr <<
"RETCODE_IMMUTABLE_POLICY" << std::endl;
132 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
133 std::cerr <<
"RETCODE_INCONSISTENT_POLICY" << std::endl;
136 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
137 std::cerr <<
"RETCODE_ALREADY_DELETED" << std::endl;
140 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
141 std::cerr <<
"RETCODE_TIMEOUT" << std::endl;
144 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
145 std::cerr <<
"RETCODE_NO_DATA" << std::endl;
148 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
149 std::cerr <<
"RETCODE_ILLEGAL_OPERATION" << std::endl;
152 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
153 std::cerr <<
"RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
156 std::cerr <<
"UNKNOWN" << std::endl;
162 std::vector<uint8_t> vector_data;
164 vector_data.resize(size);
167 for (
size_t i = 0; i < elements; ++i, ++radar_data, ++detection_data) {
168 radar_data->
x = detection_data->
depth * cosf(detection_data->
azimuth) * cosf(-detection_data->
altitude);
169 radar_data->
y = detection_data->
depth * sinf(-detection_data->
azimuth) * cosf(detection_data->
altitude);
170 radar_data->
z = detection_data->
depth * sinf(detection_data->
altitude);
174 SetData(seconds, nanoseconds, height, width, elements, std::move(vector_data));
183 header.
stamp(std::move(time));
187 descriptor1.
name(
"x");
190 descriptor1.
count(1);
192 descriptor2.
name(
"y");
195 descriptor2.
count(1);
197 descriptor3.
name(
"z");
200 descriptor3.
count(1);
202 descriptor4.
name(
"velocity");
205 descriptor4.
count(1);
207 descriptor5.
name(
"azimuth");
210 descriptor5.
count(1);
212 descriptor6.
name(
"altitude");
215 descriptor6.
count(1);
217 descriptor7.
name(
"depth");
220 descriptor7.
count(1);
223 _impl->_radar.header(std::move(header));
224 _impl->_radar.width(elements);
225 _impl->_radar.height(height);
226 _impl->_radar.is_bigendian(
false);
227 _impl->_radar.fields({descriptor1, descriptor2, descriptor3, descriptor4, descriptor5, descriptor6, descriptor7});
228 _impl->_radar.point_step(point_size);
229 _impl->_radar.row_step(elements * point_size);
230 _impl->_radar.is_dense(
false);
231 _impl->_radar.data(std::move(data));
244 if (
_impl->_datawriter)
245 _impl->_publisher->delete_datawriter(
_impl->_datawriter);
247 if (
_impl->_publisher)
248 _impl->_participant->delete_publisher(
_impl->_publisher);
251 _impl->_participant->delete_topic(
_impl->_topic);
253 if (
_impl->_participant)
254 efd::DomainParticipantFactory::get_instance()->delete_participant(
_impl->_participant);
275 _name = std::move(other._name);
276 _parent = std::move(other._parent);
277 _impl = std::move(other._impl);
282 _name = std::move(other._name);
283 _parent = std::move(other._parent);
284 _impl = std::move(other._impl);
This class represents the structure Time defined by the user in the IDL file.
eProsima_user_DllExport void nanosec(uint32_t _nanosec)
This function sets a value in member nanosec
eProsima_user_DllExport void sec(int32_t _sec)
This function sets a value in member sec
const std::string & parent() const
CarlaRadarPublisher(const char *ros_name="", const char *parent="")
std::shared_ptr< CarlaRadarPublisherImpl > _impl
void SetData(int32_t seconds, uint32_t nanoseconds, size_t height, size_t width, size_t elements, const uint8_t *data)
CarlaRadarPublisher & operator=(const CarlaRadarPublisher &)
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.
This class represents the structure PointField defined by the user in the IDL file.
eProsima_user_DllExport void count(uint32_t _count)
This function sets a value in member count
eProsima_user_DllExport void offset(uint32_t _offset)
This function sets a value in member offset
eProsima_user_DllExport void name(const std::string &_name)
This function copies the value in member name
eProsima_user_DllExport void datatype(uint8_t _datatype)
This function sets a value in member datatype
eprosima::fastrtps::types::ReturnCode_t erc
This file contains definitions of common data structures used in traffic manager.
const uint8_t PointField__FLOAT32
sensor_msgs::msg::PointCloud2 _radar
efd::Publisher * _publisher
efd::DomainParticipant * _participant
efd::DataWriter * _datawriter
carla::sensor::data::RadarDetection detection