ROS環境讀取yaml文件中數組

利用ROS自帶的XmlRpc::XmlRpcValue實現一維數組或者二位數組等相似json數據的讀取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文件中數據以下spa

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參數文件,便可在程序中讀取code

相關文章
相關標籤/搜索