ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
This code needs to be reorganized if you want it to work well.
ros has restrictions on what you can do inside a subscriber callback. A well written app does not do anything that takes a long time (looping or heavy cpu processing) and it must never sleep. Creating a subscriber object inside a callback is not a good idea because it may be a little slow and may not see a message sent too soon afterward, but it is technically permitted to do so.
All of your code in callback()
should be in a find_face()
method that is called from the main loop. You are allowed to loop and sleep in the main loop, and in functions that it calls. Your callback()
should simply set a flag that controls whether the main loop calls find_face()
or not. It will work better if you create the stop_callback()
subscriber just once before you enter the main loop.
2 | No.2 Revision |
This code needs to be reorganized if you want it to work well.
ros has restrictions on what you can do inside a subscriber callback. A well written app does not do anything inside the callback that takes a long time (looping or heavy cpu processing) and it must never sleep. sleep. Creating a subscriber object inside a callback is not a good idea because it may be a little slow and may not see a message sent too soon afterward, but it is technically permitted to do so.
All of your code in callback()
should be in a find_face()
method that is called from the main loop. You are allowed to loop and sleep in the main loop, and in functions that it calls. Your callback()
should simply set a flag that controls whether the main loop calls find_face()
or not. It will work better if you create the stop_callback()
subscriber just once before you enter the main loop.