SoftBank Robotics documentation What's new in NAOqi 2.5?

ALAnimationPlayer API

NAOqi Motion - Overview | API | Tutorials | Advanced


Namespace : AL

Method list

class ALAnimationPlayerProxy

This is a naoqi2 service.

ALMemory Keys list

Methods

qi::Future<void> ALAnimationPlayerProxy::run(const std::string& path)

Runs an animation.

Parameters:
  • path – Path to the animation. For further details, see: Animation Paths
Returns:

A future to cancel the animation.

Calling the method asynchronously allows to cancel the animation by canceling the future.

qi::Future<void> ALAnimationPlayerProxy::runTag(const std::string& tag)

There are two overloads of this function:

Runs an animation randomly chosen among all the animations with a specified tag.

Parameters:
  • tag – Tag of animations. For further details, see: Tags
Returns:

A future to cancel the animation.

qi::Future<void> ALAnimationPlayerProxy::runTag(const std::string& path, const std::string& tag)

Runs an animation randomly chosen among all the animations, contained in a specified path, and with a specified tag.

Parameters:
  • path – Path to look for the animations.
  • tag – Tag of animations. For further details, see: Tags
Returns:

A future to cancel the animation.

void ALAnimationPlayerProxy::declarePathForTags(const std::string& path)

Allow using animations contained in the specified path as tagged animations.

Parameters:
  • path – Path that contains tagged animations. If [posture] is in the path it will be replaced by all handled posture families (not only the current one).

alanimationplayer_tutorial_declarePathForTags.py

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

"""Example: Use declarePathForTags Method"""

import qi
import argparse
import sys


def main(session):
    """
    This example uses the declarePathForTags method.
    """
    # Get the service ALAnimationPlayer.

    animation_player_service = session.service("ALAnimationPlayer")

    # With this command we declare a package of animations having the uid "myanimlib", structured as follow:
    #   Nao/Stand/...
    #       Sit/...
    #       SitOnPod/...
    #   Pepper/Stand/...
    animation_player_service.declarePathForTags("myanimlib/[robot]/[posture]/")


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

    args = parser.parse_args()
    session = qi.Session()
    try:
        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.")
        sys.exit(1)
    main(session)

To execute this script, type:

python alanimationplayer_tutorial_declarePathForTags.py --qi-url=tcp://<robot name or robot id>:9559
void ALAnimationPlayerProxy::addTagForAnimations(const TagForAnimations& tagsToAnimations)

Associates tags to animations.

Parameters:
  • tagsToAnimations – Map of tag to animations. (in C++ it’s std::map<std::string, std::vector<std::string> >)

alanimationplayer_tutorial_addTagForAnimations.py

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

"""Example: Use addTagForAnimations Method"""

import qi
import argparse
import sys


def main(session):
    """
    This example uses the addTagForAnimations method.
    """
    # Get the service ALAnimationPlayer.

    animation_player_service = session.service("ALAnimationPlayer")
    tagToAnims = {}
    tagToAnims["myNewTag1"] = ["animations/Stand/Gestures/Hey_1", "animations/Stand/Gestures/Hey_3"]
    tagToAnims["myNewTag2"] = ["animations/Stand/Gestures/WhatSThis_2"]
    animation_player_service.addTagForAnimations(tagToAnims)


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

    args = parser.parse_args()
    session = qi.Session()
    try:
        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.")
        sys.exit(1)
    main(session)

To execute this script, type:

python alanimationplayer_tutorial_addTagForAnimations.py --qi-url=tcp://<robot name or robot id>:9559
void ALAnimationPlayerProxy::reset()

Go back to the default ALAnimationPlayer’s configuration. Only the “Animation Library” will be declared as an animation package and all the links between tags and animations dynamically added will be removed.