41 from naoqi_bridge_msgs.msg
import RunBehaviorAction
43 from naoqi_bridge_msgs.srv
import (
44 GetInstalledBehaviors,
45 GetInstalledBehaviorsResponse,
50 NODE_NAME =
"nao_behaviors" 55 NaoqiNode.__init__( self, self.
NODE_NAME )
59 self.
lock = threading.RLock()
66 "get_installed_behaviors",
67 GetInstalledBehaviors,
79 self.actionlibServer.register_preempt_callback( self.
stopBehavior )
81 self.actionlibServer.start()
84 result = self.behaviorProxy.getInstalledBehaviors()
85 return GetInstalledBehaviorsResponse( result )
91 "Execution of behavior: '{}' requested".format(request.behavior))
94 if not request.behavior
in self.behaviorProxy.getInstalledBehaviors():
95 error_msg =
"Behavior '{}' not installed".format(request.behavior)
96 self.actionlibServer.set_aborted(text = error_msg)
97 rospy.logdebug(error_msg)
102 if self.actionlibServer.is_preempt_requested():
103 self.actionlibServer.set_preempted()
104 rospy.logdebug(
"Behavior execution preempted before it started")
110 taskID = self.behaviorProxy.post.runBehavior( self.
behavior )
113 rospy.logdebug(
"Waiting for behavior execution to complete")
114 self.behaviorProxy.wait( taskID, 0 )
120 if self.actionlibServer.is_preempt_requested() :
121 self.actionlibServer.set_preempted()
122 rospy.logdebug(
"Behavior execution preempted")
125 self.actionlibServer.set_succeeded()
126 rospy.logdebug(
"Behavior execution succeeded")
130 if self.
behavior and self.actionlibServer.is_active() :
131 self.behaviorProxy.stopBehavior( self.
behavior )
134 if __name__ ==
'__main__':
136 rospy.loginfo( node.NODE_NAME +
" running..." )
138 rospy.loginfo( node.NODE_NAME +
" stopped." )
getInstalledBehaviorsService
def runBehavior(self, request)
def getInstalledBehaviors(self, request)
def get_proxy(self, name, warn=True)