nao_alife.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 #
00004 # ROS node to interface with Naoqi Autonomous Life modules
00005 # Tested with NaoQI: 2.1
00006 #
00007 # Copyright (c) 2014, Kei Okada
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 Imperial College London 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 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     #This should be treated as a constant
00044     NODE_NAME = "nao_alife"
00045 
00046     def __init__( self ):
00047 
00048         #Initialisation
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         #Proxy to interface with LEDs
00055         self.proxy = self.get_proxy( "ALAutonomousLife" )
00056 
00057         # Register ROS services
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)


nao_apps
Author(s):
autogenerated on Sat Jun 8 2019 20:38:35