Aldebaran documentation What's new in NAOqi 2.4.3?


NAOqi Core - Overview | API

What it does

ALBehaviorManager is intended to manage Behaviors. With this module, you can:

  • Load, start, stop Behaviors,
  • Manage default Behaviors,
  • get information about Behaviors.

How it works

Default Behaviors

Some Behaviors can be marked as “Default”, which means they are automatically started when NAOqi launches. ALBehaviorManager allows the user to add or remove such Behaviors, or to launch and stop them.

Behavior name

The name of a Behavior is composed of the package id it is from, and its local Behavior path. Starting a Behavior usually looks like this:



Choregraphe 1.14 generated packages with a single Behavior at its root. Starting such a Behavior looks like this:

  • myBehaviorManagerProxy.startBehavior("my_application/.") or
  • myBehaviorManagerProxy.startBehavior("my_application")

Getting started

The following Python script shows how to use ALBehaviorManager.

To use it:

Step Action
Upload a Behavior from Choregraphe on the robot.

Run the python script giving the NAO’s IP and the Behavior name as argument:

python robotIp behaviorName

#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use ALBehaviorManager Module"""

import qi
import argparse
import sys
import time

def main(session, behavior_name):
    Use ALBehaviorManager Module.
    # Get the service ALBehaviorManager.

    behavior_mng_service = session.service("ALBehaviorManager")

    launchAndStopBehavior(behavior_mng_service, behavior_name)
    defaultBehaviors(behavior_mng_service, behavior_name)

def getBehaviors(behavior_mng_service):
    Know which behaviors are on the robot.

    names = behavior_mng_service.getInstalledBehaviors()
    print "Behaviors on the robot:"
    print names

    names = behavior_mng_service.getRunningBehaviors()
    print "Running behaviors:"
    print names

def launchAndStopBehavior(behavior_mng_service, behavior_name):
    Launch and stop a behavior, if possible.
    # Check that the behavior exists.
    if (behavior_mng_service.isBehaviorInstalled(behavior_name)):
        # Check that it is not already running.
        if (not behavior_mng_service.isBehaviorRunning(behavior_name)):
            # Launch behavior. This is a blocking call, use _async=True if you do not
            # want to wait for the behavior to finish.
            behavior_mng_service.runBehavior(behavior_name, _async=True)
            print "Behavior is already running."

        print "Behavior not found."

    names = behavior_mng_service.getRunningBehaviors()
    print "Running behaviors:"
    print names

    # Stop the behavior.
    if (behavior_mng_service.isBehaviorRunning(behavior_name)):
        print "Behavior is already stopped."

    names = behavior_mng_service.getRunningBehaviors()
    print "Running behaviors:"
    print names

def defaultBehaviors(behavior_mng_service, behavior_name):
    Set a behavior as default and remove it from default behavior.

    # Get default behaviors.
    names = behavior_mng_service.getDefaultBehaviors()
    print "Default behaviors:"
    print names

    # Add behavior to default.

    names = behavior_mng_service.getDefaultBehaviors()
    print "Default behaviors:"
    print names

    # Remove behavior from default.

    names = behavior_mng_service.getDefaultBehaviors()
    print "Default behaviors:"
    print names

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="",
                        help="Robot IP address. On robot or Local Naoqi: use ''.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")
    parser.add_argument("--behavior_name", type=str, required=True,
                        help="Name of the behavior")

    args = parser.parse_args()
    session = qi.Session()
        session.connect("tcp://" + args.ip + ":" + str(args.port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
    main(session, args.behavior_name)