forked from Archive/PX4-Autopilot
microRTPS bridge: fix templates for ROS2 usage
This commit is contained in:
parent
3007b0876c
commit
88a7e3df09
|
@ -102,8 +102,12 @@ bool @(topic)_Publisher::init()
|
|||
@[else]@
|
||||
Wparam.topic.topicName = "@(topic)PubSubTopic";
|
||||
@[end if]@
|
||||
@[if ros2_distro and ros2_distro != "ardent"]@
|
||||
@[if ros2_distro]@
|
||||
@[ if ros2_distro == "ardent"]@
|
||||
Wparam.qos.m_partition.push_back("rt");
|
||||
@[ else]@
|
||||
Wparam.topic.topicName = "rt/" + Wparam.topic.topicName;
|
||||
@[ end if]@
|
||||
@[end if]@
|
||||
mp_publisher = Domain::createPublisher(mp_participant, Wparam, static_cast<PublisherListener*>(&m_listener));
|
||||
if(mp_publisher == nullptr)
|
||||
|
@ -139,9 +143,17 @@ void @(topic)_Publisher::run()
|
|||
|
||||
// Publication code
|
||||
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
|
||||
@[ if ros2_distro]@
|
||||
@(package)::msg::dds_::@(topic)_ st;
|
||||
@[ else]@
|
||||
@(topic)_ st;
|
||||
@[ end if]@
|
||||
@[else]@
|
||||
@[ if ros2_distro]@
|
||||
@(package)::msg::@(topic) st;
|
||||
@[ else]@
|
||||
@(topic) st;
|
||||
@[ end if]@
|
||||
@[end if]@
|
||||
|
||||
/* Initialize your structure here */
|
||||
|
@ -168,10 +180,18 @@ void @(topic)_Publisher::run()
|
|||
}
|
||||
|
||||
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
|
||||
@[ if ros2_distro]@
|
||||
void @(topic)_Publisher::publish(@(package)::msg::dds_::@(topic)_* st)
|
||||
@[ else]@
|
||||
void @(topic)_Publisher::publish(@(topic)_* st)
|
||||
@[ end if]@
|
||||
@[else]@
|
||||
@[ if ros2_distro]@
|
||||
void @(topic)_Publisher::publish(@(package)::msg::@(topic)* st)
|
||||
@[ else]@
|
||||
void @(topic)_Publisher::publish(@(topic)* st)
|
||||
@[ end if]@
|
||||
@[end if]@
|
||||
{
|
||||
mp_publisher->write(st);
|
||||
}
|
||||
|
|
|
@ -81,10 +81,18 @@ public:
|
|||
bool init();
|
||||
void run();
|
||||
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
|
||||
@[ if ros2_distro]@
|
||||
void publish(@(package)::msg::dds_::@(topic)_* st);
|
||||
@[ else]@
|
||||
void publish(@(topic)_* st);
|
||||
@[ end if]@
|
||||
@[else]@
|
||||
@[ if ros2_distro]@
|
||||
void publish(@(package)::msg::@(topic)* st);
|
||||
@[ else]@
|
||||
void publish(@(topic)* st);
|
||||
@[ end if]@
|
||||
@[end if]@
|
||||
private:
|
||||
Participant *mp_participant;
|
||||
Publisher *mp_publisher;
|
||||
|
@ -98,10 +106,18 @@ private:
|
|||
int n_matched;
|
||||
} m_listener;
|
||||
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
|
||||
@[ if ros2_distro]@
|
||||
@(package)::msg::dds_::@(topic)_PubSubType myType;
|
||||
@[ else]@
|
||||
@(topic)_PubSubType myType;
|
||||
@[ end if]@
|
||||
@[else]@
|
||||
@[ if ros2_distro]@
|
||||
@(package)::msg::@(topic)PubSubType myType;
|
||||
@[ else]@
|
||||
@(topic)PubSubType myType;
|
||||
@[ end if]@
|
||||
@[end if]@
|
||||
};
|
||||
|
||||
#endif // _@(topic)__PUBLISHER_H_
|
||||
|
|
|
@ -93,9 +93,17 @@ void RtpsTopics::publish(uint8_t topic_ID, char data_buffer[], size_t len)
|
|||
case @(rtps_message_id(ids, topic)): // @(topic)
|
||||
{
|
||||
@[ if 1.5 <= fastrtpsgen_version[0] <= 1.7]@
|
||||
@[ if ros2_distro[0]]@
|
||||
@(package[0])::msg::dds_::@(topic)_ st;
|
||||
@[ else]@
|
||||
@(topic)_ st;
|
||||
@[ end if]@
|
||||
@[ else]@
|
||||
@[ if ros2_distro[0]]@
|
||||
@(package[0])::msg::@(topic) st;
|
||||
@[ else]@
|
||||
@(topic) st;
|
||||
@[ end if]@
|
||||
@[ end if]@
|
||||
eprosima::fastcdr::FastBuffer cdrbuffer(data_buffer, len);
|
||||
eprosima::fastcdr::Cdr cdr_des(cdrbuffer);
|
||||
|
@ -150,9 +158,17 @@ bool RtpsTopics::getMsg(const uint8_t topic_ID, eprosima::fastcdr::Cdr &scdr)
|
|||
if (_@(topic)_sub.hasMsg())
|
||||
{
|
||||
@[ if 1.5 <= fastrtpsgen_version[0] <= 1.7]@
|
||||
@[ if ros2_distro[0]]@
|
||||
@(package[0])::msg::dds_::@(topic)_ msg = _@(topic)_sub.getMsg();
|
||||
@[ else]@
|
||||
@(topic)_ msg = _@(topic)_sub.getMsg();
|
||||
@[ end if]@
|
||||
@[ else]@
|
||||
@[ if ros2_distro[0]]@
|
||||
@(package[0])::msg::@(topic) msg = _@(topic)_sub.getMsg();
|
||||
@[ else]@
|
||||
@(topic) msg = _@(topic)_sub.getMsg();
|
||||
@[ end if]@
|
||||
@[ end if]@
|
||||
msg.serialize(scdr);
|
||||
ret = true;
|
||||
|
|
|
@ -97,8 +97,12 @@ bool @(topic)_Subscriber::init()
|
|||
@[else]@
|
||||
Rparam.topic.topicName = "@(topic)PubSubTopic";
|
||||
@[end if]@
|
||||
@[if ros2_distro and ros2_distro != "ardent"]@
|
||||
Rparam.topic.topicName = "rt/" + Wparam.topic.topicName;
|
||||
@[if ros2_distro]@
|
||||
@[ if ros2_distro == "ardent"]@
|
||||
Rparam.qos.m_partition.push_back("rt");
|
||||
@[ else]@
|
||||
Rparam.topic.topicName = "rt/" + Rparam.topic.topicName;
|
||||
@[ end if]@
|
||||
@[end if]@
|
||||
mp_subscriber = Domain::createSubscriber(mp_participant, Rparam, static_cast<SubscriberListener*>(&m_listener));
|
||||
if(mp_subscriber == nullptr)
|
||||
|
@ -126,9 +130,17 @@ void @(topic)_Subscriber::SubListener::onNewDataMessage(Subscriber* sub)
|
|||
{
|
||||
// Take data
|
||||
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
|
||||
@[ if ros2_distro]@
|
||||
@(package)::msg::dds_::@(topic)_ st;
|
||||
@[ else]@
|
||||
@(topic)_ st;
|
||||
@[ end if]@
|
||||
@[else]@
|
||||
@[ if ros2_distro]@
|
||||
@(package)::msg::@(topic) st;
|
||||
@[ else]@
|
||||
@(topic) st;
|
||||
@[ end if]@
|
||||
@[end if]@
|
||||
|
||||
if(sub->takeNextData(&st, &m_info))
|
||||
|
@ -157,10 +169,18 @@ bool @(topic)_Subscriber::hasMsg()
|
|||
}
|
||||
|
||||
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
|
||||
@[ if ros2_distro]@
|
||||
@(package)::msg::dds_::@(topic)_ @(topic)_Subscriber::getMsg()
|
||||
@[ else]@
|
||||
@(topic)_ @(topic)_Subscriber::getMsg()
|
||||
@[ end if]@
|
||||
@[else]@
|
||||
@[ if ros2_distro]@
|
||||
@(package)::msg::@(topic) @(topic)_Subscriber::getMsg()
|
||||
@[ else]@
|
||||
@(topic) @(topic)_Subscriber::getMsg()
|
||||
@[ end if]@
|
||||
@[end if]@
|
||||
{
|
||||
m_listener.has_msg = false;
|
||||
return m_listener.msg;
|
||||
|
|
|
@ -82,10 +82,18 @@ public:
|
|||
void run();
|
||||
bool hasMsg();
|
||||
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
|
||||
@[ if ros2_distro]@
|
||||
@(package)::msg::dds_::@(topic)_ getMsg();
|
||||
@[ else]@
|
||||
@(topic)_ getMsg();
|
||||
@[ end if]@
|
||||
@[else]@
|
||||
@[ if ros2_distro]@
|
||||
@(package)::msg::@(topic) getMsg();
|
||||
@[ else]@
|
||||
@(topic) getMsg();
|
||||
@[ end if]@
|
||||
@[end if]@
|
||||
private:
|
||||
Participant *mp_participant;
|
||||
Subscriber *mp_subscriber;
|
||||
|
@ -101,18 +109,34 @@ private:
|
|||
int n_matched;
|
||||
int n_msg;
|
||||
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
|
||||
@[ if ros2_distro]@
|
||||
@(package)::msg::dds_::@(topic)_ msg;
|
||||
@[ else]@
|
||||
@(topic)_ msg;
|
||||
@[ end if]@
|
||||
@[else]@
|
||||
@[ if ros2_distro]@
|
||||
@(package)::msg::@(topic) msg;
|
||||
@[ else]@
|
||||
@(topic) msg;
|
||||
@[ end if]@
|
||||
@[end if]@
|
||||
bool has_msg = false;
|
||||
|
||||
} m_listener;
|
||||
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
|
||||
@[ if ros2_distro]@
|
||||
@(package)::msg::dds_::@(topic)_PubSubType myType;
|
||||
@[ else]@
|
||||
@(topic)_PubSubType myType;
|
||||
@[ end if]@
|
||||
@[else]@
|
||||
@[ if ros2_distro]@
|
||||
@(package)::msg::@(topic)PubSubType myType;
|
||||
@[ else]@
|
||||
@(topic)PubSubType myType;
|
||||
@[ end if]@
|
||||
@[end if]@
|
||||
};
|
||||
|
||||
#endif // _@(topic)__SUBSCRIBER_H_
|
||||
|
|
Loading…
Reference in New Issue