Advice on subscribing to multiple topics
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()
Asked by bgagnon on 2012-07-19 23:59:40 UTC
Comments
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.
Asked by Lorenz on 2012-07-20 01:58:44 UTC
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.
Asked by bgagnon on 2012-07-22 23:02:09 UTC
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?
Asked by bgagnon on 2012-07-22 23:03:31 UTC
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.Asked by Lorenz on 2012-07-22 23:03:55 UTC
The python process takes up only 3 percent of my CPU.
Asked by bgagnon on 2012-07-23 02:06:15 UTC
Just to verify, what's the output of
rostopic hz rawOdom
androstopic hz iwlist
?Asked by Lorenz on 2012-07-23 02:10:20 UTC
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.
Asked by dornhege on 2012-07-23 03:11:54 UTC
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.)
Asked by bgagnon on 2012-07-23 03:18:46 UTC
I've also found something else out. If I subscribe to the original odom message, even without subscribing to the iwlist, it still slows down the iwlist node and reduces it's rate from 0.678 to 0.148. Once again, this is without even subscribing to the iwlist node.
Asked by bgagnon on 2012-07-23 03:22:39 UTC
Does that mean that the call to iwlist just takes longer?
Asked by Lorenz on 2012-07-23 03:29:11 UTC
I don't know. Would subscribing to a node that is running on a remote machine slow that node down? From 0.678? to 0.148Hz?
Asked by bgagnon on 2012-07-23 03:32:01 UTC
Normally not. I assume that something that is not necessarily ros related is slowing down the call to iwlist. Can you please check if the call to iwlist gets slower?
Asked by Lorenz on 2012-07-23 03:34:20 UTC
That is in fact the problem. Any advice on a work around? Also, if I run the bagger node from the turtlebot I do not get the slowing down of the call time.
Asked by bgagnon on 2012-07-23 03:45:18 UTC
I don't think your problem is really ros related. The cause might have something to do with your wifi driver or the way iwlist is implemented. I would try to find an alternative to iwlist and try different hardware.
Asked by Lorenz on 2012-07-23 03:48:53 UTC
It might still be somewhat ROS related. Maybe the high-rate odom publishing and the iwlist both working on networking somehow conflict?
Asked by dornhege on 2012-07-23 03:51:54 UTC
I wouldn't consider 30Hz to be high rate though. But you are right. Maybe something as weird as a lock that prevents iwlist to terminate quickly if odom is published.
Asked by Lorenz on 2012-07-23 03:54:22 UTC
Ok, looks like I'm going to have to try a different strategy. Thanks for helping me pin-point the problem! I realize the problem isn't ros anymore (maybe), but instead of iwlist, how would you suggest I capture wlan data?
Asked by bgagnon on 2012-07-23 04:09:52 UTC