-->

Interfacing a native DDS system with ROS2

2019-07-20 21:07发布

问题:

To communicate to a ROS2 based publisher and a RTI Connext based subscriber, both of them need to have a compatible QoS settings.

I am using RTI Connector for python and using the XML Application Creation to run the subscriber.

I run a talker_py in ROS2 which has a default QoS and subscribe to these messages in RTI Connext Pro.

The ROS2 IDL is looks like this :

{
     module msg
     {
         module dds_ {
            struct String_ {
                String data_;
            };
         };
     };
};

I use the rtiddsgen utility tool to convert it into a XML file. Here is the converted 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>

I added the <types> to my USER_QoS.xml and it looks like :

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

Now when I use the RTI Connector for python, the first step here is trying to load the USER_QoS.xml file and it always give the error Unable to parse the .xml file. I strongly feel that this is because of the presence of the keyword module in the <types> definition.

Here is the python script for the RTI Connector:

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)

I feel that the connector is not able to parse this module keyword. Could it be the case ?

回答1:

When I try your setup, Connector provides more output than what you have indicated. Among others:

RTIXMLParser_validateOnStartTag:Parse error at line 15: Unexpected tag 'durablitiy'

This is an error in your XML, according to the its schema the tag name should be durability.

Then you seem to have made copy-paste errors copying the generated <types> tag and its contents into your XML. For that, connector gives the following error:

RTIXMLParser_parseFromFile_ex:Parse error at line 50: not well-formed (invalid token)

Indeed your line 50 has a superfluous quote at the end:

<member name="data_" type="std_msgs::msg::dds_::string" "/>

Also, the value of the type attribute is different from the generated XML that you tried to insert here, which has:

<member name="data_" type="string"/>

After correcting those errors, Connector instantiates properly.

To validate your XML file against its schema, you can/should use the associated XSD schema definition.