我没有使用 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 <--> DDS 映射做出更多贡献。
我希望这有帮助,詹皮耶罗