如何使用 ROS 从 yaml 文件中读取带有元组的数组?
How to read in an array with tuples from a yaml file with ROS?
我有一个这样的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);
}
}
根据文档,没有任何函数getParam
来获取对向量或向量向量。因此,您需要更改 YAML 文件并仅使用现有函数getParam
。
相关文章:
- COM 接口 c# 封送数组数组
- 使用数组数组调用 C++ 函数
- 为什么我们必须在 C++ 中释放数组数组,而不仅仅是整个"matrix"
- 在C++中返回基元类型数组(Java比较)
- 形成元组数组C++
- 如何在 C++ 中定义数组数组
- 如何正确分配动态创建int并将其分配给具有值的动态数组数组
- 将指针返回使用New创建的数组数组
- 一种从元组/数组获取参数包的方法
- 如何在 HDF5 中逐个存储组数组
- 如何在 c++ 中将字符串拆分为字符串 2d 数组数组
- 如何将字符串数组转换为char数组数组
- 当将多个TypedArrayContents数组加载到V8数组中时(数组数组)时,最后一个元素将覆盖所有元素
- C AVX2:访问数组数组中的地址时SEG故障
- 不能和正确的方法来声明类成员 c++11 中的 int 数组数组
- 包含字符数组数组的结构
- 根据函数名称数组数组的索引调用函数
- 不同的计数器,同一数组.数组元素不变.C
- C++11-元组数组中的元组
- 从QSettings中读取自定义元类型数组