1

我一直在尝试在 Ubuntu 20.04.2 LTS 上使用凌华科技的Vortex OpenSplice 社区版和 Python API(PyEnv 虚拟环境中的 Python 版本 3.6)。我遵循了PythonDCPSAPIGuide并让 ($OSPL_HOME/tools/python/examples) 中的 python 示例正常工作。但是,我无法弄清楚如何使用idlpp. 我怎么能做到这一点?

到目前为止我做了什么:

我有一个 IDL 文件,其中包含许多其他 IDL 文件的路径。我已使用以下 bash 脚本将这些 IDL 文件转换为 python 主题类:

#!/bin/bash

for FILE in *.idl; do
  $OSPL_HOME/bin/idlpp -I $OSPL_HOME/etc/idl -S -l python -d . $FILE
done

这将创建一系列 python 包(python 主题类),我将它们导入到同一目录中的 python 脚本中。

使用这些包,我想在我的 python 脚本中创建或注册一个域参与者的主题。例如下面的 python 代码,(但是'create_topic'函数不存在):

# myExampleDDSFile.py

from dds import *
from foo import foo_type # idlpp generated module/class
from foo2 import foo_type2 # idlpp generated module/class

dp = DomainParticipant()
topic = dp.create_topic('foo_topic',foo_type) # this function doesn't exist for a domain participant
pub = dp.create_publisher()

这可能吗?如果可以,我将如何注册一个我用python中的域参与者静态创建的主题?


我注意到在提供的 python 示例(例如 $OSPL_HOME/tools/python/examples/example1.py)中,使用下面的代码动态注册了一个主题,但我认为这与静态生成的 python 主题类无关:

# example1.py snippet

dp = DomainParticipant()
gen_info = ddsutil.get_dds_classes_from_idl('example1.idl', 'basic::module_SequenceOfStruct::SequenceOfStruct_struct')
topic = gen_info.register_topic(dp, 'Example1')

我在源代码中也看不到相关功能。

如果这是一个简单的问题,或者我错过了什么,我深表歉意——我对 Vortex OpenSplice DDS 非常陌生。

任何帮助,将不胜感激。

4

1 回答 1

1

我无法与 OpenSplice 交谈,但您可以使用 CoreDX DDS 做到这一点。例如,给定 IDL 文件“hello.idl”:

struct StringMsg
{
   string msg;
};

coredx_ddl -l python -f hello.idl -d hello

然后,下面的 python 是如何使用生成的 'StringMsg' 类型来构造 Topic 和 DataReader 的示例:

import time
import dds.domain
from  hello import StringMsg

# Use default QoS, and no listener
dp    = dds.domain.DomainParticipant( 0 )
topic = dds.topic.Topic( StringMsg, "helloTopic", "StringMsg", dp )
sub   = dds.sub.Subscriber( dp )
dr    = dds.sub.DataReader( sub, topic )
rc    = dr.create_readcondition( dds.core.SampleState.ANY_SAMPLE_STATE,
                                 dds.core.ViewState.ANY_VIEW_STATE,
                                 dds.core.InstanceState.ANY_INSTANCE_STATE )
ws    = dds.cond.WaitSet()
ws.attach_condition(rc)

while True:
    t = dds.core.Duration.infinite()
    print('waiting for data...')
    ws.wait(t)
    while True:
        try:
            samples = dr.take( )
            for s in samples:
                if s.info.valid_data:
                    print("received: {}".format(s.data.msg))
        except dds.core.Error:
            break;
于 2021-04-29T23:34:04.207 回答