Skip to content

Commit b2f4d52

Browse files
author
Enrique Fernández Perdomo
committed
Merge pull request #14 from clearpathrobotics/plot_not_node
Make plot.py not a ROS node
2 parents 0b29632 + 9a0b666 commit b2f4d52

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

bag_tools/scripts/plot.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
# @todo split all this into libraries
3333
from __future__ import print_function
3434

35-
import rospy
3635
import roslib
3736
import roslib.msgs
3837
import rosbag
@@ -426,19 +425,18 @@ def __init__(self, bags, topics, plot_arrays=True, plot_headers=True, plot_forma
426425

427426
# @todo support multiple bags, for now we take the first one only
428427
if len(self._bags) > 1:
429-
rospy.logwarn("Does NOT support multiple bags yet! Only first bag will be used.")
428+
print("Does NOT support multiple bags yet! Only first bag will be used.", file=sys.stderr)
430429
bag = self._bags[0]
431430

432-
rospy.loginfo("Processing %s ..." % bag)
431+
print("Processing %s ..." % bag)
433432

434433
# Retrieve/Expand plottable topic fields:
435434
plottable_topics = []
436435
for topic in topics:
437436
plottable_topics += self.get_plot_fields(topic)[0]
438437

439438
if len(plottable_topics) == 0:
440-
rospy.logwarn("No topic/field can be plotted!")
441-
rospy.signal_shutdown("No topic/field can be plotted!")
439+
print("No topic/field can be plotted!", file=sys.stderr)
442440
return
443441

444442
# Create topic evaluators:
@@ -478,12 +476,10 @@ def __init__(self, bags, topics, plot_arrays=True, plot_headers=True, plot_forma
478476

479477
times[topic].append(time.to_sec())
480478
except IOError as e:
481-
rospy.logerr('Failed to open bag file %s: %s!' % (bag, e.strerror))
482-
rospy.signal_shutdown('Failed to open bag file %s: %s!' % (bag, e.strerror))
479+
print('Failed to open bag file %s: %s!' % (bag, e.strerror), file=sys.stderr)
483480
return
484481
except rosbag.ROSBagException as e:
485-
rospy.logerr('Failed to read bag file %s: %s!' % (bag, e.message))
486-
rospy.signal_shutdown('Failed to read bag file %s: %s!' % (bag, e.message))
482+
print('Failed to read bag file %s: %s!' % (bag, e.message), file=sys.stderr)
487483
return
488484

489485
min_time = []
@@ -517,7 +513,7 @@ def __init__(self, bags, topics, plot_arrays=True, plot_headers=True, plot_forma
517513

518514
plt.close(fig)
519515
except OverflowError as e:
520-
rospy.logerr('Failed to save plot as %s image file (try other format, e.g. svg): %s', self._plot_format, e.message)
516+
print('Failed to save plot as %s image file (try other format, e.g. svg): %s', self._plot_format, e.message, file=sys.stderr)
521517

522518
def get_plot_fields(self, topic_name):
523519
"""
@@ -598,8 +594,6 @@ def get_plot_fields(self, topic_name):
598594

599595

600596
if __name__ == "__main__":
601-
rospy.init_node('plot', anonymous=True)
602-
603597
parser = argparse.ArgumentParser(
604598
description='Plots a list of topics into a single axis. '
605599
'All the numeric fields are plotted in different series. '

0 commit comments

Comments
 (0)