zoukankan      html  css  js  c++  java
  • Mr_matcher的细节2

    1.参数服务器

    ROS参数服务器能保存数据类型包括:strings, integers, floats, booleans, lists, dictionaries, iso8601 dates, and base64-encoded data。Dictionaries则必需有字符串key值。

    roscpp参数API能支持全部类型,多数情况容易使用的类型有:strings, integers, floats and booleans,使用其他类型参考XmlRpc::XmlRpcValue class

    roscpp有两个版本的API接口:bare版和handle版。

    bare版:在 ros::param 命令空间下。

    handle版:通过ros::NodeHandle接口使用。

    2.获取参数

    从参数服务器获取值,每个版本都支持strings, integers, doubles, booleans 和XmlRpc::XmlRpcValue

    返回 false代表参数不存在或不是正确的类型。

    1)NodeHandle版本

    ros::NodeHandle::getParam()

    NodeHandle版本:参数相对于NodeHandle的命名空间进行解析。

    ros::NodeHandle nh;
    std::string global_name, relative_name, default_param;
    if (nh.getParam("/global_name", global_name))
    {
      ...
    }
    
    if (nh.getParam("relative_name", relative_name))
    {
    ...
    }
    
    // Default value version
    nh.param<std::string>("default_param", default_param, "default_value");
    

     3.设置参数

    NodeHandle版本
    ros::NodeHandle::setParam() NodeHandle版本:参数相对于NodeHandle的命名空间进行解析 ros::NodeHandle nh; nh.setParam("/global_param", 5); nh.setParam("relative_param", "my_string"); nh.setParam("bool_param", false);

    4.检查参数是否存在

    handle版:ros::NodeHandle::hasParam()
    ros::NodeHandle nh;
    if (nh.hasParam("my_param"))
    {
      ...
    }

    5.删除参数

    handle版:ros::NodeHandle::deleteParam()
    
    ros::NodeHandle nh;
    nh.deleteParam("my_param");

     6.访问私有参数

    handle版:创建的ros::NodeHandle实例,并提供私有的命名空间作为其命名空间
    ros::NodeHandle nh("~");
    std::string param;
    nh.getParam("private_name", param);
    

     参考http://www.ncnynl.com/archives/201702/1295.html

  • 相关阅读:
    每天一道LeetCode--141.Linked List Cycle(链表环问题)
    每天一道LeetCode--119.Pascal's Triangle II(杨辉三角)
    每天一道LeetCode--118. Pascal's Triangle(杨辉三角)
    CF1277D Let's Play the Words?
    CF1281B Azamon Web Services
    CF1197D Yet Another Subarray Problem
    CF1237D Balanced Playlist
    CF1239A Ivan the Fool and the Probability Theory
    CF1223D Sequence Sorting
    CF1228D Complete Tripartite
  • 原文地址:https://www.cnblogs.com/gary-guo/p/7065305.html
Copyright © 2011-2022 走看看