list_topics.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # copyright 2014 UNL Nimbus Lab 
00003 #
00004 #  Licensed under the Apache License, Version 2.0 (the "License");
00005 #     you may not use this file except in compliance with the License.
00006 #    You may obtain a copy of the License at
00007 #  
00008 #        http://www.apache.org/licenses/LICENSE-2.0
00009 #  
00010 #    Unless required by applicable law or agreed to in writing, software
00011 #  distributed under the License is distributed on an "AS IS" BASIS,
00012 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013 #   See the License for the specific language governing permissions and
00014 #   limitations under the License.
00015 import json, sys, re
00016 import rospy, rostopic
00017 from ros_glass_tools.srv import Topics
00018 
00019 
00020 
00021 
00022 class ListTopics:
00023     '''Node to return a list of all running topics when service is called'''
00024     def __init__(self):
00025         rospy.init_node("list_topics_server")
00026         self.serv = rospy.Service("list_topics", Topics, self.list)
00027 
00028 
00029 
00030 
00031     def list(self, request):
00032         '''request for service handler return the list'''
00033         topics = self.get_ros_topics()
00034         return topics
00035 
00036     def get_ros_topics(self):
00037         '''return list of published topics'''
00038         try:
00039             topics = rospy.get_published_topics()
00040             return ' ,'.join((topic[0] for topic in topics))            
00041         except:
00042             rospy.logerr("no core active")
00043             return False 
00044 
00045 
00046 
00047 
00048 if __name__ == '__main__':
00049     lt = ListTopics()
00050     rospy.spin()


ros_glass_tools
Author(s):
autogenerated on Thu Aug 27 2015 14:47:21