mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 06:03:33 +08:00
first push on supporting ROS2 Dashing and IDL 4.2
This commit is contained in:
@@ -125,7 +125,11 @@ void @(topic)_Publisher::run()
|
||||
|
||||
// Publication code
|
||||
|
||||
@[if (ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal") and float(fastrtps_version) < 1.9]@
|
||||
@(topic)_ st;
|
||||
@[else]@
|
||||
@(topic) st;
|
||||
@[end if]@
|
||||
|
||||
/* Initialize your structure here */
|
||||
|
||||
@@ -150,7 +154,11 @@ void @(topic)_Publisher::run()
|
||||
}while(std::cin >> ch);
|
||||
}
|
||||
|
||||
@[if (ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal") and float(fastrtps_version) < 1.9]@
|
||||
void @(topic)_Publisher::publish(@(topic)_* st)
|
||||
@[else]@
|
||||
void @(topic)_Publisher::publish(@(topic)* st)
|
||||
@[end if]@
|
||||
{
|
||||
mp_publisher->write(st);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,11 @@ topic = alias if alias else spec.short_name
|
||||
#include <fastrtps/fastrtps_fwd.h>
|
||||
#include <fastrtps/publisher/PublisherListener.h>
|
||||
|
||||
@[if float(fastrtps_version) < 1.9]@
|
||||
#include "@(topic)_PubSubTypes.h"
|
||||
@[else]@
|
||||
#include "@(topic)PubSubTypes.h"
|
||||
@[end if]@
|
||||
|
||||
using namespace eprosima::fastrtps;
|
||||
using namespace eprosima::fastrtps::rtps;
|
||||
@@ -76,7 +80,11 @@ public:
|
||||
virtual ~@(topic)_Publisher();
|
||||
bool init();
|
||||
void run();
|
||||
@[if (ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal") and float(fastrtps_version) < 1.9]@
|
||||
void publish(@(topic)_* st);
|
||||
@[else]@
|
||||
void publish(@(topic)* st);
|
||||
@[end if]@
|
||||
private:
|
||||
Participant *mp_participant;
|
||||
Publisher *mp_publisher;
|
||||
@@ -89,7 +97,11 @@ private:
|
||||
void onPublicationMatched(Publisher* pub, MatchingInfo& info);
|
||||
int n_matched;
|
||||
} m_listener;
|
||||
@[if float(fastrtps_version) < 1.9]@
|
||||
@(topic)_PubSubType myType;
|
||||
@[else]@
|
||||
@(topic)PubSubType myType;
|
||||
@[end if]@
|
||||
};
|
||||
|
||||
#endif // _@(topic)__PUBLISHER_H_
|
||||
|
||||
@@ -92,7 +92,11 @@ void RtpsTopics::publish(uint8_t topic_ID, char data_buffer[], size_t len)
|
||||
@[for topic in send_topics]@
|
||||
case @(rtps_message_id(ids, topic)): // @(topic)
|
||||
{
|
||||
@[ if ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" and float(fastrtps_version) < 1.9]@
|
||||
@(topic)_ st;
|
||||
@[ else]@
|
||||
@(topic) st;
|
||||
@[ end if]@
|
||||
eprosima::fastcdr::FastBuffer cdrbuffer(data_buffer, len);
|
||||
eprosima::fastcdr::Cdr cdr_des(cdrbuffer);
|
||||
st.deserialize(cdr_des);
|
||||
@@ -145,7 +149,11 @@ bool RtpsTopics::getMsg(const uint8_t topic_ID, eprosima::fastcdr::Cdr &scdr)
|
||||
case @(rtps_message_id(ids, topic)): // @(topic)
|
||||
if (_@(topic)_sub.hasMsg())
|
||||
{
|
||||
@[ if ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" and float(fastrtps_version) < 1.9]@
|
||||
@(topic)_ msg = _@(topic)_sub.getMsg();
|
||||
@[ else]@
|
||||
@(topic) msg = _@(topic)_sub.getMsg();
|
||||
@[ end if]@
|
||||
msg.serialize(scdr);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
@@ -117,6 +117,13 @@ void @(topic)_Subscriber::SubListener::onNewDataMessage(Subscriber* sub)
|
||||
{
|
||||
// Take data
|
||||
if(sub->takeNextData(&msg, &m_info))
|
||||
@[if (ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal") and float(fastrtps_version) < 1.9]@
|
||||
@(topic)_ st;
|
||||
@[else]@
|
||||
@(topic) st;
|
||||
@[end if]@
|
||||
|
||||
if(sub->takeNextData(&st, &m_info))
|
||||
{
|
||||
if(m_info.sampleKind == ALIVE)
|
||||
{
|
||||
@@ -141,7 +148,11 @@ bool @(topic)_Subscriber::hasMsg()
|
||||
return m_listener.has_msg;
|
||||
}
|
||||
|
||||
@[if (ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal") and float(fastrtps_version) < 1.9]@
|
||||
@(topic)_ @(topic)_Subscriber::getMsg()
|
||||
@[else]@
|
||||
@(topic) @(topic)_Subscriber::getMsg()
|
||||
@[end if]@
|
||||
{
|
||||
m_listener.has_msg = false;
|
||||
return m_listener.msg;
|
||||
|
||||
@@ -64,7 +64,11 @@ topic = alias if alias else spec.short_name
|
||||
#include <fastrtps/fastrtps_fwd.h>
|
||||
#include <fastrtps/subscriber/SubscriberListener.h>
|
||||
#include <fastrtps/subscriber/SampleInfo.h>
|
||||
@[if float(fastrtps_version) < 1.9]@
|
||||
#include "@(topic)_PubSubTypes.h"
|
||||
@[else]@
|
||||
#include "@(topic)PubSubTypes.h"
|
||||
@[end if]@
|
||||
|
||||
using namespace eprosima::fastrtps;
|
||||
using namespace eprosima::fastrtps::rtps;
|
||||
@@ -77,7 +81,11 @@ public:
|
||||
bool init();
|
||||
void run();
|
||||
bool hasMsg();
|
||||
@[if (ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal") and float(fastrtps_version) < 1.9]@
|
||||
@(topic)_ getMsg();
|
||||
@[else]@
|
||||
@(topic) getMsg();
|
||||
@[end if]@
|
||||
private:
|
||||
Participant *mp_participant;
|
||||
Subscriber *mp_subscriber;
|
||||
@@ -92,11 +100,19 @@ private:
|
||||
SampleInfo_t m_info;
|
||||
int n_matched;
|
||||
int n_msg;
|
||||
@[if (ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal") and float(fastrtps_version) < 1.9]@
|
||||
@(topic)_ msg;
|
||||
@[else]@
|
||||
@(topic) msg;
|
||||
@[end if]@
|
||||
bool has_msg = false;
|
||||
|
||||
} m_listener;
|
||||
@[if float(fastrtps_version) < 1.9]@
|
||||
@(topic)_PubSubType myType;
|
||||
@[else]@
|
||||
@(topic)PubSubType myType;
|
||||
@[end if]@
|
||||
};
|
||||
|
||||
#endif // _@(topic)__SUBSCRIBER_H_
|
||||
|
||||
@@ -57,7 +57,11 @@ def get_include_directives(spec):
|
||||
if genmsg.msgs.is_valid_constant_type(genmsg.msgs.bare_msg_type(field.type)):
|
||||
continue
|
||||
builtin_type = str(field.base_type).replace('px4/', '')
|
||||
@[if ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" and float(fastrtps_version) < 1.9]@
|
||||
include_directive = '#include "%s_.idl"' % builtin_type
|
||||
@[else]@
|
||||
include_directive = '#include "%s.idl"' % builtin_type
|
||||
@[end if]@
|
||||
builtin_types.add(builtin_type)
|
||||
include_directives.add(include_directive)
|
||||
return sorted(include_directives)
|
||||
@@ -74,10 +78,17 @@ def get_idl_type_name(field_type):
|
||||
def add_msg_field(field):
|
||||
if (not field.is_header):
|
||||
if field.is_array:
|
||||
@[if ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" and float(fastrtps_version) < 1.9]@
|
||||
print(' {0}__{1}_array_{2} {3}_;'.format(topic, str(get_idl_type_name(field.base_type)).replace(" ", "_"), str(field.array_len), field.name))
|
||||
else:
|
||||
base_type = get_idl_type_name(field.base_type) + "_" if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type)
|
||||
print(' {0} {1}_;'.format(base_type, field.name))
|
||||
@[else]@
|
||||
print(' {0}__{1}_array_{2} {3};'.format(topic, str(get_idl_type_name(field.base_type)).replace(" ", "_"), str(field.array_len), field.name))
|
||||
else:
|
||||
base_type = get_idl_type_name(field.base_type) if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type)
|
||||
print(' {0} {1};'.format(base_type, field.name))
|
||||
@[end if]@
|
||||
|
||||
|
||||
def add_msg_fields():
|
||||
@@ -88,6 +99,11 @@ def add_msg_fields():
|
||||
def add_array_typedefs():
|
||||
for field in spec.parsed_fields():
|
||||
if not field.is_header and field.is_array:
|
||||
@[if ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" and float(fastrtps_version) < 1.9]@
|
||||
base_type = get_idl_type_name(field.base_type) + "_" if get_idl_type_name(field.base_type) in builtin_types else
|
||||
@[else]@
|
||||
base_type = get_idl_type_name(field.base_type) if get_idl_type_name(field.base_type) in builtin_types else
|
||||
@[end if]@
|
||||
base_type = get_idl_type_name(field.base_type) + "_" if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type)
|
||||
array_type = 'typedef {0} {1}__{2}_array_{3}[{4}];'.format(base_type, topic, get_idl_type_name(field.base_type).replace(" ", "_"), field.array_len, field.array_len)
|
||||
if array_type not in array_types:
|
||||
@@ -109,18 +125,28 @@ def add_msg_constants():
|
||||
@#############################
|
||||
@# Include dependency messages
|
||||
@#############################
|
||||
@[for line in get_include_directives(spec)]
|
||||
@(line)
|
||||
@[end for]
|
||||
@[for line in get_include_directives(spec)]@
|
||||
@(line)@
|
||||
@[end for]@
|
||||
@# Constants
|
||||
@add_msg_constants()
|
||||
@# Array types
|
||||
@add_array_typedefs()
|
||||
@[if ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" and float(fastrtps_version) < 1.9]@
|
||||
struct @(topic)_
|
||||
@[else]@
|
||||
struct @(topic)
|
||||
@[end if]@
|
||||
{
|
||||
@add_msg_fields()
|
||||
@[if ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" and float(fastrtps_version) < 1.9]@
|
||||
}; // struct @(topic)_
|
||||
|
||||
#pragma keylist @(topic)_
|
||||
@[else]@
|
||||
}; // struct @(topic)
|
||||
|
||||
#pragma keylist @(topic)
|
||||
@[end if]@
|
||||
|
||||
#endif // __@(topic)__idl__
|
||||
|
||||
Reference in New Issue
Block a user