rospy的publisher和init_node

1,class Publiser (发布者)

废话不多说,先看官方文档对这个api的解释

class Publisher(Topic):
    """
    Class for registering as a publisher of a ROS topic.
    """
    '''这里说的是Publisher类的作用,注册为ROS topic的发布者'''
    def __init__(self,name,data_class,subscriber_listener=None,
                 tcp_nodelay=False,latch=False,
                 headers=None,queue_size=None):
        '''
        下面是对各个参数的解释
        Constructor
        @param name:resource name of topic,e.g.laser
        topic的资源名,比如激光。
        @type name:str
        类型str
        @param data_class: message class for serialization
        @type data_class:L{message} class
        消息序列化的类
        @param subscriber_listener:listener for 
        subscriber_listener events.may be None.
        @type subscriber_listener:L{SubscribeListemer}
        订阅者类,可以为空
        @param tcp_nodelay: If True,sets TCP_NODELAY on publisher‘s socket (disables Nagle algorithm).This result in lower latency publishing at the cost of efficiency.
        @type tcp_nodelay:boll
        tcp节点延迟,如果为真的话,设置节点延迟在tcp节点上。这个结果以降低发布者的效率为代价。
        @param latch: If True, the last message published is
        'latched', meaning that any future subscribers will be sent
        that message immediately upon connection。
        @type  latch: bool
        如果为真的话,最新的信息是latched,指的是在连接的时候,未来的订阅着,会第一时间发送message。
        @param headers: If not None, a dictionary with additional header
        key-values being used for future connections.
        @type  headers: dict
        请求头
         @param queue_size: The queue size used for asynchronously
        publishing messages from different threads.  A size of zero
        means an infinite queue, which can be dangerous.  When the
        keyword is not being used or when None is passed all
        publishing will happen synchronously and a warning message
        will be printed.
        @type  queue_size: int
        来自不同的线程,为了异步发送消息被使用的队列大小。
        初始化为0的队列是很危险的。当参数没有被使用或者为空的时候,所有的消息将被同步发送,一个警告的消息被打印在控制台上。
        '''

2, rospy.init_node (初始化节点)

def init_node(name,argv=None,anonymous=False,log_level=None,
              disable_rostime=False,disable_rosout=False,disable_signals=False,xmlrpc_port=0,tcpros_port=0):
    '''
     Register client node with the master under the specified name.
    This MUST be called from the main Python thread unless
    disable_signals is set to True. Duplicate calls to init_node are
    only allowed if the arguments are identical as the side-effects of
    this method are not reversible.
    注册客户端节点到master,使用指定的名字。这必须从python的主线程调用除非disable_signals被设置为true。对init_node的重复调用是被允许的,只有参数完全一样,而且这种方法是不可逆的。
    @param name: Node's name. This parameter must be a base name,
        meaning that it cannot contain namespaces (i.e. '/')
    @type  name: str
    node节点名字。
     @param argv: Command line arguments to this program, including
        remapping arguments (default: sys.argv). If you provide argv
        to init_node(), any previously created rospy data structure
        (Publisher, Subscriber, Service) will have invalid
        mappings. It is important that you call init_node() first if
        you wish to provide your own argv.
    @type  argv: [str]
    这个程序的命令行参数,包括映射参数。如果你提供argv到init_node(),之前任何已经创建的rospy数据结构(publisher,subscriber,service)都将失效。首先调用init_node()非常重要,如果您希望提供自己的argv。
    @param anonymous: if True, a name will be auto-generated for the
        node using name as the base.  This is useful when you wish to
        have multiple instances of the same node and don't care about
        their actual names (e.g. tools, guis). name will be used as
        the stem of the auto-generated name. NOTE: you cannot remap
        the name of an anonymous node.  
    @type anonymous: bool
    如果为真,一个名字将会自动生成对于节点,来作为base名称。这是有用的,当你希望有多个节点,而不关心她们的名字。name将会被使用作为自动生成名字的词干。注意:你不能重新映射
匿名节点的名称。
	@param log_level: log level for sending message to /rosout and log
        file, which is INFO by default. For convenience, you may use
        rospy.DEBUG, rospy.INFO, rospy.ERROR, rospy.WARN, rospy.FATAL
    @type  log_level: int
    对于发送信息来说的日志等级,到/rosout and log file,默认等级是default.For convenience, you may use
        rospy.DEBUG, rospy.INFO, rospy.ERROR, rospy.WARN, rospy.FATAL。
     @param disable_signals: If True, rospy will not register its own
        signal handlers. You must set this flag if (a) you are unable
        to call init_node from the main thread and/or you are using
        rospy in an environment where you need to control your own
        signal handling (e.g. WX). If you set this to True, you should
        call rospy.signal_shutdown(reason) to initiate clean shutdown.

        NOTE: disable_signals is overridden to True if
        roslib.is_interactive() is True.
        
    @type  disable_signals: bool
    如果为true,rospy将不会注册他的唯一的信号处理器。你必须设置这个flag,如果在一个你正在使用的主线程的环境中你需要控制你的信号你不能调用init_node()。如果你设置为true,你应该调用rospy.signal_shutdowm(reason)去初始化优雅的关闭。
     @param disable_rostime: for internal testing only: suppresses
        automatic subscription to rostime
    @type  disable_rostime: bool
    对内部测试来说,压制自动订阅到rostime.
      @param disable_rosout: for internal testing only: suppress
        auto-publication of rosout
    @type  disable_rostime: bool
    对内部测试来说,压制rosout的自动发布。
     @param xmlrpc_port: If provided, it will use this port number for the client XMLRPC node.
    @type  xmlrpc_port: int
    如果提供的话,对client XMLPRC node来说,它将使用这个端口数字。
    @param tcpros_port: If provided, the TCPROS server will listen for
        connections on this port
    @type  tcpros_port: int
    如果提供的话,TCPROS服务将会监听端口的链接。
    
    '''
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是梦磊OL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值