File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222from led_msgs .srv import SetLEDs
2323from led_msgs .msg import LEDStateArray , LEDState
2424from aruco_pose .msg import Marker , MarkerArray , Point2D
25+ from clover import long_callback
2526
2627import dynamic_reconfigure .client
2728
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ find_package(OpenCV ${_opencv_version} REQUIRED
5353## Uncomment this if the package has a setup.py. This macro ensures
5454## modules and global scripts declared therein get installed
5555## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
56- # catkin_python_setup()
56+ catkin_python_setup ()
5757
5858################################################
5959## Declare ROS messages, services and actions ##
Original file line number Diff line number Diff line change 1+ ## ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD
2+
3+ from distutils .core import setup
4+ from catkin_pkg .python_setup import generate_distutils_setup
5+
6+ # fetch values from package.xml
7+ setup_args = generate_distutils_setup (
8+ packages = ['clover' ],
9+ package_dir = {'' : 'src' })
10+
11+ setup (** setup_args )
Original file line number Diff line number Diff line change 1+ import rospy
2+ from threading import Thread , Event
3+
4+ def long_callback (fn ):
5+ """
6+ Decorator fixing a rospy issue for long-running topic callbacks, primarily
7+ for image processing.
8+
9+ See: https://github.com/ros/ros_comm/issues/1901.
10+
11+ Usage example:
12+
13+ @long_callback
14+ def image_callback(msg):
15+ # perform image processing
16+ # ...
17+
18+ rospy.Subscriber('main_camera/image_raw', Image, image_callback)
19+ """
20+ e = Event ()
21+
22+ def thread ():
23+ while not rospy .is_shutdown ():
24+ e .wait ()
25+ e .clear ()
26+ fn (thread .current_msg )
27+
28+ thread .current_msg = None
29+ Thread (target = thread , daemon = True ).start ()
30+
31+ def wrapper (msg ):
32+ thread .current_msg = msg
33+ e .set ()
34+
35+ return wrapper
Original file line number Diff line number Diff line change 33import pytest
44from mavros_msgs .msg import State
55from clover import srv
6+ import time
67
78@pytest .fixture ()
89def node ():
@@ -60,3 +61,18 @@ def wait_print():
6061
6162 t .join ()
6263 assert wait_print .result == 'test'
64+
65+ def test_long_callback ():
66+ from clover import long_callback
67+ from time import sleep
68+
69+ # very basic test for long_callback
70+ @long_callback
71+ def cb (i ):
72+ cb .counter += i
73+ cb .counter = 0
74+ cb (2 )
75+ sleep (0.1 )
76+ cb (3 )
77+ sleep (1 )
78+ assert cb .counter == 5
You can’t perform that action at this time.
0 commit comments