1 #define _GLIBCXX_USE_CXX11_ABI 0 9 #include <fastdds/dds/domain/DomainParticipant.hpp> 10 #include <fastdds/dds/subscriber/Subscriber.hpp> 11 #include <fastdds/dds/topic/Topic.hpp> 12 #include <fastdds/dds/subscriber/DataReader.hpp> 13 #include <fastdds/dds/topic/TypeSupport.hpp> 14 #include <fastdds/dds/subscriber/SampleInfo.hpp> 16 #include <fastdds/dds/domain/qos/DomainParticipantQos.hpp> 17 #include <fastdds/dds/domain/DomainParticipantFactory.hpp> 18 #include <fastdds/dds/subscriber/qos/SubscriberQos.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/subscriber/qos/DataReaderQos.hpp> 24 #include <fastdds/dds/subscriber/DataReaderListener.hpp> 30 namespace efd = eprosima::fastdds::dds;
31 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::SubscriberQos subqos = efd::SUBSCRIBER_QOS_DEFAULT;
64 _impl->_subscriber = _impl->_participant->create_subscriber(subqos,
nullptr);
65 if (_impl->_subscriber ==
nullptr) {
66 std::cerr <<
"Failed to create Subscriber" << std::endl;
70 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
71 const std::string base {
"rt/carla/" };
72 const std::string publisher_type {
"/vehicle_control_cmd"};
73 std::string topic_name = base;
75 topic_name += _parent +
"/";
77 topic_name += publisher_type;
78 _impl->_topic = _impl->_participant->create_topic(topic_name, _impl->_type->getName(), tqos);
79 if (_impl->_topic ==
nullptr) {
80 std::cerr <<
"Failed to create Topic" << std::endl;
84 efd::DataReaderQos rqos = efd::DATAREADER_QOS_DEFAULT;
85 efd::DataReaderListener* listener = (efd::DataReaderListener*)_impl->_listener._impl.get();
86 _impl->_datareader = _impl->_subscriber->create_datareader(_impl->_topic, rqos, listener);
87 if (_impl->_datareader ==
nullptr) {
88 std::cerr <<
"Failed to create DataReader" << std::endl;
96 eprosima::fastrtps::types::ReturnCode_t rcode = _impl->_datareader->take_next_sample(&_impl->_event, &info);
97 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
100 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
101 std::cerr <<
"RETCODE_ERROR" << std::endl;
104 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
105 std::cerr <<
"RETCODE_UNSUPPORTED" << std::endl;
108 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
109 std::cerr <<
"RETCODE_BAD_PARAMETER" << std::endl;
112 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
113 std::cerr <<
"RETCODE_PRECONDITION_NOT_MET" << std::endl;
116 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
117 std::cerr <<
"RETCODE_OUT_OF_RESOURCES" << std::endl;
120 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
121 std::cerr <<
"RETCODE_NOT_ENABLED" << std::endl;
124 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
125 std::cerr <<
"RETCODE_IMMUTABLE_POLICY" << std::endl;
128 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
129 std::cerr <<
"RETCODE_INCONSISTENT_POLICY" << std::endl;
132 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
133 std::cerr <<
"RETCODE_ALREADY_DELETED" << std::endl;
136 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
137 std::cerr <<
"RETCODE_TIMEOUT" << std::endl;
140 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
141 std::cerr <<
"RETCODE_NO_DATA" << std::endl;
144 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
145 std::cerr <<
"RETCODE_ILLEGAL_OPERATION" << std::endl;
148 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
149 std::cerr <<
"RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
152 std::cerr <<
"UNKNOWN" << std::endl;
157 _impl->_control = control;
158 _impl->_new_message =
true;
162 _impl->_alive =
false;
166 _impl->_new_message =
false;
167 return _impl->_control;
171 return _impl->_alive;
175 return _impl->_new_message;
179 return _impl->_vehicle;
184 _impl->_listener.SetOwner(
this);
185 _impl->_vehicle = vehicle;
194 if (
_impl->_datareader)
195 _impl->_subscriber->delete_datareader(
_impl->_datareader);
197 if (
_impl->_subscriber)
198 _impl->_participant->delete_subscriber(
_impl->_subscriber);
201 _impl->_participant->delete_topic(
_impl->_topic);
203 if (
_impl->_participant)
204 efd::DomainParticipantFactory::get_instance()->delete_participant(
_impl->_participant);
212 _impl->_listener.SetOwner(
this);
220 _impl->_listener.SetOwner(
this);
227 _name = std::move(other._name);
228 _parent = std::move(other._parent);
229 _impl = std::move(other._impl);
230 _impl->_listener.SetOwner(
this);
235 _name = std::move(other._name);
236 _parent = std::move(other._parent);
237 _impl = std::move(other._impl);
238 _impl->_listener.SetOwner(
this);
VehicleControl GetMessage()
efd::DomainParticipant * _participant
eprosima::fastrtps::types::ReturnCode_t erc
CarlaEgoVehicleControlSubscriber & operator=(const CarlaEgoVehicleControlSubscriber &)
carla_msgs::msg::CarlaEgoVehicleControl _event
This file contains definitions of common data structures used in traffic manager. ...
efd::Subscriber * _subscriber
std::shared_ptr< CarlaEgoVehicleControlSubscriberImpl > _impl
This class represents the structure CarlaEgoVehicleControl defined by the user in the IDL file...
This class represents the TopicDataType of the type CarlaEgoVehicleControl defined by the user in the...
const std::string & parent() const
CarlaSubscriberListener _listener
void ForwardMessage(VehicleControl control)
efd::DataReader * _datareader
CarlaEgoVehicleControlSubscriber(void *vehicle, const char *ros_name="", const char *parent="")
~CarlaEgoVehicleControlSubscriber()