microRTPS bridge: fix templates for ROS2 usage

This commit is contained in:
TSC21 2019-10-14 14:59:42 +01:00 committed by Nuno Marques
parent 3007b0876c
commit 88a7e3df09
5 changed files with 101 additions and 5 deletions

View File

@ -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,9 +180,17 @@ void @(topic)_Publisher::run()
}
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
void @(topic)_Publisher::publish(@(topic)_* st)
@[ if ros2_distro]@
void @(topic)_Publisher::publish(@(package)::msg::dds_::@(topic)_* st)
@[ else]@
void @(topic)_Publisher::publish(@(topic)_* st)
@[ end if]@
@[else]@
void @(topic)_Publisher::publish(@(topic)* st)
@[ 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);

View File

@ -81,9 +81,17 @@ 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;
@ -98,9 +106,17 @@ 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]@
};

View File

@ -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;

View File

@ -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,9 +169,17 @@ 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;

View File

@ -82,9 +82,17 @@ 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;
@ -101,17 +109,33 @@ 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]@
};