rospy相关API的学习

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lqzdreamer/article/details/82812601

rospy的API源代码说明

访问节点信息

  • rospy.get_name(),获取此节点的完全限定名称,如果不是节点则返回空字符。
  • rospy.get_namespace(),获取此节点的命名空间
  • rospy.get_node_uri(),获取这个节点的XMLRPC URI

操作名称

操作名称的独立的节点库,查看rospy.names 和rosgraph.names.
函数定义:rospy.resolve_name(name, caller_id=None)
解析ROS名称,全局规范格式
私有~names 会解析成相对节点名
使用caller_id ,可解析相对于不同节点的名称(又叫 “caller ID”)
解析本地命名空间,可以忽略参数,或取caller_id=None

rospy.get_param() 从参数服务器获得参数

def get_param(param_name, default=_unspecified):
""" 
Retrieve a parameter from the param server NOTE: this method is thread-safe.
@param default: (optional) default value to return if key is not set 
@type default: any 
@return: parameter value 
@rtype: XmlRpcLegalValue 
@raise ROSException: if parameter server reports an error 
@raise KeyError: if value not set and default is not given
"""  

rospy.wait_for_message() 从topic中获得消息

def wait_for_message(topic, topic_type, timeout=None):
""" 
Receive one message from topic. This will create a new subscription to the topic, receive one message, then unsubscribe. @param topic: name of topic 
@type topic: str 
@param topic_type: topic type
@type topic_type: L{rospy.Message} class
@param timeout: timeout time in seconds 
@type timeout: double 
@return: Message 
@rtype: L{rospy.Message} 
@raise ROSException: if specified timeout is exceeded 
@raise ROSInterruptException: if shutdown interrupts wait 

猜你喜欢

转载自blog.csdn.net/lqzdreamer/article/details/82812601