简体   繁体   English

ROS:发布主题无需 3 秒锁存

[英]ROS: Publish topic without 3 second latching

As a premise I must say I am very inexperienced with ROS.作为一个前提,我必须说我对 ROS 非常缺乏经验。

I am trying to publish several ros messages but for every publish that I make I get the "publishing and latching message for 3.0 seconds", which looks like it is blocking for 3 seconds.我正在尝试发布几条 ros 消息,但是对于我进行的每次发布,我都会收到“发布和锁定消息 3.0 秒”,这看起来像是阻塞了 3 秒。

I'll leave you with an example of how I am publishing one single message:我将为您提供一个示例,说明我如何发布一条消息:

rostopic pub -1 /heifu0/mavros/adsb/send mavros_msgs/ADSBVehicle "header: // then the rest of the message

I've also tried to use the following argument: -r 10, which sets the message frequency to 10Hz (which it does indeed) but only for the first message Ie it keeps re-sending the first message 10 times a second.我还尝试使用以下参数:-r 10,它将消息频率设置为 10Hz(确实如此),但仅适用于第一条消息,即它保持每秒重新发送第一条消息 10 次。

Basically i want to publish a message without latching, if possible, so i can publish multiple messages a second.基本上,如果可能的话,我想在不锁定的情况下发布一条消息,这样我就可以在一秒钟内发布多条消息。 I have a constant stream of messages coming and i need to publish them all as fast as i can.我有一个恒定的 stream 消息,我需要尽快发布它们。

Part of the issue is that rostopic CLI tools are really meant to be helpers for debugging/testing.部分问题在于rostopic CLI 工具实际上是用于调试/测试的助手。 It has certain limitations that you're seeing now.它有你现在看到的某些限制。 Unfortunately, you cannot remove that latching for 3 seconds message, even for 1-shot publications.不幸的是,您无法删除该锁定 3 秒的消息,即使对于 1-shot 出版物也是如此。 Instead this is a job for an actual ROS node.相反,这是一个实际 ROS 节点的工作。 It can be done in a couple of lines of Python like so:它可以在几行 Python 中完成,如下所示:

import rospy
from mavros_msgs.msg import ADSBVehicle

class MyNode:
    def __init__(self):
        rospy.init_node('my_relay_node')
        self.rate = rospy.Rate(10.0) #10Hz

        self.status_pub = rospy.Publisher('/heifu0/mavros/adsb/send', ADSBVehicle, queue_size=10)

    def check_and_send(self):
        #Check for some condition here
        if some_condition:
            output_msg = ADSBVehicle()
            #Fill in message fields here
            self.status_pub.publish(output_msg)

    def run_node(self):
        while not rospy.is_shutdown():
            self.check_and_send()
            self.rate.sleep() #Run at 10Hz

if __name__ == '__main__':
    node = myNode()
    node.run_node()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM