Overview | API
ALBehaviorManager is intended to manage behaviors. With this module, you can:
Some behaviors can be marked as “Default”, which means they will be automatically started when NAOqi launches. ALBehaviorManager allows the user to add or remove such behaviors, or to launch and stop them.
The following Python script shows how to use ALBehaviorManager. To use it, upload a behavior from Choregraphe on the robot. Then run the python script giving the NAO’s IP and the behavior name as argument:
python albehaviormanager_example.py robotIp behaviorName
import sys
import time
from naoqi import ALProxy
def main(robotIP, behaviorName):
# Create proxy to ALBehaviorManager
managerProxy = ALProxy("ALBehaviorManager", robotIP, 9559)
getBehaviors(managerProxy)
launchAndStopBehavior(managerProxy, behaviorName)
defaultBehaviors(managerProxy, behaviorName)
def getBehaviors(managerProxy):
''' Know which behaviors are on the robot '''
names = managerProxy.getInstalledBehaviors()
print "Behaviors on the robot:"
print names
names = managerProxy.getRunningBehaviors()
print "Running behaviors:"
print names
def launchAndStopBehavior(managerProxy, behaviorName):
''' Launch and stop a behavior, if possible. '''
# Check that the behavior exists.
if (managerProxy.isBehaviorInstalled(behaviorName)):
# Check that it is not already running.
if (not managerProxy.isBehaviorRunning(behaviorName)):
# Launch behavior. This is a blocking call, use post if you do not
# want to wait for the behavior to finish.
managerProxy.post.runBehavior(behaviorName)
time.sleep(0.5)
else:
print "Behavior is already running."
else:
print "Behavior not found."
return
names = managerProxy.getRunningBehaviors()
print "Running behaviors:"
print names
# Stop the behavior.
if (managerProxy.isBehaviorRunning(behaviorName)):
managerProxy.stopBehavior(behaviorName)
time.sleep(1.0)
else:
print "Behavior is already stopped."
names = managerProxy.getRunningBehaviors()
print "Running behaviors:"
print names
def defaultBehaviors(managerProxy, behaviorName):
''' Set a behavior as default and remove it from default behavior. '''
# Get default behaviors.
names = managerProxy.getDefaultBehaviors()
print "Default behaviors:"
print names
# Add behavior to default.
managerProxy.addDefaultBehavior(behaviorName)
names = managerProxy.getDefaultBehaviors()
print "Default behaviors:"
print names
# Remove behavior from default.
managerProxy.removeDefaultBehavior(behaviorName)
names = managerProxy.getDefaultBehaviors()
print "Default behaviors:"
print names
if __name__ == "__main__":
if (len(sys.argv) < 3):
print "Usage python albehaviormanager_example.py robotIP behaviorName"
sys.exit(1)
main(sys.argv[1], sys.argv[2])