polygon_array_to_polygon.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 from __future__ import absolute_import
00004 from __future__ import division
00005 from __future__ import print_function
00006 
00007 import dynamic_reconfigure.server
00008 from geometry_msgs.msg import PolygonStamped
00009 from jsk_recognition_msgs.msg import PolygonArray
00010 from jsk_topic_tools import ConnectionBasedTransport
00011 from jsk_topic_tools.log_utils import logerr_throttle
00012 from jsk_recognition_utils.cfg import PolygonArrayToPolygonConfig
00013 import rospy
00014 
00015 
00016 class PolygonArrayToPolygon(ConnectionBasedTransport):
00017 
00018     def __init__(self):
00019         super(self.__class__, self).__init__()
00020         self.pub = self.advertise('~output', PolygonStamped, queue_size=1)
00021         dynamic_reconfigure.server.Server(PolygonArrayToPolygonConfig,
00022                                           self._config_callback)
00023 
00024     def subscribe(self):
00025         self.sub = rospy.Subscriber('~input', PolygonArray, self._convert)
00026 
00027     def unsubscribe(self):
00028         self.sub.unregister()
00029 
00030     def _config_callback(self, config, level):
00031         self.index = config.index
00032         return config
00033 
00034     def _convert(self, msg):
00035         polygon_msg = PolygonStamped()
00036         polygon_msg.header = msg.header
00037         if self.index < 0:
00038             return
00039         elif self.index < len(msg.polygons):
00040             polygon_msg = msg.polygons[self.index]
00041             self.pub.publish(polygon_msg)
00042         else:
00043             logerr_throttle(10,
00044                             'Invalid index {} is specified '
00045                             'for polygon array whose size is {}'
00046                             .format(self.index, len(msg.polygons)))
00047 
00048 
00049 if __name__ == '__main__':
00050     rospy.init_node('polygon_array_to_polygon')
00051     PolygonArrayToPolygon()
00052     rospy.spin()


jsk_recognition_utils
Author(s):
autogenerated on Sun Oct 8 2017 02:42:48