Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Printing data from a subscriber is lagging on several topics

Hi,

I am subscribing to several topics to print data while running a TurtleBot simulator in Gazebo. I am running it inside of a VM. The topics are /odom, /gazebo/model_states,/ and /amcl_pose. The amcl_pose publishes at an average rate of 2Hz, whereas the others publish at about 800Hz to 1000Hz. When I subscribe to those topics and print the data (I sleep for .5 seconds after printing), the data lags on the /odom and /gazebo/model_states topics, both which publish very fast. This is not a problem in the /amcl_pose since it publishes 2 messages per second. Here is the code that I am using which is similar for all topics, except the data structure and the subscribed topic.

import rospy
import time

from nav_msgs.msg import Odometry

class robot_pose():

    def __init__(self):
        rospy.init_node("robot_odom_pose_monitor")      
            rospy.Subscriber("/odom", Odometry, self.PoseEventCallback, queue_size=1)
        rospy.spin();

    def PoseEventCallback(self,data):
        pose = data.pose.pose
        position = pose.position

        output = "time: " + time.strftime("%Y-%m-%d %H:%M:%S") + " | x: " + str(position.x) + " | y: " + str(position.y)

        rospy.loginfo(data.pose.pose.position.x)
        rospy.sleep(0.5)

if __name__ == '__main__':
    try:
        robot_pose()
    except rospy.ROSInterruptException:
        robot_pose.close()
        rospy.loginfo("exception")

As you can see, I am setting the queue_size to be 1, which would mean that new messages that are published should override the single message waiting on the queue when I process the data. Hence, I should be getting the latest message all the time. However, when I run this code, that is not the case. It seems as if I process all of the messages and the data lags from what is currently happening in the simulator.

Any ideas as to why I see this behavior?

Thanks!

Printing data from a subscriber is lagging on several topics

Hi,

I am subscribing to several topics to print data while running a TurtleBot simulator in Gazebo. I am running it inside of a VM. The topics are /odom, /gazebo/model_states,/ and /amcl_pose. The amcl_pose publishes at an average rate of 2Hz, whereas the others publish at about 800Hz to 1000Hz. When I subscribe to those topics and print the data (I sleep for .5 seconds after printing), the data lags on the /odom and /gazebo/model_states topics, both which publish very fast. This is not a problem in the /amcl_pose since it publishes 2 messages per second. Here is the code that I am using which is similar for all topics, except the data structure and the subscribed topic.

import rospy
import time

from nav_msgs.msg import Odometry

class robot_pose():

    def __init__(self):
        rospy.init_node("robot_odom_pose_monitor")      
            rospy.Subscriber("/odom", Odometry, self.PoseEventCallback, queue_size=1)
        rospy.spin();

    def PoseEventCallback(self,data):
        pose = data.pose.pose
        position = pose.position

        output = "time: " + time.strftime("%Y-%m-%d %H:%M:%S") + " | x: " + str(position.x) + " | y: " + str(position.y)

        rospy.loginfo(data.pose.pose.position.x)
rospy.loginfo(output)
        rospy.sleep(0.5)

if __name__ == '__main__':
    try:
        robot_pose()
    except rospy.ROSInterruptException:
        robot_pose.close()
        rospy.loginfo("exception")

As you can see, I am setting the queue_size to be 1, which would mean that new messages that are published should override the single message waiting on the queue when I process the data. Hence, I should be getting the latest message all the time. However, when I run this code, that is not the case. It seems as if I process all of the messages and the data lags from what is currently happening in the simulator.

Any ideas as to why I see this behavior?

Thanks!