c++ - 如何从带有 ROS 的 yaml 文件中读取包含元组的数组?
问题描述
我有一个这样的 yaml 文件:
object_0:
- v: 1.55
- t_x: 110.281
- t_y: 367.959
- traj_const_dist: 1.0
- trajectory: [[117, 356], [116, 356], [115, 356], [114, 356], [113, 356], [113, 357], [113, 358], [113, 359], [113, 360]]
参数trajectory
定义如下:std::vector<std::pair<double,double>> trajectory_;
当我读入参数时:
ros::NodeHandle nh_;
nh_.param<std::vector<std::pair<double, double>>>(obj_topic, trajectory_, std::vector<std::pair<double, double>>());
...我收到此错误:
error: no matching function for call to ‘ros::NodeHandle::getParam(const string&, std::vector<std::pair<double, double> >&) const’
if (getParam(param_name, param_val))
如果你给我建议会有所帮助。数据类型std::vector<std::pair<double, double>>>
不正确?
(不好意思,项目很大,很难做一个小的可编译的例子,如果你坚持的话,我会做一个小的。)
解决方案
可以通过使用 XmlRpc::XmlRpcValue 来完成
假设 yaml 文件中的参数已经加载到参数服务器,可以使用以下代码片段:
XmlRpc::XmlRpcValue trajectory;
nh_.getParam("/param_name", trajectory);
/*To ensure the reading will happen if the data is provided in right format*/
if (trajectory.getType() == XmlRpc::XmlRpcValue::TypeArray)
{
for (int i = 0; i < trajectory.size(); i++)
{
XmlRpc::XmlRpcValue trajectoryObject = trajectory[i];
/*Individual coordinate points in trajectory*/
int xCoordinate = trajectoryObject[0];
int yCoordinate = trajectoryObject[1];
ROS_INFO("The %d th coordinate values are : %d and %d", ixCoordinate, yCoordinate);
}
}
推荐阅读
- linux - Systemtap - 从内核空间调用系统调用
- angular - 授权标头未通过 HTTPS 加密
- python-3.x - 访问单个树估计器以预测来自梯度提升分类器估计器的值
- sapui5 - 消耗性面板之间的键盘导航
- node.js - 如何获取 jsonwebtoken 密钥的密钥?
- azure - Apache Alluxio 可以使用 Azure Data Lake 作为底层存储吗?
- javascript - 如何在 JavaScript 中删除/更改函数绑定
- javascript - 如何在角度更改数组中的值后获取有序索引?
- angular - Angular 5 中的路由问题
- c# - Visual Studio 2012 中的 HTTPClient POST