-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement long_callback Python decorator addressing #218
Clover package Python library added.
- Loading branch information
Showing
5 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD | ||
|
||
from distutils.core import setup | ||
from catkin_pkg.python_setup import generate_distutils_setup | ||
|
||
# fetch values from package.xml | ||
setup_args = generate_distutils_setup( | ||
packages=['clover'], | ||
package_dir={'': 'src'}) | ||
|
||
setup(**setup_args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import rospy | ||
from threading import Thread, Event | ||
|
||
def long_callback(fn): | ||
""" | ||
Decorator fixing a rospy issue for long-running topic callbacks, primarily | ||
for image processing. | ||
See: https://github.com/ros/ros_comm/issues/1901. | ||
Usage example: | ||
@long_callback | ||
def image_callback(msg): | ||
# perform image processing | ||
# ... | ||
rospy.Subscriber('main_camera/image_raw', Image, image_callback) | ||
""" | ||
e = Event() | ||
|
||
def thread(): | ||
while not rospy.is_shutdown(): | ||
e.wait() | ||
e.clear() | ||
fn(thread.current_msg) | ||
|
||
thread.current_msg = None | ||
Thread(target=thread, daemon=True).start() | ||
|
||
def wrapper(msg): | ||
thread.current_msg = msg | ||
e.set() | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters