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 import distutils
00036
00037 from naoqi_driver.naoqi_node import NaoqiNode
00038 from naoqi import (ALBroker, ALProxy, ALModule)
00039
00040 from std_srvs.srv import( Empty, EmptyResponse )
00041
00042 class NaoALife(NaoqiNode):
00043
00044 NODE_NAME = "nao_alife"
00045
00046 def __init__( self ):
00047
00048
00049 NaoqiNode.__init__( self, self.NODE_NAME )
00050 if self.get_version() < distutils.version.LooseVersion('2.0'):
00051 rospy.logwarn("{} is only available on NaoQi version 2.0 or higher, your version is {}".format(self.NODE_NAME, self.get_version()))
00052 exit(1)
00053
00054
00055 self.proxy = self.get_proxy( "ALAutonomousLife" )
00056
00057
00058 self.disabled_srv = rospy.Service("~disabled", Empty, self.disabled )
00059 self.solitary_srv = rospy.Service("~solitary", Empty, self.solitary )
00060 self.interactive_srv = rospy.Service("~interactive", Empty, self.interactive )
00061 self.safeguard_srv = rospy.Service("~safeguard", Empty, self.safeguard )
00062
00063 def setstate( self, state):
00064 try:
00065 self.proxy.setState( state )
00066 except Exception as e:
00067 rospy.logwarn("Could not transit from " + self.proxy.getState() + " to " + state)
00068 rospy.logerr(e)
00069 return EmptyResponse()
00070
00071 def disabled( self, request = None ):
00072 return self.setstate('disabled')
00073 def solitary( self, request = None ):
00074 return self.setstate('solitary')
00075 def interactive( self, request = None ):
00076 return self.setstate('interactive')
00077 def safeguard( self, request = None ):
00078 return self.setstate('safeguard')
00079
00080 if __name__ == '__main__':
00081 node = NaoALife()
00082 rospy.loginfo( node.NODE_NAME + " running..." )
00083 rospy.spin()
00084 rospy.loginfo( node.NODE_NAME + " stopped." )
00085 exit(0)