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;
32 using erc = eprosima::fastrtps::types::ReturnCode_t;
49 if (
_impl->_type ==
nullptr) {
50 std::cerr <<
"Invalid TypeSupport" << std::endl;
54 efd::DomainParticipantQos pqos = efd::PARTICIPANT_QOS_DEFAULT;
57 auto factory = efd::DomainParticipantFactory::get_instance();
59 _impl->_participant = factory->create_participant(0, pqos);
60 if (
_impl->_participant ==
nullptr) {
61 std::cerr <<
"Failed to create DomainParticipant" << std::endl;
65 _impl->_type.register_type(
_impl->_participant);
67 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
69 _impl->_publisher =
_impl->_participant->create_publisher(pubqos,
nullptr);
70 if (
_impl->_publisher ==
nullptr) {
71 std::cerr <<
"Failed to create Publisher" << std::endl;
75 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
77 const std::string base {
"rt/carla/" };
78 std::string topic_name = base;
85 _impl->_topic =
_impl->_participant->create_topic(topic_name,
_impl->_type->getName(), tqos);
86 if (
_impl->_topic ==
nullptr) {
87 std::cerr <<
"Failed to create Topic" << std::endl;
91 efd::DataWriterQos wqos = efd::DATAWRITER_QOS_DEFAULT;
93 wqos.endpoint().history_memory_policy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
97 _impl->_datawriter =
_impl->_publisher->create_datawriter(
_impl->_topic, wqos, listener);
98 if (
_impl->_datawriter ==
nullptr) {
99 std::cerr <<
"Failed to create DataWriter" << std::endl;
109 eprosima::fastrtps::rtps::InstanceHandle_t instance_handle;
111 eprosima::fastrtps::types::ReturnCode_t rcode =
_impl->_datawriter->write(&
_impl->_nav, instance_handle);
113 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
117 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
118 std::cerr <<
"RETCODE_ERROR" << std::endl;
121 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
122 std::cerr <<
"RETCODE_UNSUPPORTED" << std::endl;
125 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
126 std::cerr <<
"RETCODE_BAD_PARAMETER" << std::endl;
129 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
130 std::cerr <<
"RETCODE_PRECONDITION_NOT_MET" << std::endl;
133 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
134 std::cerr <<
"RETCODE_OUT_OF_RESOURCES" << std::endl;
137 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
138 std::cerr <<
"RETCODE_NOT_ENABLED" << std::endl;
141 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
142 std::cerr <<
"RETCODE_IMMUTABLE_POLICY" << std::endl;
145 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
146 std::cerr <<
"RETCODE_INCONSISTENT_POLICY" << std::endl;
149 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
150 std::cerr <<
"RETCODE_ALREADY_DELETED" << std::endl;
153 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
154 std::cerr <<
"RETCODE_TIMEOUT" << std::endl;
157 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
158 std::cerr <<
"RETCODE_NO_DATA" << std::endl;
161 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
162 std::cerr <<
"RETCODE_ILLEGAL_OPERATION" << std::endl;
165 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
166 std::cerr <<
"RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
170 std::cerr <<
"UNKNOWN return code: " << rcode() << std::endl;
182 std_msgs::msg::Header header;
183 header.stamp(std::move(time));
186 _impl->_nav.header(std::move(header));
187 _impl->_nav.latitude(*data++);
188 _impl->_nav.longitude(*data++);
189 _impl->_nav.altitude(*data++);
203 if (
_impl->_datawriter)
204 _impl->_publisher->delete_datawriter(
_impl->_datawriter);
206 if (
_impl->_publisher)
207 _impl->_participant->delete_publisher(
_impl->_publisher);
210 _impl->_participant->delete_topic(
_impl->_topic);
212 if (
_impl->_participant)
213 efd::DomainParticipantFactory::get_instance()->delete_participant(
_impl->_participant);
234 _name = std::move(other._name);
235 _parent = std::move(other._parent);
236 _impl = std::move(other._impl);
241 _name = std::move(other._name);
242 _parent = std::move(other._parent);
243 _impl = std::move(other._impl);
eProsima_user_DllExport void nanosec(uint32_t _nanosec)
此函数设置成员nanosec的值。
eProsima_user_DllExport void sec(int32_t _sec)
此函数设置成员sec的值。
用于在ROS 2中发布CARLA的GNSS(全球导航卫星系统)数据的类。 继承自CarlaPublisher类,专门用于初始化、设置和发布GNSS数据。
bool Init()
初始化函数,用于设置ROS节点和发布者。
~CarlaGNSSPublisher()
析构函数,用于销毁CarlaGNSSPublisher对象。
void SetData(int32_t seconds, uint32_t nanoseconds, const double *data)
设置GNSS数据。
std::shared_ptr< CarlaGNSSPublisherImpl > _impl
指向CarlaGNSSPublisherImpl的智能指针,用于隐藏实现细节。
CarlaGNSSPublisher(const char *ros_name="", const char *parent="")
构造函数,用于创建CarlaGNSSPublisher对象。
CarlaGNSSPublisher & operator=(const CarlaGNSSPublisher &)
拷贝赋值运算符,用于将当前对象的状态复制到另一个同类型的对象中。
const std::string & parent() const
This class represents the TopicDataType of the type NavSatFix defined by the user in the IDL file.
This class represents the structure NavSatFix defined by the user in the IDL file.
eprosima::fastrtps::types::ReturnCode_t erc
@using erc
sensor_msgs::msg::NavSatFix _nav
efd::Publisher * _publisher
efd::DomainParticipant * _participant
efd::DataWriter * _datawriter