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>
24#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
25#include <fastdds/dds/publisher/DataWriterListener.hpp>
39 namespace efd = eprosima::fastdds::dds;
40 using erc = eprosima::fastrtps::types::ReturnCode_t;
82 carla_msgs::msg::CarlaCollisionEvent
_event {};
95 if (
_impl->_type ==
nullptr) {
96 std::cerr <<
"Invalid TypeSupport" << std::endl;
103 efd::DomainParticipantQos pqos = efd::PARTICIPANT_QOS_DEFAULT;
109 auto factory = efd::DomainParticipantFactory::get_instance();
110 _impl->_participant = factory->create_participant(0, pqos);
111 if (
_impl->_participant ==
nullptr) {
112 std::cerr <<
"Failed to create DomainParticipant" << std::endl;
119 _impl->_type.register_type(
_impl->_participant);
124 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
129 _impl->_publisher =
_impl->_participant->create_publisher(pubqos,
nullptr);
130 if (
_impl->_publisher ==
nullptr) {
131 std::cerr <<
"Failed to create Publisher" << std::endl;
138 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
143 const std::string base {
"rt/carla/" };
144 std::string topic_name = base;
152 _impl->_topic =
_impl->_participant->create_topic(topic_name,
_impl->_type->getName(), tqos);
153 if (
_impl->_topic ==
nullptr) {
154 std::cerr <<
"Failed to create Topic" << std::endl;
161 efd::DataWriterQos wqos = efd::DATAWRITER_QOS_DEFAULT;
162 wqos.endpoint().history_memory_policy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
168 _impl->_datawriter =
_impl->_publisher->create_datawriter(
_impl->_topic, wqos, listener);
169 if (
_impl->_datawriter ==
nullptr) {
170 std::cerr <<
"Failed to create DataWriter" << std::endl;
194 eprosima::fastrtps::rtps::InstanceHandle_t instance_handle;
196 eprosima::fastrtps::types::ReturnCode_t rcode =
_impl->_datawriter->write(&
_impl->_event, instance_handle);
198 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
203 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
204 std::cerr <<
"RETCODE_ERROR" << std::endl;
207 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
208 std::cerr <<
"RETCODE_UNSUPPORTED" << std::endl;
211 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
212 std::cerr <<
"RETCODE_BAD_PARAMETER" << std::endl;
215 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
216 std::cerr <<
"RETCODE_PRECONDITION_NOT_MET" << std::endl;
219 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
220 std::cerr <<
"RETCODE_OUT_OF_RESOURCES" << std::endl;
223 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
224 std::cerr <<
"RETCODE_NOT_ENABLED" << std::endl;
227 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
228 std::cerr <<
"RETCODE_IMMUTABLE_POLICY" << std::endl;
231 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
232 std::cerr <<
"RETCODE_INCONSISTENT_POLICY" << std::endl;
235 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
236 std::cerr <<
"RETCODE_ALREADY_DELETED" << std::endl;
239 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
240 std::cerr <<
"RETCODE_TIMEOUT" << std::endl;
243 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
244 std::cerr <<
"RETCODE_NO_DATA" << std::endl;
247 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
248 std::cerr <<
"RETCODE_ILLEGAL_OPERATION" << std::endl;
251 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
252 std::cerr <<
"RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
256 std::cerr <<
"UNKNOWN" << std::endl;
273 std::vector<float> vector_data ;
274 SetData(seconds, nanoseconds, actor_id, {x, y, z});
292 std_msgs::msg::Header header;
293 header.stamp(std::move(time));
300 _impl->_event.header(std::move(header));
301 _impl->_event.other_actor_id(actor_id);
302 _impl->_event.normal_impulse(impulse);
326 if (
_impl->_datawriter)
327 _impl->_publisher->delete_datawriter(
_impl->_datawriter);
329 if (
_impl->_publisher)
330 _impl->_participant->delete_publisher(
_impl->_publisher);
333 _impl->_participant->delete_topic(
_impl->_topic);
335 if (
_impl->_participant)
336 efd::DomainParticipantFactory::get_instance()->delete_participant(
_impl->_participant);
376 _name = std::move(other._name);
377 _parent = std::move(other._parent);
378 _impl = std::move(other._impl);
390 _name = std::move(other._name);
391 _parent = std::move(other._parent);
392 _impl = std::move(other._impl);
eProsima_user_DllExport void nanosec(uint32_t _nanosec)
此函数设置成员nanosec的值。
eProsima_user_DllExport void sec(int32_t _sec)
此函数设置成员sec的值。
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="")
构造函数,初始化CarlaCollisionPublisher。
CarlaCollisionPublisher & operator=(const CarlaCollisionPublisher &)
赋值运算符。
~CarlaCollisionPublisher()
析构函数,清理资源并释放内部实现。
const std::string & parent() const
此类代表了用户在 IDL 文件中定义的 CarlaCollisionEvent 类型的主题数据类型(TopicDataType)。
此类表示用户在 IDL 文件中定义的 Vector3 结构。 <>
eProsima_user_DllExport void x(double _x)
设置成员 x 的值
eProsima_user_DllExport void z(double _z)
设置成员 z 的值
eProsima_user_DllExport void y(double _y)
设置成员 y 的值
eprosima::fastrtps::types::ReturnCode_t erc
@using erc
CarlaCollisionPublisher的内部实现结构体
efd::TypeSupport _type
DDS类型支持
carla_msgs::msg::CarlaCollisionEvent _event
CARLA碰撞事件消息
efd::DataWriter * _datawriter
DDS数据写入器指针
CarlaListener _listener
Carla监听器
efd::Topic * _topic
DDS主题指针
efd::Publisher * _publisher
DDS发布者指针
efd::DomainParticipant * _participant
DDS域参与者指针