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> 29 namespace efd = eprosima::fastdds::dds;
30 using erc = eprosima::fastrtps::types::ReturnCode_t;
48 if (_impl->_type ==
nullptr) {
49 std::cerr <<
"Invalid TypeSupport" << std::endl;
53 efd::DomainParticipantQos pqos = efd::PARTICIPANT_QOS_DEFAULT;
55 auto factory = efd::DomainParticipantFactory::get_instance();
56 _impl->_participant = factory->create_participant(0, pqos);
57 if (_impl->_participant ==
nullptr) {
58 std::cerr <<
"Failed to create DomainParticipant" << std::endl;
61 _impl->_type.register_type(_impl->_participant);
63 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
64 _impl->_publisher = _impl->_participant->create_publisher(pubqos,
nullptr);
65 if (_impl->_publisher ==
nullptr) {
66 std::cerr <<
"Failed to create Publisher" << std::endl;
70 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
71 const std::string topic_name {
"rt/tf" };
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;
92 eprosima::fastrtps::types::ReturnCode_t rcode = _impl->_datawriter->write(&_impl->_transform, instance_handle);
93 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
96 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
97 std::cerr <<
"RETCODE_ERROR" << std::endl;
100 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
101 std::cerr <<
"RETCODE_UNSUPPORTED" << std::endl;
104 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
105 std::cerr <<
"RETCODE_BAD_PARAMETER" << std::endl;
108 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
109 std::cerr <<
"RETCODE_PRECONDITION_NOT_MET" << std::endl;
112 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
113 std::cerr <<
"RETCODE_OUT_OF_RESOURCES" << std::endl;
116 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
117 std::cerr <<
"RETCODE_NOT_ENABLED" << std::endl;
120 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
121 std::cerr <<
"RETCODE_IMMUTABLE_POLICY" << std::endl;
124 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
125 std::cerr <<
"RETCODE_INCONSISTENT_POLICY" << std::endl;
128 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
129 std::cerr <<
"RETCODE_ALREADY_DELETED" << std::endl;
132 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
133 std::cerr <<
"RETCODE_TIMEOUT" << std::endl;
136 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
137 std::cerr <<
"RETCODE_NO_DATA" << std::endl;
140 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
141 std::cerr <<
"RETCODE_ILLEGAL_OPERATION" << std::endl;
144 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
145 std::cerr <<
"RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
148 std::cerr <<
"UNKNOWN" << std::endl;
154 int same_translation = std::memcmp(translation, _impl->last_translation,
sizeof(
float) * 3);
155 int same_rotation = std::memcmp(rotation, _impl->last_rotation,
sizeof(
float) * 3);
156 if (same_translation != 0 || same_rotation != 0) {
157 std::memcpy(_impl->last_translation, translation,
sizeof(
float) * 3);
158 std::memcpy(_impl->last_rotation, rotation,
sizeof(
float) * 3);
160 const float tx = *translation++;
161 const float ty = *translation++;
162 const float tz = *translation++;
164 const float rx = ((*rotation++) * -1.0f) * (M_PIf32 / 180.0f);
165 const float ry = ((*rotation++) * -1.0f) * (M_PIf32 / 180.0f);
166 const float rz = *rotation++ * (M_PIf32 / 180.0f);
168 const float cr = cosf(rz * 0.5f);
169 const float sr = sinf(rz * 0.5f);
170 const float cp = cosf(rx * 0.5f);
171 const float sp = sinf(rx * 0.5f);
172 const float cy = cosf(ry * 0.5f);
173 const float sy = sinf(ry * 0.5f);
175 _impl->vec_translation.x(tx);
176 _impl->vec_translation.y(-ty);
177 _impl->vec_translation.z(tz);
179 _impl->vec_rotation.w(cr * cp * cy + sr * sp * sy);
180 _impl->vec_rotation.x(sr * cp * cy - cr * sp * sy);
181 _impl->vec_rotation.y(cr * sp * cy + sr * cp * sy);
182 _impl->vec_rotation.z(cr * cp * sy - sr * sp * cy);
190 header.
stamp(std::move(time));
198 ts.
header(std::move(header));
201 _impl->_transform.transforms({ts});
214 if (
_impl->_datawriter)
215 _impl->_publisher->delete_datawriter(
_impl->_datawriter);
217 if (
_impl->_publisher)
218 _impl->_participant->delete_publisher(
_impl->_publisher);
221 _impl->_participant->delete_topic(
_impl->_topic);
223 if (
_impl->_participant)
224 efd::DomainParticipantFactory::get_instance()->delete_participant(
_impl->_participant);
245 _name = std::move(other._name);
246 _parent = std::move(other._parent);
247 _impl = std::move(other._impl);
252 _name = std::move(other._name);
253 _parent = std::move(other._parent);
254 _impl = std::move(other._impl);
eprosima::fastrtps::rtps::InstanceHandle_t InstanceHandle_t
eprosima::fastrtps::types::ReturnCode_t erc
This file contains definitions of common data structures used in traffic manager. ...
This class represents the structure Vector3 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.
const std::string & parent() const
This class represents the structure Time defined by the user in the IDL file.
This class represents the TopicDataType of the type TFMessage defined by the user in the IDL file...
This class represents the structure TFMessage defined by the user in the IDL file.
This class represents the structure Quaternion defined by the user in the IDL file.