Advice on subscribing to multiple topics [closed]

asked 2012-07-19 23:59:40 -0600

bgagnon gravatar image

updated 2012-07-23 03:23:10 -0600

Hello,

This is not so much an error I'm receiving, but more so a question of how I should handle a situation.

Currently I have a node publishing a string version of some of the odometry data and it publishes this once every time the actual odom message is published. (no problems here). I also have a node that slowly updates containing wlan information. It gets this data by running "sudo iwlist wlan0 scan" through python and parsing the output. It updates about once a second.

Both of these nodes run on the turtlebot laptop itself. I also have another node on my workstation that simply takes these topics, combines them and puts them in a bag file for later use. It adds a line to the bag file every time it receives new odom data. It combines the odom data with wlan information stored in a variable that gets updated when the node receives new wlan data.

The only issue with this configuration is that instead of the wlan data variable being updated at the already slow rate of 1Hz, it slows down to once every 5 seconds which is totally unacceptable.

I feel like the high-rate receiving of the odom data is somehow interfering with the getting of the wlan information. What is the quickest and best solution to store this data at the fastest rate?

All ideas appreciated! Thanks,

Blair

I'll put here my bagger code. I think there is an error with the string addition, but don't worry about that.

#!/usr/bin/env python
import roslib; roslib.load_manifest('robonav_py')
import rospy
import rosbag
import signal
import sys
from std_msgs.msg import String
bagger = rosbag.Bag('/home/robolab/ros_workspace/rawAllData.bag', 'w')
output = open('/home/robolab/ros_workspace/rawAllData.txt', 'w')
IWList = ""

def updateIWList(data):
    global IWList
    IWList = data

def bag(data):
    global IWList
    bagger.write('rawAllData', str(data)+","+str(IWList))
    output.write(str(data)+","+str(IWList)+'\n')

def baggerScan():
    rospy.init_node('bagger')
    rospy.Subscriber('iwlist', String, updateIWList)
    rospy.Subscriber('rawOdom', String, bag)
    rospy.spin()

def signal_handler(signal, frame):
    bagger.close()
    output.close()
    sys.exit(0)

if __name__ == '__main__':
    signal.signal(signal.SIGINT, signal_handler)
    baggerScan()
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2015-03-27 19:04:49.247808

Comments

1

How is your cpu usage? Does commenting out the line that writes to the bag help? Btw. the signal handler is I guess a bad solution. Instead, I'd use a try-finally block in your main function. Otherwise, your node might not unregister cleanly since you catch sigint.

Lorenz gravatar image Lorenz  ( 2012-07-20 01:58:44 -0600 )edit

I wasn't able to get the CPU usage, but commenting out the bag.write() lines does nothing. I have a feeling there is an issue with the fact that odom is updated at a very high rate and iwlist is only updated ever 1.4 seconds.

bgagnon gravatar image bgagnon  ( 2012-07-22 23:02:09 -0600 )edit

Is there a way to tell rospy that I want the iwlist subscriber to have higher priority that the odom subscriber so that it handles iwlist as fast as possible?

bgagnon gravatar image bgagnon  ( 2012-07-22 23:03:31 -0600 )edit

Why can't you get cpu usage? Just execute top in a second terminal. If your python process is at 100%, the it really might be the odom rate. However, normally, odometry is not published with more than 30-50 Hz which is not really much.

Lorenz gravatar image Lorenz  ( 2012-07-22 23:03:55 -0600 )edit

The python process takes up only 3 percent of my CPU.

bgagnon gravatar image bgagnon  ( 2012-07-23 02:06:15 -0600 )edit

Just to verify, what's the output of rostopic hz rawOdom and rostopic hz iwlist?

Lorenz gravatar image Lorenz  ( 2012-07-23 02:10:20 -0600 )edit

Can you also check if it is the subscription that slows the node down? Try running @Lorenz' commands with and without your bagger node running.

dornhege gravatar image dornhege  ( 2012-07-23 03:11:54 -0600 )edit

The average rate is 0.678 for iwlist and 30 for odom. (I've simplified some things and now just record the original odom data.)

bgagnon gravatar image bgagnon  ( 2012-07-23 03:18:46 -0600 )edit