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>
33 namespace efd = eprosima::fastdds::dds;
35 using erc = eprosima::fastrtps::types::ReturnCode_t;
78 if (
_impl->_type ==
nullptr) {
79 std::cerr <<
"Invalid TypeSupport" << std::endl;
86 efd::DomainParticipantQos pqos = efd::PARTICIPANT_QOS_DEFAULT;
88 auto factory = efd::DomainParticipantFactory::get_instance();
89 _impl->_participant = factory->create_participant(0, pqos);
93 if (
_impl->_participant ==
nullptr) {
94 std::cerr <<
"Failed to create DomainParticipant" << std::endl;
100 _impl->_type.register_type(
_impl->_participant);
104 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
105 _impl->_publisher =
_impl->_participant->create_publisher(pubqos,
nullptr);
109 if (
_impl->_publisher ==
nullptr) {
110 std::cerr <<
"Failed to create Publisher" << std::endl;
116 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
117 const std::string topic_name {
"rt/tf" };
118 _impl->_topic =
_impl->_participant->create_topic(topic_name,
_impl->_type->getName(), tqos);
122 if (
_impl->_topic ==
nullptr) {
123 std::cerr <<
"Failed to create Topic" << std::endl;
130 efd::DataWriterQos wqos = efd::DATAWRITER_QOS_DEFAULT;
131 wqos.endpoint().history_memory_policy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
133 _impl->_datawriter =
_impl->_publisher->create_datawriter(
_impl->_topic, wqos, listener);
137 if (
_impl->_datawriter ==
nullptr) {
138 std::cerr <<
"Failed to create DataWriter" << std::endl;
162 eprosima::fastrtps::rtps::InstanceHandle_t instance_handle;
163 eprosima::fastrtps::types::ReturnCode_t rcode =
_impl->_datawriter->write(&
_impl->_transform, instance_handle);
170 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
176 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
178 std::cerr <<
"RETCODE_ERROR" << std::endl;
181 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
183 std::cerr <<
"RETCODE_UNSUPPORTED" << std::endl;
186 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
188 std::cerr <<
"RETCODE_BAD_PARAMETER" << std::endl;
191 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) {
198 std::cerr <<
"RETCODE_OUT_OF_RESOURCES" << std::endl;
201 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
203 std::cerr <<
"RETCODE_NOT_ENABLED" << std::endl;
206 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
208 std::cerr <<
"RETCODE_IMMUTABLE_POLICY" << std::endl;
211 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
213 std::cerr <<
"RETCODE_INCONSISTENT_POLICY" << std::endl;
216 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
218 std::cerr <<
"RETCODE_ALREADY_DELETED" << std::endl;
221 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
223 std::cerr <<
"RETCODE_TIMEOUT" << std::endl;
226 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
228 std::cerr <<
"RETCODE_NO_DATA" << std::endl;
231 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
233 std::cerr <<
"RETCODE_ILLEGAL_OPERATION" << std::endl;
236 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
238 std::cerr <<
"RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
242 std::cerr <<
"UNKNOWN" << std::endl;
258 int same_translation = std::memcmp(translation,
_impl->last_translation,
sizeof(
float) * 3);
259 int same_rotation = std::memcmp(rotation,
_impl->last_rotation,
sizeof(
float) * 3);
261 if (same_translation != 0 || same_rotation != 0) {
262 std::memcpy(
_impl->last_translation, translation,
sizeof(
float) * 3);
263 std::memcpy(
_impl->last_rotation, rotation,
sizeof(
float) * 3);
265 const float tx = *translation++;
266 const float ty = *translation++;
267 const float tz = *translation++;
269 const float rx = ((*rotation++) * -1.0f) * (M_PIf32 / 180.0f);
270 const float ry = ((*rotation++) * -1.0f) * (M_PIf32 / 180.0f);
271 const float rz = *rotation++ * (M_PIf32 / 180.0f);
273 const float cr = cosf(rz * 0.5f);
274 const float sr = sinf(rz * 0.5f);
275 const float cp = cosf(rx * 0.5f);
276 const float sp = sinf(rx * 0.5f);
277 const float cy = cosf(ry * 0.5f);
278 const float sy = sinf(ry * 0.5f);
280 _impl->vec_translation.x(tx);
281 _impl->vec_translation.y(-ty);
282 _impl->vec_translation.z(tz);
284 _impl->vec_rotation.w(
cr * cp * cy + sr * sp * sy);
285 _impl->vec_rotation.x(sr * cp * cy -
cr * sp * sy);
286 _impl->vec_rotation.y(
cr * sp * cy + sr * cp * sy);
287 _impl->vec_rotation.z(
cr * cp * sy - sr * sp * cy);
294 std_msgs::msg::Header header;
295 header.stamp(std::move(time));
303 ts.
header(std::move(header));
307 _impl->_transform.transforms({ts});
331 if (
_impl->_datawriter)
332 _impl->_publisher->delete_datawriter(
_impl->_datawriter);
334 if (
_impl->_publisher)
335 _impl->_participant->delete_publisher(
_impl->_publisher);
338 _impl->_participant->delete_topic(
_impl->_topic);
340 if (
_impl->_participant)
341 efd::DomainParticipantFactory::get_instance()->delete_participant(
_impl->_participant);
383 _name = std::move(other._name);
384 _parent = std::move(other._parent);
385 _impl = std::move(other._impl);
397 _name = std::move(other._name);
398 _parent = std::move(other._parent);
399 _impl = std::move(other._impl);
eProsima_user_DllExport void nanosec(uint32_t _nanosec)
此函数设置成员nanosec的值。
eProsima_user_DllExport void sec(int32_t _sec)
此函数设置成员sec的值。
const std::string & parent() const
This class represents the structure Quaternion defined by the user in the IDL file.
此类表示用户在 IDL 文件中定义的 Vector3 结构。 <>
This class represents the TopicDataType of the type TFMessage defined by the user in the IDL file.
eprosima::fastrtps::types::ReturnCode_t erc
@using erc