问题描述
ROS初学者在这里。我会正确的。
我想做什么:
- 使用roslibpy和rosbridge服务器通过LAN在非ROS客户端之间建立连接
- 按命令输入发布消息并测量往返时间(RTT)
设置如下:
- 在Ubuntu MATE 18.04上运行的ROS melodic和rosbridge。按照官方文档使用命令
roslaunch rosbridge_server rosbridge_websocket.launch
启动rosbridge服务器。 - 客户端使用受this tutorial启发的roslibpy运行python脚本来测量RTT(将整个脚本粘贴到下面)。
- 客户端和服务器运行在不同的计算机上,通过WiFi和LAN建立连接。
预期行为:
- 在运行我的python脚本后输入命令“ send”时,一条消息将发布到主题。
- 鉴于我正在LAN中运行此程序,我希望RTT
我得到的是
- 输入命令“ send”后,我测量的RTT在1s和20s之间!
- 使用命令行参数--streaming启动脚本时,脚本将根据教程执行(每0.5秒发布一条新消息)。在这种情况下,RTT在20ms-100ms之间。
有人可以向我解释,这是怎么回事?服务器进入睡眠模式还是其他?为什么RTT在“流式”和“非流式”行为之间存在根本差异?
这是我的剧本:
import signal
import logging
import time
import roslibpy
# Globals
log = None
streaming = False
execute = False
host = '172.16.2.215'
client = None
publisher = None
subscriber = None
# Startup message
start_up_msg = "\n### ROS Testing Script ###\nPlease type the following commands and press ENTER to execute:\n quit: quit testing script\n send: publish a timestamp to ROS server\n\nYou can also run this script with the cmdline argument --streaming which will publish messages continuously in a 0.5s interval"
# Functions
def receive_message(msg):
age = int(time.time() * 1000) - msg['data']
log.info('Age of message: %6dms',age)
def publish_message():
publisher.publish(dict(data=int(time.time() * 1000)))
if streaming:
client.call_later(.5,publish_message)
def get_input():
user_input = input()
if user_input == 'quit':
global execute
execute = False
elif user_input == 'send':
publish_message()
log.info(f"User input: {user_input}")
def init():
# Configure singal handling
signal.signal(signal.SIGINT,signal.SIG_DFL)
# Configure logging
global log
logging.basicConfig(format='# %(levelname)s: %(message)s',level=logging.INFO)
log = logging.getLogger(__name__)
log.info(start_up_msg)
# Start endless loop
global execute
execute = True
# Init roslibpy
global client,publisher,subscriber
client = roslibpy.Ros(host=host,port=9090)
publisher = roslibpy.Topic(client,'/testing','std_msgs/UInt64')
publisher.advertise()
subscriber = roslibpy.Topic(client,'std_msgs/UInt64')
subscriber.subscribe(receive_message)
try:
if streaming:
client.on_ready(publish_message)
client.run()
except:
log.info("Unable to connect to ROS server.")
def core_loop():
global execute
while execute:
get_input()
if __name__ == "__main__":
import argparse
# parse commandline arguments
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpformatter,description=__doc__)
parser.add_argument('--streaming',action='count',default=0,help='publish messages continuously')
args=parser.parse_args()
streaming = args.streaming > 0
init()
core_loop()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)