$search
00001 00002 # SVN $HeadURL: http://alufr-ros-pkg.googlecode.com/svn/trunk/humanoid_stacks/nao_robot/nao_driver/src/nao_driver/nao_driver_naoqi.py $ 00003 # SVN $Id: nao_driver_naoqi.py 2245 2011-11-28 16:25:56Z hornunga@informatik.uni-freiburg.de $ 00004 00005 00006 # Copyright 2009-2011 Armin Hornung, University of Freiburg 00007 # http://www.ros.org/wiki/nao 00008 # 00009 # Redistribution and use in source and binary forms, with or without 00010 # modification, are permitted provided that the following conditions are met: 00011 # 00012 # # Redistributions of source code must retain the above copyright 00013 # notice, this list of conditions and the following disclaimer. 00014 # # Redistributions in binary form must reproduce the above copyright 00015 # notice, this list of conditions and the following disclaimer in the 00016 # documentation and/or other materials provided with the distribution. 00017 # # Neither the name of the University of Freiburg nor the names of its 00018 # contributors may be used to endorse or promote products derived from 00019 # this software without specific prior written permission. 00020 # 00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00022 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00024 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00025 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00026 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00027 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00028 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00029 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00030 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00031 # POSSIBILITY OF SUCH DAMAGE. 00032 # 00033 00034 import rospy 00035 00036 # import Aldebaran API (must be in PYTHONPATH): 00037 try: 00038 import motion 00039 from naoqi import ALProxy 00040 except ImportError: 00041 rospy.logerr("Error importing NaoQI. Please make sure that Aldebaran's NaoQI API is in your PYTHONPATH.") 00042 exit(1) 00043 00044 class NaoNode(): 00045 def __init__(self): 00046 # get connection from command line: 00047 from optparse import OptionParser 00048 00049 parser = OptionParser() 00050 parser.add_option("--pip", dest="pip", default="127.0.0.1", 00051 help="IP/hostname of parent broker. Default is 127.0.0.1.", metavar="IP") 00052 parser.add_option("--pport", dest="pport", default=9559, 00053 help="port of parent broker. Default is 9559.", metavar="PORT") 00054 00055 (options, args) = parser.parse_args() 00056 self.pip = options.pip 00057 self.pport = int(options.pport) 00058 00059 def connectNaoQi(self, ip, port): 00060 rospy.loginfo("Connecting to NaoQi at %s:%d", ip, port) 00061 00062 00063 self.motionProxy = None 00064 self.memProxy = None 00065 00066 try: 00067 self.motionProxy = ALProxy("ALMotion", ip, port) 00068 self.memProxy = ALProxy("ALMemory", ip, port) 00069 # TODO: check self.memProxy.version() for > 1.6 00070 except RuntimeError, e: 00071 rospy.logerr("Could not create Proxy to ALMotion or ALMemory, exiting. \nException message:\n%s", e) 00072 exit(1) 00073 00074 def getProxy(self, name, warn=True): 00075 proxy = None 00076 00077 try: 00078 proxy = ALProxy(name,self.pip,self.pport) 00079 except RuntimeError,e: 00080 if warn: 00081 rospy.logerr("Could not create Proxy to \"%s\". \nException message:\n%s",name, e) 00082 00083 return proxy