我没有使用ROS的经验,但我会尝试帮助DDS / Connector部分。
据我所知,在DDS中你不能指定一个无界数组。您可以使用无界序列,但不能使用数组。因此,如果您使用的类型如下所示:
struct DetectedObject { short id; string name; short x; short y; }; struct MyMessage { short id; DetectedObject objects[10]; };
或者你有一个无界的序列:
struct DetectedObject { short id; string name; short x; short y; }; struct MyMessage { short id; sequence<DetectedObject> objects; };
然后您的连接器代码将是这样的:
connector = rti.Connector("MyParticipantLibrary::PubParticipant", filepath + "/ROS.xml") outputDDS = connector.getOutput("MyPub::MyTopicWriter") for i in range(1, 500): # There are two ways to set values in an instance: # 1. Field by Fields: outputDDS.instance.setNumber("id", 1) #note index, for now, starts from 1. This may change in the future outputDDS.instance.setNumber("objects[1].id", 2) outputDDS.instance.setString("objects[1].name", "aName") outputDDS.instance.setNumber("objects[1].x", 3) outputDDS.instance.setNumber("objects[1].y", 4) outputDDS.write() # OR # 2. By first creating a dictionary and then setting it all at once: myDict = {'id': 5, 'objects': [{'id': 6, 'name': '', 'x': 7, 'y': 8}]} outputDDS.instance.setDictionary(myDict) outputDDS.write() sleep(2)
也许其他人可以为ROS做出更多贡献&lt; - &gt;关于无界数组的DDS映射。
我希望这有帮助, Gianpiero