我有一个像这样的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>>>
是否正确?
(对不起,这是一个巨大的项目,很难举一个小而可编译的示例。如果您坚持下去,我会做一个小示例。)
答案 0 :(得分:0)
根据documentation,没有任何函数getParam
用于获取对向量或向量向量。因此,您需要更改YAML文件并仅使用现有功能getParam
。
答案 1 :(得分:0)
它可以通过使用 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);
}
}