nao_alife.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #
4 # ROS node to interface with Naoqi Autonomous Life modules
5 # Tested with NaoQI: 2.1
6 #
7 # Copyright (c) 2014, Kei Okada
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are met:
11 #
12 # # Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # # Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 # # Neither the name of the Imperial College London nor the names of its
18 # contributors may be used to endorse or promote products derived from
19 # this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 #
33 
34 import rospy
35 import distutils
36 
37 from naoqi_driver.naoqi_node import NaoqiNode
38 from naoqi import (ALBroker, ALProxy, ALModule)
39 
40 from std_srvs.srv import( Empty, EmptyResponse )
41 
43  #This should be treated as a constant
44  NODE_NAME = "nao_alife"
45 
46  def __init__( self ):
47 
48  #Initialisation
49  NaoqiNode.__init__( self, self.NODE_NAME )
50  if self.get_version() < distutils.version.LooseVersion('2.0'):
51  rospy.logwarn("{} is only available on NaoQi version 2.0 or higher, your version is {}".format(self.NODE_NAME, self.get_version()))
52  exit(1)
53 
54  #Proxy to interface with LEDs
55  self.proxy = self.get_proxy( "ALAutonomousLife" )
56 
57  # Register ROS services
58  self.disabled_srv = rospy.Service("~disabled", Empty, self.disabled )
59  self.solitary_srv = rospy.Service("~solitary", Empty, self.solitary )
60  self.interactive_srv = rospy.Service("~interactive", Empty, self.interactive )
61  self.safeguard_srv = rospy.Service("~safeguard", Empty, self.safeguard )
62 
63  def setstate( self, state):
64  try:
65  self.proxy.setState( state )
66  except Exception as e:
67  rospy.logwarn("Could not transit from " + self.proxy.getState() + " to " + state)
68  rospy.logerr(e)
69  return EmptyResponse()
70 
71  def disabled( self, request = None ):
72  return self.setstate('disabled')
73  def solitary( self, request = None ):
74  return self.setstate('solitary')
75  def interactive( self, request = None ):
76  return self.setstate('interactive')
77  def safeguard( self, request = None ):
78  return self.setstate('safeguard')
79 
80 if __name__ == '__main__':
81  node = NaoALife()
82  rospy.loginfo( node.NODE_NAME + " running..." )
83  rospy.spin()
84  rospy.loginfo( node.NODE_NAME + " stopped." )
85  exit(0)
def disabled(self, request=None)
Definition: nao_alife.py:71
def solitary(self, request=None)
Definition: nao_alife.py:73
def safeguard(self, request=None)
Definition: nao_alife.py:77
def setstate(self, state)
Definition: nao_alife.py:63
def __init__(self)
Definition: nao_alife.py:46
def interactive(self, request=None)
Definition: nao_alife.py:75
def get_proxy(self, name, warn=True)


nao_apps
Author(s):
autogenerated on Mon Jun 10 2019 14:04:55