-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rqt_bag: publish clock time from bag #204
Merged
dirk-thomas
merged 1 commit into
ros-visualization:groovy-devel
from
MatthiasNieuwenhuisen:groovy-devel
Jan 21, 2014
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -35,10 +35,11 @@ | |
""" | ||
|
||
import rospy | ||
|
||
import rosgraph_msgs | ||
|
||
from python_qt_binding.QtCore import QObject | ||
|
||
CLOCK_TOPIC = "/clock" | ||
|
||
class Player(QObject): | ||
""" | ||
|
@@ -51,6 +52,8 @@ def __init__(self, timeline): | |
self._publishing = set() | ||
self._publishers = {} | ||
|
||
self._publish_clock = False | ||
|
||
def is_publishing(self, topic): | ||
return topic in self._publishing | ||
|
||
|
@@ -71,9 +74,32 @@ def stop_publishing(self, topic): | |
|
||
self._publishing.remove(topic) | ||
|
||
def start_clock_publishing(self): | ||
if CLOCK_TOPIC not in self._publishers: | ||
# Activate clock publishing only if the publisher was created successful | ||
self._publish_clock = self.create_publisher(CLOCK_TOPIC, rosgraph_msgs.msg.Clock()) | ||
|
||
def stop_clock_publishing(self): | ||
self._publish_clock = False | ||
if CLOCK_TOPIC in self._publishers: | ||
self._publishers[CLOCK_TOPIC].unregister() | ||
del self._publishers[CLOCK_TOPIC] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The behavior of start/stop clock should be symmetric. Either both start and stop the publisher or neither of them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved in 4cd8131 |
||
def stop(self): | ||
for topic in list(self._publishing): | ||
self.stop_publishing(topic) | ||
self.stop_clock_publishing() | ||
|
||
def create_publisher(self, topic, msg): | ||
try: | ||
self._publishers[topic] = rospy.Publisher(topic, type(msg)) | ||
return True | ||
except Exception as ex: | ||
# Any errors, stop listening/publishing to this topic | ||
rospy.logerr('Error creating publisher on topic %s for type %s. \nError text: %s' % (topic, str(type(msg)), str(ex))) | ||
if topic != CLOCK_TOPIC: | ||
self.stop_publishing(topic) | ||
return False | ||
|
||
def message_viewed(self, bag, msg_data): | ||
""" | ||
|
@@ -85,16 +111,16 @@ def message_viewed(self, bag, msg_data): | |
if self.timeline.play_speed <= 0.0: | ||
return | ||
|
||
topic, msg, _ = msg_data | ||
topic, msg, clock = msg_data | ||
|
||
# Create publisher if this is the first message on the topic | ||
if topic not in self._publishers: | ||
try: | ||
self._publishers[topic] = rospy.Publisher(topic, type(msg)) | ||
except Exception as ex: | ||
# Any errors, stop listening/publishing to this topic | ||
rospy.logerr('Error creating publisher on topic %s for type %s. \nError text: %s' % (topic, str(type(msg)), str(ex))) | ||
self.stop_publishing(topic) | ||
self.create_publisher(topic, msg) | ||
|
||
if self._publish_clock: | ||
time_msg = rosgraph_msgs.msg.Clock() | ||
time_msg.clock = clock | ||
self._publishers[CLOCK_TOPIC].publish(time_msg) | ||
|
||
self._publishers[topic].publish(msg) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add
rosgraph_msgs
as a run dependency to the package manifest.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 32ed5a4