2 from rospy.impl.tcpros_base
import DEFAULT_BUFF_SIZE
3 from Queue
import Queue, Empty
as EmptyQueueException
4 from threading
import Condition
7 callback_queue = Queue()
11 This spinner is used in place of the rospy.spin() method. Whereas 12 rospy.spin() simply waits for rospy.is_shutdown(), this spinner processes 13 the callback queue until rospy.is_shutdown() is true. The callback 14 queue is thread-safe, so for a multi-threaded queue processor, call this 15 spin method in multiple threads. 17 while not rospy.is_shutdown():
19 condition = callback_queue.get(block=
True, timeout=0.1)
20 except EmptyQueueException:
32 This decorator can be used on service or subscriber callbacks. A callback 33 wrapped with this decorator will put a condition on the callback_queue and 34 then wait its turn before executing the decorated callback. 37 if hasattr(callback,
'single_threaded')
and callback.single_threaded:
40 def wrapped_callback(*args, **kwds):
42 condition = Condition()
44 callback_queue.put(condition)
49 ret = callback(*args, **kwds)
53 wrapped_callback.single_threaded =
True 54 return wrapped_callback
58 This is a decorator for functions that handle ROS service calls. 59 It catches unhandled exceptions and reports them cleanly as errors 62 def wrapper(*args, **kwds):
64 return func(*args, **kwds)
66 rospy.logerr(traceback.format_exc())
71 def __init__(self, name, service_class, handler,
72 buff_size=DEFAULT_BUFF_SIZE, error_handler=
None,
76 super(Service, self).
__init__(name, service_class, handler, buff_size,
80 def __init__(self, name, data_class, callback=None, callback_args=None,
81 queue_size=
None, buff_size=DEFAULT_BUFF_SIZE,
82 tcp_nodelay=
False, asynchronous=
False):
85 super(Subscriber, self).
__init__(name, data_class, callback,
86 callback_args, queue_size, buff_size, tcp_nodelay)
89 def __init__(self, period, callback, oneshot=False, asynchronous=False):
92 super(Timer, self).
__init__(period, callback, oneshot)
def single_threaded(callback)
def service_wrapper(func)
def __init__(self, name, service_class, handler, buff_size=DEFAULT_BUFF_SIZE, error_handler=None, asynchronous=False)
def __init__(self, period, callback, oneshot=False, asynchronous=False)
def __init__(self, name, data_class, callback=None, callback_args=None, queue_size=None, buff_size=DEFAULT_BUFF_SIZE, tcp_nodelay=False, asynchronous=False)