naoqi_gaze_analysis.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2016 Aldebaran
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 #
18 import rospy
19 from naoqi_driver.naoqi_node import NaoqiNode
20 from naoqi_bridge_msgs.srv import (
21  SetFloatResponse,
22  SetFloat,
23  GetFloatResponse,
24  GetFloat)
25 
26 class NaoqiGazeAnalysis (NaoqiNode):
27  def __init__(self):
28  NaoqiNode.__init__(self, 'naoqi_gaze_analysis')
29  self.connectNaoQi()
30  self.setToleranceSrv = rospy.Service("set_gaze_analysis_tolerance", SetFloat, self.handleSetGazeAnalysisTolerance)
31  self.getToleranceSrv = rospy.Service("get_gaze_analysis_tolerance", GetFloat, self.handleGetGazeAnalysisTolerance)
32  rospy.loginfo("naoqi_gaze_analysis is initialized")
33 
34  def connectNaoQi(self):
35  rospy.loginfo("Connecting to NaoQi at %s:%d", self.pip, self.pport)
36  self.gazeProxy = self.get_proxy("ALGazeAnalysis")
37  if self.gazeProxy is None:
38  rospy.logerr("Could not get a proxy to ALGazeAnalysis")
39  exit(1)
40 
42  res = SetFloatResponse()
43  res.success = False
44  try:
45  self.gazeProxy.setTolerance(req.data)
46  res.success = True
47  return res
48  except RuntimeError, e:
49  rospy.logerr("Exception caught:\n%s", e)
50  return res
51 
53  try:
54  res = GetFloatResponse()
55  res.data = self.gazeProxy.getTolerance()
56  return res
57  except RuntimeError, e:
58  rospy.logerr("Exception caught:\n%s", e)
59  return res
60 
61 if __name__ == '__main__':
62  gaze_analysis = NaoqiGazeAnalysis()
63  rospy.spin()


naoqi_apps
Author(s): Vincent Rabaud
autogenerated on Thu Jul 16 2020 03:18:28