要与基于ROS2的发布者和基于RTI Connext的订户进行通信,两者都需要具有兼容的QoS设置。
我将RTI Connector用于python,并使用XML Application Creation运行订户。
我在ROS2中运行了default QoS的talker_py
,并在RTI Connext Pro中订阅了这些消息。
ROS2 IDL看起来像这样:
{
module msg
{
module dds_ {
struct String_ {
String data_;
};
};
};
};
我使用rtiddsgen
实用工具将其转换为XML文件。这是转换后的XML:
<?xml version="1.0" encoding="UTF-8"?>
<types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="/path/to/RTIInstall/rti_connext_dds-5.3.1/bin/../resource/app/app_support/rtiddsgen/schema/rti_dds_topic_types.xsd">
<module name="std_msgs">
<module name="msg">
<module name="dds_">
<struct name="String_">
<member name="data_" type="string"/>
</struct>
</module>
</module>
</module>
</types>
我将<types>
添加到了USER_QoS.xml
中,它看起来像:
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://community.rti.com/schema/5.1.0/rti_dds_profiles.xsd" version="5.1.0">
<!-- Qos Library -->
<qos_library name="QosLibrary">
<qos_profile name="DefaultProfile" is_default_qos="true">
<datawriter_qos>
<history>
<kind>KEEP_LAST_HISTORY_QOS</kind>
<depth>1000</depth>
</history>
<reliability>
<kind>RELIABLE_RELIABILITY_QOS</kind>
</reliability>
<durablitiy>
<kind>VOLATILE_DURABILITY_QOS</kind>
</durablitiy>
</datawriter_qos>
<participant_qos>
<transport_builtin>
<mask>UDPV4 | SHMEM</mask>
</transport_builtin>
<!-- Turn on monitoring -->
<!-- Begin Monitoring
<property>
<value>
<element>
<name>rti.monitor.library</name>
<value>rtimonitoring</value>
</element>
<element>
<name>rti.monitor.create_function_ptr</name>
<value>$(NDDS_MONITOR)</value>
</element>
</value>
</property>
End Monitoring -->
</participant_qos>
</qos_profile>
</qos_library>
<!-- types -->
<types>
<module name="std_msgs">
<module name="msg">
<module name="dds_">
<struct name="String_" extensibility="extensible">
<member name="data_" type="std_msgs::msg::dds_::string" "/>
</struct>
</module>
</module>
</module>
</types>
<!-- Domain Library -->
<domain_library name="MyDomainLibrary">
<domain name="MyDomain" domain_id="0">
<register_type name="std_msgs::msg::dds_::String_" type_ref="std_msgs::msg::dds_::String_" />
<topic name="chatter" register_type_ref="std_msgs::msg::dds_::String_"/>
</domain>
</domain_library>
<!-- Participant library -->
<domain_participant_library name="MyParticipantLibrary">
<domain_participant name="Zero" domain_ref="MyDomainLibrary::MyDomain">
<subscriber name="MySubscriber">
<data_reader name="MyChatterReader" topic_ref="chatter" />
</subscriber>
</domain_participant>
</domain_participant_library>
</dds>
现在,当我将RTI连接器用于python时,此处的第一步是尝试加载USER_QoS.xml
文件,并且该文件始终会显示错误Unable to parse the .xml file
。我强烈认为这是因为module
定义中存在关键字<types>
。
这是RTI连接器的python脚本:
from __future__ import print_function
from sys import path as sysPath
from os import path as osPath
from time import sleep
filepath = osPath.dirname(osPath.realpath(__file__))
sysPath.append(filepath + "/../../../")
import rticonnextdds_connector as rti
connector = rti.Connector("MyParticipantLibrary::Zero",
filepath + "/../User_QoS.xml")
inputDDS = connector.getInput("MySubscriber::MyChatterReader")
for i in range(1, 500):
inputDDS.take()
numOfSamples = inputDDS.samples.getLength()
for j in range(1, numOfSamples+1):
if inputDDS.infos.isValid(j):
# This gives you a dictionary
sample = inputDDS.samples.getDictionary(j)
x = sample['x']
# Or you can just access the field directly
toPrint = "Received x: " + repr(x)
print(toPrint)
sleep(2)
我认为连接器无法解析此module
关键字。可能是这样吗?
答案 0 :(得分:2)
当我尝试设置时,连接器提供的输出比您指示的要多。除其他外:
RTIXMLParser_validateOnStartTag:Parse error at line 15: Unexpected tag 'durablitiy'
这是XML中的错误,根据其架构,标记名称应为durability
。
然后,您似乎在复制生成的<types>
标签及其内容到XML中时出现了复制粘贴错误。为此,连接器给出以下错误:
RTIXMLParser_parseFromFile_ex:Parse error at line 50: not well-formed (invalid token)
事实上,您的第50行结尾处有多余的报价:
<member name="data_" type="std_msgs::msg::dds_::string" "/>
此外,type
属性的值与您尝试在此处插入的生成XML有所不同,
<member name="data_" type="string"/>
更正这些错误后,连接器会正确实例化。
要根据其架构验证XML文件,您可以/应该使用the associated XSD schema definition。