Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 import rospy
00035
00036
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
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
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