naoqi_gaze_analysis.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #                                                                             
00003 #  Copyright 2016 Aldebaran                                                   
00004 #                                                                             
00005 #  Licensed under the Apache License, Version 2.0 (the "License");            
00006 #  you may not use this file except in compliance with the License.           
00007 #  You may obtain a copy of the License at                                    
00008 #                                                                             
00009 #      http://www.apache.org/licenses/LICENSE-2.0                             
00010 #                                                                             
00011 #  Unless required by applicable law or agreed to in writing, software        
00012 #  distributed under the License is distributed on an "AS IS" BASIS,          
00013 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   
00014 #  See the License for the specific language governing permissions and        
00015 #  limitations under the License.                                             
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()


naoqi_apps
Author(s): Vincent Rabaud
autogenerated on Sat Jun 8 2019 20:30:09