利用ROS自带的XmlRpc::XmlRpcValue实现一维数组或者二位数组等类似json数据的读取
C++代码实现如下
XmlRpc::XmlRpcValue scanner_params;
nh.getParam("scanners", scanner_params);
for(size_t i = 0; i<scanner_params.size(); ++i)
{
const String& server_ip = scanner_params[i]["server_ip"];
const int& server_port = scanner_params[i]["server_port"];
const String& frame_id = scanner_params[i]["frame_id"];
const String& pub_topic = scanner_params[i]["pub_topic"];
}
Yaml文件中数据如下
scanners:
- { pub_topic: "scan_head", frame_id: "laser_scanner_link_head",server_ip: "192.168.167.100",server_port: 2111}
- { pub_topic: "scan_middle",frame_id: "laser_scanner_link_middle",server_ip: "192.168.167.101",server_port: 2111}
- {pub_topic: "scan_tail",frame_id: "laser_scanner_link_tail",server_ip: "192.168.167.102",server_port: 2111}
在launch文件中加载yaml参数文件,即可在程序中读取