Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import rospy
00019 from naoqi_driver.naoqi_node import NaoqiNode
00020 from naoqi_bridge_msgs.srv import (
00021 SetFloatResponse,
00022 SetFloat,
00023 GetFloatResponse,
00024 GetFloat)
00025
00026 class NaoqiGazeAnalysis (NaoqiNode):
00027 def __init__(self):
00028 NaoqiNode.__init__(self, 'naoqi_gaze_analysis')
00029 self.connectNaoQi()
00030 self.setToleranceSrv = rospy.Service("set_gaze_analysis_tolerance", SetFloat, self.handleSetGazeAnalysisTolerance)
00031 self.getToleranceSrv = rospy.Service("get_gaze_analysis_tolerance", GetFloat, self.handleGetGazeAnalysisTolerance)
00032 rospy.loginfo("naoqi_gaze_analysis is initialized")
00033
00034 def connectNaoQi(self):
00035 rospy.loginfo("Connecting to NaoQi at %s:%d", self.pip, self.pport)
00036 self.gazeProxy = self.get_proxy("ALGazeAnalysis")
00037 if self.gazeProxy is None:
00038 rospy.logerr("Could not get a proxy to ALGazeAnalysis")
00039 exit(1)
00040
00041 def handleSetGazeAnalysisTolerance(self, req):
00042 res = SetFloatResponse()
00043 res.success = False
00044 try:
00045 self.gazeProxy.setTolerance(req.data)
00046 res.success = True
00047 return res
00048 except RuntimeError, e:
00049 rospy.logerr("Exception caught:\n%s", e)
00050 return res
00051
00052 def handleGetGazeAnalysisTolerance(self, req):
00053 try:
00054 res = GetFloatResponse()
00055 res.data = self.gazeProxy.getTolerance()
00056 return res
00057 except RuntimeError, e:
00058 rospy.logerr("Exception caught:\n%s", e)
00059 return res
00060
00061 if __name__ == '__main__':
00062 gaze_analysis = NaoqiGazeAnalysis()
00063 rospy.spin()