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>
18#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
19#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
20#include <fastdds/dds/publisher/qos/PublisherQos.hpp>
21#include <fastdds/dds/topic/qos/TopicQos.hpp>
24#include <fastrtps/attributes/ParticipantAttributes.h>
25#include <fastrtps/qos/QosPolicies.h>
26#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
27#include <fastdds/dds/publisher/DataWriterListener.hpp>
35 namespace efd = eprosima::fastdds::dds;
36 using erc = eprosima::fastrtps::types::ReturnCode_t;
48 struct CarlaCameraInfoPublisherImpl {
51 efd::Topic*
_topic {
nullptr };
74 if (
_impl->_type ==
nullptr) {
75 std::cerr <<
"Invalid TypeSupport" << std::endl;
79 efd::DomainParticipantQos pqos = efd::PARTICIPANT_QOS_DEFAULT;
81 auto factory = efd::DomainParticipantFactory::get_instance();
82 _impl->_participant = factory->create_participant(0, pqos);
83 if (
_impl->_participant ==
nullptr) {
84 std::cerr <<
"Failed to create DomainParticipant" << std::endl;
87 _impl->_type.register_type(
_impl->_participant);
89 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
90 _impl->_publisher =
_impl->_participant->create_publisher(pubqos,
nullptr);
91 if (
_impl->_publisher ==
nullptr) {
92 std::cerr <<
"Failed to create Publisher" << std::endl;
96 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
97 const std::string publisher_type {
"/image"};
98 const std::string base {
"rt/carla/" };
99 std::string topic_name = base;
103 topic_name += publisher_type;
104 _impl->_topic =
_impl->_participant->create_topic(topic_name,
_impl->_type->getName(), tqos);
105 if (
_impl->_topic ==
nullptr) {
106 std::cerr <<
"Failed to create Topic" << std::endl;
109 efd::DataWriterQos wqos = efd::DATAWRITER_QOS_DEFAULT;
110 wqos.endpoint().history_memory_policy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
112 _impl->_datawriter =
_impl->_publisher->create_datawriter(
_impl->_topic, wqos, listener);
113 if (
_impl->_datawriter ==
nullptr) {
114 std::cerr <<
"Failed to create DataWriter" << std::endl;
124 std::cerr <<
"Invalid TypeSupport" << std::endl;
128 efd::DomainParticipantQos pqos = efd::PARTICIPANT_QOS_DEFAULT;
130 auto factory = efd::DomainParticipantFactory::get_instance();
131 _impl_info->_participant = factory->create_participant(0, pqos);
133 std::cerr <<
"Failed to create DomainParticipant" << std::endl;
138 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
141 std::cerr <<
"Failed to create Publisher" << std::endl;
145 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
146 const std::string publisher_type {
"/camera_info"};
147 const std::string base {
"rt/carla/" };
148 std::string topic_name = base;
152 topic_name += publisher_type;
155 std::cerr <<
"Failed to create Topic" << std::endl;
158 efd::DataWriterQos wqos = efd::DATAWRITER_QOS_DEFAULT;
162 std::cerr <<
"Failed to create DataWriter" << std::endl;
175 eprosima::fastrtps::rtps::InstanceHandle_t instance_handle;
176 eprosima::fastrtps::types::ReturnCode_t rcode =
_impl->_datawriter->write(&
_impl->_image, instance_handle);
177 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
180 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
181 std::cerr <<
"RETCODE_ERROR" << std::endl;
184 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
185 std::cerr <<
"RETCODE_UNSUPPORTED" << std::endl;
188 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
189 std::cerr <<
"RETCODE_BAD_PARAMETER" << std::endl;
192 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
193 std::cerr <<
"RETCODE_PRECONDITION_NOT_MET" << std::endl;
196 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
197 std::cerr <<
"RETCODE_OUT_OF_RESOURCES" << std::endl;
200 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
201 std::cerr <<
"RETCODE_NOT_ENABLED" << std::endl;
204 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
205 std::cerr <<
"RETCODE_IMMUTABLE_POLICY" << std::endl;
208 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
209 std::cerr <<
"RETCODE_INCONSISTENT_POLICY" << std::endl;
212 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
213 std::cerr <<
"RETCODE_ALREADY_DELETED" << std::endl;
216 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
217 std::cerr <<
"RETCODE_TIMEOUT" << std::endl;
220 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
221 std::cerr <<
"RETCODE_NO_DATA" << std::endl;
224 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
225 std::cerr <<
"RETCODE_ILLEGAL_OPERATION" << std::endl;
228 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
229 std::cerr <<
"RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
232 std::cerr <<
"UNKNOWN" << std::endl;
237 eprosima::fastrtps::rtps::InstanceHandle_t instance_handle;
239 eprosima::fastrtps::types::ReturnCode_t rcode =
_impl_info->_datawriter->write(&
_impl_info->_info, instance_handle);
240 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
243 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
244 std::cerr <<
"RETCODE_ERROR" << std::endl;
247 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
248 std::cerr <<
"RETCODE_UNSUPPORTED" << std::endl;
251 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
252 std::cerr <<
"RETCODE_BAD_PARAMETER" << std::endl;
255 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
256 std::cerr <<
"RETCODE_PRECONDITION_NOT_MET" << std::endl;
259 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
260 std::cerr <<
"RETCODE_OUT_OF_RESOURCES" << std::endl;
263 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
264 std::cerr <<
"RETCODE_NOT_ENABLED" << std::endl;
267 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
268 std::cerr <<
"RETCODE_IMMUTABLE_POLICY" << std::endl;
271 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
272 std::cerr <<
"RETCODE_INCONSISTENT_POLICY" << std::endl;
275 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
276 std::cerr <<
"RETCODE_ALREADY_DELETED" << std::endl;
279 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
280 std::cerr <<
"RETCODE_TIMEOUT" << std::endl;
283 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
284 std::cerr <<
"RETCODE_NO_DATA" << std::endl;
287 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
288 std::cerr <<
"RETCODE_ILLEGAL_OPERATION" << std::endl;
291 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
292 std::cerr <<
"RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
295 std::cerr <<
"UNKNOWN" << std::endl;
300 std::vector<uint8_t> vector_data;
301 const size_t size = height * width * 4;
302 vector_data.resize(size);
303 std::memcpy(&vector_data[0], &data[0], size);
304 SetImageData(seconds, nanoseconds, height, width, std::move(vector_data));
314 header.
stamp(std::move(time));
316 _impl->_image.header(header);
318 _impl->_image.width(width);
319 _impl->_image.height(height);
320 _impl->_image.encoding(
"bgra8");
321 _impl->_image.is_bigendian(0);
322 _impl->_image.step(
_impl->_image.width() *
sizeof(uint8_t) * 4);
323 _impl->_image.data(std::move(data));
332 header.
stamp(std::move(time));
358 if (
_impl->_datawriter)
359 _impl->_publisher->delete_datawriter(
_impl->_datawriter);
361 if (
_impl->_publisher)
362 _impl->_participant->delete_publisher(
_impl->_publisher);
365 _impl->_participant->delete_topic(
_impl->_topic);
367 if (
_impl->_participant)
368 efd::DomainParticipantFactory::get_instance()->delete_participant(
_impl->_participant);
383 efd::DomainParticipantFactory::get_instance()->delete_participant(
_impl_info->_participant);
406 _name = std::move(other._name);
407 _parent = std::move(other._parent);
408 _impl = std::move(other._impl);
414 _name = std::move(other._name);
415 _parent = std::move(other._parent);
416 _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
std::shared_ptr< CarlaCameraInfoPublisherImpl > _impl_info
std::shared_ptr< CarlaRGBCameraPublisherImpl > _impl
void SetImageData(int32_t seconds, uint32_t nanoseconds, uint32_t height, uint32_t width, const uint8_t *data)
void SetInfoRegionOfInterest(uint32_t x_offset, uint32_t y_offset, uint32_t height, uint32_t width, bool do_rectify)
~CarlaRGBCameraPublisher()
CarlaRGBCameraPublisher(const char *ros_name="", const char *parent="")
void InitInfoData(uint32_t x_offset, uint32_t y_offset, uint32_t height, uint32_t width, float fov, bool do_rectify)
CarlaRGBCameraPublisher & operator=(const CarlaRGBCameraPublisher &)
void SetCameraInfoData(int32_t seconds, uint32_t nanoseconds)
bool HasBeenInitialized() const
This class represents the TopicDataType of the type CameraInfo defined by the user in the IDL file.
This class represents the structure CameraInfo defined by the user in the IDL file.
This class represents the TopicDataType of the type Image defined by the user in the IDL file.
This class represents the structure Image defined by the user in the IDL file.
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
This file contains definitions of common data structures used in traffic manager.
sensor_msgs::msg::CameraInfo _info
efd::DomainParticipant * _participant
efd::DataWriter * _datawriter
efd::Publisher * _publisher
sensor_msgs::msg::Image _image
efd::DataWriter * _datawriter
efd::Publisher * _publisher
efd::DomainParticipant * _participant