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> 30 namespace efd = eprosima::fastdds::dds;
31 using erc = eprosima::fastrtps::types::ReturnCode_t;
44 if (_impl->_type ==
nullptr) {
45 std::cerr <<
"Invalid TypeSupport" << std::endl;
49 efd::DomainParticipantQos pqos = efd::PARTICIPANT_QOS_DEFAULT;
51 auto factory = efd::DomainParticipantFactory::get_instance();
52 _impl->_participant = factory->create_participant(0, pqos);
53 if (_impl->_participant ==
nullptr) {
54 std::cerr <<
"Failed to create DomainParticipant" << std::endl;
57 _impl->_type.register_type(_impl->_participant);
59 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
60 _impl->_publisher = _impl->_participant->create_publisher(pubqos,
nullptr);
61 if (_impl->_publisher ==
nullptr) {
62 std::cerr <<
"Failed to create Publisher" << std::endl;
66 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
67 const std::string base {
"rt/carla/" };
68 std::string topic_name = base;
70 topic_name += _parent +
"/";
72 _impl->_topic = _impl->_participant->create_topic(topic_name, _impl->_type->getName(), tqos);
73 if (_impl->_topic ==
nullptr) {
74 std::cerr <<
"Failed to create Topic" << std::endl;
78 efd::DataWriterQos wqos = efd::DATAWRITER_QOS_DEFAULT;
79 wqos.endpoint().history_memory_policy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
80 efd::DataWriterListener* listener = (efd::DataWriterListener*)_impl->_listener._impl.get();
81 _impl->_datawriter = _impl->_publisher->create_datawriter(_impl->_topic, wqos, listener);
82 if (_impl->_datawriter ==
nullptr) {
83 std::cerr <<
"Failed to create DataWriter" << std::endl;
93 eprosima::fastrtps::types::ReturnCode_t rcode = _impl->_datawriter->write(&_impl->_event, instance_handle);
94 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
97 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
98 std::cerr <<
"RETCODE_ERROR" << std::endl;
101 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
102 std::cerr <<
"RETCODE_UNSUPPORTED" << std::endl;
105 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
106 std::cerr <<
"RETCODE_BAD_PARAMETER" << std::endl;
109 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
110 std::cerr <<
"RETCODE_PRECONDITION_NOT_MET" << std::endl;
113 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
114 std::cerr <<
"RETCODE_OUT_OF_RESOURCES" << std::endl;
117 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
118 std::cerr <<
"RETCODE_NOT_ENABLED" << std::endl;
121 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
122 std::cerr <<
"RETCODE_IMMUTABLE_POLICY" << std::endl;
125 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
126 std::cerr <<
"RETCODE_INCONSISTENT_POLICY" << std::endl;
129 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
130 std::cerr <<
"RETCODE_ALREADY_DELETED" << std::endl;
133 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
134 std::cerr <<
"RETCODE_TIMEOUT" << std::endl;
137 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
138 std::cerr <<
"RETCODE_NO_DATA" << std::endl;
141 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
142 std::cerr <<
"RETCODE_ILLEGAL_OPERATION" << std::endl;
145 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
146 std::cerr <<
"RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
149 std::cerr <<
"UNKNOWN" << std::endl;
154 std::vector<float> vector_data ;
155 SetData(seconds, nanoseconds, actor_id, {x, y, z});
164 header.
stamp(std::move(time));
171 _impl->_event.header(std::move(header));
172 _impl->_event.other_actor_id(actor_id);
173 _impl->_event.normal_impulse(impulse);
186 if (
_impl->_datawriter)
187 _impl->_publisher->delete_datawriter(
_impl->_datawriter);
189 if (
_impl->_publisher)
190 _impl->_participant->delete_publisher(
_impl->_publisher);
193 _impl->_participant->delete_topic(
_impl->_topic);
195 if (
_impl->_participant)
196 efd::DomainParticipantFactory::get_instance()->delete_participant(
_impl->_participant);
217 _name = std::move(other._name);
218 _parent = std::move(other._parent);
219 _impl = std::move(other._impl);
224 _name = std::move(other._name);
225 _parent = std::move(other._parent);
226 _impl = std::move(other._impl);
efd::DomainParticipant * _participant
eProsima_user_DllExport void y(double _y)
This function sets a value in member y.
carla_msgs::msg::CarlaCollisionEvent _event
eprosima::fastrtps::rtps::InstanceHandle_t InstanceHandle_t
eprosima::fastrtps::types::ReturnCode_t erc
~CarlaCollisionPublisher()
This file contains definitions of common data structures used in traffic manager. ...
eProsima_user_DllExport void z(double _z)
This function sets a value in member z.
This class represents the TopicDataType of the type CarlaCollisionEvent defined by the user in the ID...
This class represents the structure Vector3 defined by the user in the IDL file.
efd::Publisher * _publisher
efd::DataWriter * _datawriter
This class represents the structure CarlaCollisionEvent defined by the user in the IDL file...
eProsima_user_DllExport void sec(int32_t _sec)
This function sets a value in member sec.
eProsima_user_DllExport void nanosec(uint32_t _nanosec)
This function sets a value in member nanosec.
eProsima_user_DllExport void x(double _x)
This function sets a value in member x.
CarlaCollisionPublisher & operator=(const CarlaCollisionPublisher &)
const std::string & parent() const
This class represents the structure Time defined by the user in the IDL file.
std::shared_ptr< CarlaCollisionPublisherImpl > _impl
void SetData(int32_t seconds, uint32_t nanoseconds, uint32_t actor_id, float x, float y, float z)
CarlaCollisionPublisher(const char *ros_name="", const char *parent="")