naoqi_listening_movement.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #
4 # Copyright 2016 Aldebaran
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 #
19 import rospy
20 from naoqi_driver.naoqi_node import NaoqiNode
21 from std_srvs.srv import (
22  SetBoolResponse,
23  SetBool,
24  TriggerResponse,
25  Trigger
26 )
27 from distutils.version import LooseVersion
28 
29 class NaoqiListeningMovement(NaoqiNode):
30  def __init__(self):
31  NaoqiNode.__init__(self, 'naoqi_listening_movement')
32  self.connectNaoQi()
33 
34  self.SetEnabledSrv = rospy.Service("listening_movement/set_enabled", SetBool, self.handleSetEnabledSrv)
35  self.IsEnabledSrv = rospy.Service("listening_movement/is_enabled", Trigger, self.handleIsEnabledSrv)
36  rospy.loginfo("naoqi_listening_movement initialized")
37 
38  def connectNaoQi(self):
39  rospy.loginfo("Connecting to NaoQi at %s:%d", self.pip, self.pport)
40  self.systemProxy = self.get_proxy("ALSystem")
41  if self.systemProxy is None:
42  rospy.logerr("Could not get a proxy to ALSystem")
43  exit(1)
44  else:
45  if LooseVersion(self.systemProxy.systemVersion()) < LooseVersion("2.4"):
46  rospy.logerr("Naoqi version of your robot is " + str(self.systemProxy.systemVersion()) + ", which doesn't have a proxy to ALListeningMovement.")
47  exit(1)
48  else:
49  self.listeningMovementProxy = self.get_proxy("ALListeningMovement")
50  if self.listeningMovementProxy is None:
51  rospy.logerr("Could not get a proxy to ALListeningMovement")
52  exit(1)
53 
54  def handleSetEnabledSrv(self, req):
55  res = SetBoolResponse()
56  res.success = False
57  try:
58  self.listeningMovementProxy.setEnabled(req.data)
59  res.success = True
60  return res
61  except RuntimeError, e:
62  rospy.logerr("Exception caught:\n%s", e)
63  return res
64 
65  def handleIsEnabledSrv(self, req):
66  try:
67  res = TriggerResponse()
68  res.success = self.listeningMovementProxy.isEnabled()
69  return res
70  except RuntimeError, e:
71  rospy.logerr("Exception caught:\n%s", e)
72  return None
73 
74 if __name__ == '__main__':
75  listening_movement = NaoqiListeningMovement()
76  rospy.spin()


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