Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import logging
00018
00019 from rosgraph_msgs.msg import Log
00020 import rospy
00021
00022 from naoqi_driver.naoqi_node import NaoqiNode
00023
00024
00025 LEVELS = [Log.DEBUG, Log.FATAL, Log.ERROR, Log.WARN, Log.INFO, Log.DEBUG, Log.DEBUG]
00026 ROSOUT_PUB = rospy.topics.Publisher('/rosout', Log, latch=True, queue_size=100)
00027
00028 def onMessageCallback(msg):
00029 """
00030 Given a NAOqi dict message, publish it in /rosout
00031 :param msg: dict corresponding to a NAOqi log message
00032 """
00033 file, function, line = msg['source'].split(':')
00034 if line:
00035 line = int(line)
00036
00037 l = Log(level=LEVELS[msg['level']], name=str(msg['category']), msg=msg['message'], file=file, line=line, function=function)
00038 l.header.stamp = rospy.Time(msg['timestamp']['tv_sec'], msg['timestamp']['tv_usec'])
00039 ROSOUT_PUB.publish(l)
00040
00041 class NaoqiLogger(NaoqiNode):
00042
00043 NODE_NAME = 'nao_logger'
00044
00045 def __init__( self ):
00046
00047 NaoqiNode.__init__( self, self.NODE_NAME )
00048
00049 from distutils.version import LooseVersion
00050 if self.get_version() < LooseVersion('2.0.0'):
00051 rospy.loginfo('The NAOqi version is inferior to 2.0, hence no log bridge possible')
00052 exit(0)
00053
00054 rospy.init_node( self.NODE_NAME )
00055
00056
00057 import qi
00058 self.session = qi.Session()
00059 self.session.connect("tcp://%s:%s" % (self.pip, self.pport))
00060 self.logManager = self.session.service("LogManager")
00061
00062 self.listener = self.logManager.getListener()
00063 self.listener.onLogMessage.connect(onMessageCallback)
00064 rospy.loginfo('Logger initialized')
00065
00066 if __name__ == '__main__':
00067 try:
00068 nao_logger = NaoqiLogger()
00069 except RuntimeError as e:
00070 rospy.logerr('Something went wrong: %s' % str(e) )
00071
00072 rospy.spin()
naoqi_driver_py
Author(s): Armin Hornung, Armin Hornung, Stefan Osswald, Daniel Maier, Miguel Sarabia, Severin Lemaignan
autogenerated on Sat Jun 8 2019 20:30:13