naoqi_listening_movement.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 #                                                                             
00004 #  Copyright 2016 Aldebaran                                                   
00005 #                                                                             
00006 #  Licensed under the Apache License, Version 2.0 (the "License");            
00007 #  you may not use this file except in compliance with the License.           
00008 #  You may obtain a copy of the License at                                    
00009 #                                                                             
00010 #      http://www.apache.org/licenses/LICENSE-2.0                             
00011 #                                                                             
00012 #  Unless required by applicable law or agreed to in writing, software        
00013 #  distributed under the License is distributed on an "AS IS" BASIS,          
00014 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   
00015 #  See the License for the specific language governing permissions and        
00016 #  limitations under the License.                                             
00017 #                                                                             
00018 # 
00019 import rospy
00020 from naoqi_driver.naoqi_node import NaoqiNode
00021 from std_srvs.srv import (
00022     SetBoolResponse,
00023     SetBool,
00024     TriggerResponse,
00025     Trigger
00026 )
00027 from distutils.version import LooseVersion
00028 
00029 class NaoqiListeningMovement(NaoqiNode):
00030     def __init__(self):
00031         NaoqiNode.__init__(self, 'naoqi_listening_movement')
00032         self.connectNaoQi()
00033         
00034         self.SetEnabledSrv = rospy.Service("listening_movement/set_enabled", SetBool, self.handleSetEnabledSrv)
00035         self.IsEnabledSrv = rospy.Service("listening_movement/is_enabled", Trigger, self.handleIsEnabledSrv)
00036         rospy.loginfo("naoqi_listening_movement initialized")
00037 
00038     def connectNaoQi(self):
00039         rospy.loginfo("Connecting to NaoQi at %s:%d", self.pip, self.pport)
00040         self.systemProxy = self.get_proxy("ALSystem")
00041         if self.systemProxy is None:
00042             rospy.logerr("Could not get a proxy to ALSystem")
00043             exit(1)
00044         else:
00045             if LooseVersion(self.systemProxy.systemVersion()) < LooseVersion("2.4"):
00046                 rospy.logerr("Naoqi version of your robot is " + str(self.systemProxy.systemVersion()) + ", which doesn't have a proxy to ALListeningMovement.")
00047                 exit(1)
00048             else:
00049                 self.listeningMovementProxy = self.get_proxy("ALListeningMovement")
00050                 if self.listeningMovementProxy is None:
00051                     rospy.logerr("Could not get a proxy to ALListeningMovement")
00052                     exit(1)
00053     
00054     def handleSetEnabledSrv(self, req):
00055         res = SetBoolResponse()
00056         res.success = False
00057         try:
00058             self.listeningMovementProxy.setEnabled(req.data)
00059             res.success = True
00060             return res
00061         except RuntimeError, e:
00062             rospy.logerr("Exception caught:\n%s", e)
00063             return res
00064 
00065     def handleIsEnabledSrv(self, req):
00066         try:
00067             res = TriggerResponse()
00068             res.success = self.listeningMovementProxy.isEnabled()
00069             return  res
00070         except RuntimeError, e:
00071             rospy.logerr("Exception caught:\n%s", e)
00072             return None
00073 
00074 if __name__ == '__main__':
00075     listening_movement = NaoqiListeningMovement()
00076     rospy.spin()


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