Advice on subscribing to multiple topics [closed]
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()
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.
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.
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?
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.The python process takes up only 3 percent of my CPU.
Just to verify, what's the output of
rostopic hz rawOdom
androstopic hz iwlist
?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.
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.)