Publish to Topic super slow

asked 2020-08-22 12:15:21 -0500

prjoh gravatar image

updated 2020-08-23 00:12:50 -0500

gvdhoorn gravatar image

Hey.

ROS beginner here. I'll get right to it.

What I want to do:

  • Establish connection between non-ROS client using roslibpy and rosbridge server over LAN
  • Publish a message per command input and measure round-trip-time (RTT)

The setup is as follows:

  • ROS melodic & rosbridge running on Ubuntu MATE 18.04. Started the rosbridge server following official documentation with command roslaunch rosbridge_server rosbridge_websocket.launch.
  • Client runs a python script using roslibpy inspired by this tutorial to measure the RTT (will paste the whole script down below).
  • Client and Server run on separate machines, establishing connection over WiFi & LAN.

Expected behavior:

  • When inputting the command 'send' after running my python script, a message is published to a topic.
  • Given I am running this in LAN, I expect a RTT <100ms.

What I get:

  • After inputting the command 'send', I measure a RTT between 1s and 20s!
  • When starting my script with the command line argument --streaming, the script is executed according to the tutorial (publishing a new message every 0.5s). In this scenario the RTT is between 20ms-100ms.

Can someone explain to me, what is going wrong here? Is the server going into sleep mode or something? Why are the RTTs fundamentally different between 'streaming' and 'non-streaming' behavior?

Here is my script:

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, '/testing', '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()
edit retag flag offensive close merge delete