ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Your code is doing many things which lead to bad performance.

  1. You should not be doing any rospy calls until you have done the rospy.init_node().

  2. If you want good performance, you can not do slow stuff inside a subscribe callback: don't sleep, don't call services, don't wait for services, don't write a lot of data to files, don't convert the image data into some other format.

  3. One design strategy many have used successfully is to simply have the callback save the msg and then return. Then in your main loop, you keep checking to see if a msg is available, then process it when one shows up. In the main loop it is OK to do all the slow things I listed in item (2).

  4. If fact, you must sleep in main loop because you want to limit how many times per second the main loop executes. Typically a rospy.Rate object is used to implement this.

Your code is doing many things which lead to bad performance.

  1. You should not be doing any rospy calls until you have done the rospy.init_node().

  2. If you want good performance, you can not do slow stuff inside a subscribe callback: don't sleep, don't call services, don't wait for services, don't write a lot of data to files, don't convert the image data into some other format.

  3. One design strategy many have used successfully is to simply have the callback save the msg and then return. Then in your main loop, you keep checking to see if a msg is available, then process it when one shows up. In the main loop it is OK to do all the slow things I listed in item (2).

  4. If fact, you must sleep in main loop because you want to limit how many times per second the main loop executes. Typically a rospy.Rate object is used to implement this.

  5. If you are going to sleep, use rospy.sleep(), not time.sleep().

Your code is doing many things which lead to bad performance.

  1. You should not be doing any rospy calls until you have done the rospy.init_node().

  2. If you want good performance, you can not do slow stuff inside a subscribe callback: don't sleep, don't call services, don't wait for services, don't write a lot of data to files, don't convert the image data into some other format.

  3. One design strategy many have used successfully is to simply have the callback save the msg and then return. Then in your main loop, you keep checking to see if a msg is available, then process it when one shows up. In the main loop it is OK to do all the slow things I listed in item (2).

  4. If fact, you must sleep in main loop because you want to limit how many times per second the main loop executes. Typically a rospy.Rate object is used to implement this.

  5. If you are going to sleep, sleep in main loop, use rospy.sleep(), not time.sleep().