NAOQI API之學(xué)習(xí)筆記

NAOQI OS是軟銀pepper和nao機(jī)器人的核心操作系統(tǒng),NAOQI API提供了訪問機(jī)器人的各種傳感器設(shè)備接口以及應(yīng)用接口。

NAOqi Core之ALBehaviourManager

ALBehaviorManager旨在管理行為(Behaviour)。有了這個(gè)模塊,你可以:

  • 加載,啟動(dòng),停止一個(gè)行為;
  • 管理默認(rèn)行為;
  • 獲取有關(guān)行為的信息;

默認(rèn)行為:一些行為可以被標(biāo)記為“默認(rèn)”,這意味著它們?cè)贜AOqi啟動(dòng)時(shí)自動(dòng)啟動(dòng)。 ALBehaviorManager允許用戶添加或刪除這些行為,或啟動(dòng)和停止它們。

行為名字:一個(gè)行為的名稱由其來包ID及其本地路徑組成。開始行為通常如下所示:
myBehaviorManagerProxy.startBehavior("my_application/a_behavior")

示例:albehaviormanager_example.py


#! /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")

    getBehaviors(behavior_mng_service)
    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)
            time.sleep(0.5)
        else:
            print "Behavior is already running."

    else:
        print "Behavior not found."
    return

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

    # Stop the behavior.
    if (behavior_mng_service.isBehaviorRunning(behavior_name)):
        behavior_mng_service.stopBehavior(behavior_name)
        time.sleep(1.0)
    else:
        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.
    behavior_mng_service.addDefaultBehavior(behavior_name)

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

    # Remove behavior from default.
    behavior_mng_service.removeDefaultBehavior(behavior_name)

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


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")
    parser.add_argument("--behavior_name", type=str, required=True,
                        help="Name of the behavior")

    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, args.behavior_name)


示例運(yùn)行步驟:運(yùn)行python腳本,給出NAO的IP和行為名稱作為參數(shù),如下
python albehaviormanager_example.py robotIp behaviorName

運(yùn)行結(jié)果:

[W] 1496392380.189819 5379 qi.path.sdklayout: No Application was created, trying to deduce paths
Behaviors on the robot:
['animationMode', 'animations/LED/CircleEyes', 'animations/Stand/BodyTalk/Listening/Listening_1', 'animations/Stand/BodyTalk/Listening/Listening_2', 'animations/Stand/BodyTalk/Listening/Listening_3', 'animations/Stand/BodyTalk/Listening/Listening_4', 'animations/Stand/BodyTalk/Listening/Listening_5', 'animations/Stand/BodyTalk/Listening/Listening_6', 'animations/Stand/BodyTalk/Listening/Listening_7', 'animations/Stand/BodyTalk/Speaking/BodyTalk_1', 'animations/Stand/BodyTalk/Speaking/BodyTalk_10', 'animations/Stand/BodyTalk/Speaking/BodyTalk_11', 'animations/Stand/BodyTalk/Speaking/BodyTalk_12', 'animations/Stand/BodyTalk/Speaking/BodyTalk_13', 'animations/Stand/BodyTalk/Speaking/BodyTalk_14', 'animations/Stand/BodyTalk/Speaking/BodyTalk_15', 'animations/Stand/BodyTalk/Speaking/BodyTalk_16', 'animations/Stand/BodyTalk/Speaking/BodyTalk_2', 'animations/Stand/BodyTalk/Speaking/BodyTalk_3', 'animations/Stand/BodyTalk/Speaking/BodyTalk_4', 'animations/Stand/BodyTalk/Speaking/BodyTalk_5', 'animations/Stand/BodyTalk/Speaking/BodyTalk_6', 'animations/Stand/BodyTalk/Speaking/BodyTalk_7', 'animations/Stand/BodyTalk/Speaking/BodyTalk_8', 'animations/Stand/BodyTalk/Speaking/BodyTalk_9', 'animations/Stand/BodyTalk/Thinking/Remember_1', 'animations/Stand/BodyTalk/Thinking/Remember_2', 'animations/Stand/BodyTalk/Thinking/Remember_3', 'animations/Stand/BodyTalk/Thinking/ThinkingLoop_1', 'animations/Stand/BodyTalk/Thinking/ThinkingLoop_2', 'animations/Stand/Emotions/Negative/Angry_1', 'animations/Stand/Emotions/Negative/Angry_2', 'animations/Stand/Emotions/Negative/Angry_3', 'animations/Stand/Emotions/Negative/Angry_4', 'animations/Stand/Emotions/Negative/Anxious_1', 'animations/Stand/Emotions/Negative/Bored_1', 'animations/Stand/Emotions/Negative/Bored_2', 'animations/Stand/Emotions/Negative/Disappointed_1', 'animations/Stand/Emotions/Negative/Exhausted_1', 'animations/Stand/Emotions/Negative/Exhausted_2', 'animations/Stand/Emotions/Negative/Fear_1', 'animations/Stand/Emotions/Negative/Fear_2', 'animations/Stand/Emotions/Negative/Fearful_1', 'animations/Stand/Emotions/Negative/Frustrated_1', 'animations/Stand/Emotions/Negative/Humiliated_1', 'animations/Stand/Emotions/Negative/Hurt_1', 'animations/Stand/Emotions/Negative/Hurt_2', 'animations/Stand/Emotions/Negative/Late_1', 'animations/Stand/Emotions/Negative/Sad_1', 'animations/Stand/Emotions/Negative/Sad_2', 'animations/Stand/Emotions/Negative/Shocked_1', 'animations/Stand/Emotions/Negative/Sorry_1', 'animations/Stand/Emotions/Negative/Surprise_1', 'animations/Stand/Emotions/Negative/Surprise_2', 'animations/Stand/Emotions/Negative/Surprise_3', 'animations/Stand/Emotions/Neutral/Alienated_1', 'animations/Stand/Emotions/Neutral/AskForAttention_1', 'animations/Stand/Emotions/Neutral/AskForAttention_2', 'animations/Stand/Emotions/Neutral/AskForAttention_3', 'animations/Stand/Emotions/Neutral/Cautious_1', 'animations/Stand/Emotions/Neutral/Confused_1', 'animations/Stand/Emotions/Neutral/Determined_1', 'animations/Stand/Emotions/Neutral/Embarrassed_1', 'animations/Stand/Emotions/Neutral/Hesitation_1', 'animations/Stand/Emotions/Neutral/Innocent_1', 'animations/Stand/Emotions/Neutral/Lonely_1', 'animations/Stand/Emotions/Neutral/Mischievous_1', 'animations/Stand/Emotions/Neutral/Puzzled_1', 'animations/Stand/Emotions/Neutral/Sneeze', 'animations/Stand/Emotions/Neutral/Stubborn_1', 'animations/Stand/Emotions/Neutral/Suspicious_1', 'animations/Stand/Emotions/Positive/Amused_1', 'animations/Stand/Emotions/Positive/Confident_1', 'animations/Stand/Emotions/Positive/Ecstatic_1', 'animations/Stand/Emotions/Positive/Enthusiastic_1', 'animations/Stand/Emotions/Positive/Excited_1', 'animations/Stand/Emotions/Positive/Excited_2', 'animations/Stand/Emotions/Positive/Excited_3', 'animations/Stand/Emotions/Positive/Happy_1', 'animations/Stand/Emotions/Positive/Happy_2', 'animations/Stand/Emotions/Positive/Happy_3', 'animations/Stand/Emotions/Positive/Happy_4', 'animations/Stand/Emotions/Positive/Hungry_1', 'animations/Stand/Emotions/Positive/Hysterical_1', 'animations/Stand/Emotions/Positive/Interested_1', 'animations/Stand/Emotions/Positive/Interested_2', 'animations/Stand/Emotions/Positive/Laugh_1', 'animations/Stand/Emotions/Positive/Laugh_2', 'animations/Stand/Emotions/Positive/Laugh_3', 'animations/Stand/Emotions/Positive/Mocker_1', 'animations/Stand/Emotions/Positive/Optimistic_1', 'animations/Stand/Emotions/Positive/Peaceful_1', 'animations/Stand/Emotions/Positive/Proud_1', 'animations/Stand/Emotions/Positive/Proud_2', 'animations/Stand/Emotions/Positive/Proud_3', 'animations/Stand/Emotions/Positive/Relieved_1', 'animations/Stand/Emotions/Positive/Shy_1', 'animations/Stand/Emotions/Positive/Shy_2', 'animations/Stand/Emotions/Positive/Sure_1', 'animations/Stand/Emotions/Positive/Winner_1', 'animations/Stand/Emotions/Positive/Winner_2', 'animations/Stand/Gestures/Angry_1', 'animations/Stand/Gestures/Angry_2', 'animations/Stand/Gestures/Angry_3', 'animations/Stand/Gestures/BowShort_1', 'animations/Stand/Gestures/BowShort_2', 'animations/Stand/Gestures/BowShort_3', 'animations/Stand/Gestures/But_1', 'animations/Stand/Gestures/CalmDown_1', 'animations/Stand/Gestures/CalmDown_2', 'animations/Stand/Gestures/CalmDown_3', 'animations/Stand/Gestures/CalmDown_4', 'animations/Stand/Gestures/CalmDown_5', 'animations/Stand/Gestures/CalmDown_6', 'animations/Stand/Gestures/Choice_1', 'animations/Stand/Gestures/ComeOn_1', 'animations/Stand/Gestures/Confused_1', 'animations/Stand/Gestures/Confused_2', 'animations/Stand/Gestures/CountFive_1', 'animations/Stand/Gestures/CountFour_1', 'animations/Stand/Gestures/CountMore_1', 'animations/Stand/Gestures/CountOne_1', 'animations/Stand/Gestures/CountThree_1', 'animations/Stand/Gestures/CountTwo_1', 'animations/Stand/Gestures/Desperate_1', 'animations/Stand/Gestures/Desperate_2', 'animations/Stand/Gestures/Desperate_3', 'animations/Stand/Gestures/Desperate_4', 'animations/Stand/Gestures/Desperate_5', 'animations/Stand/Gestures/DontUnderstand_1', 'animations/Stand/Gestures/Enthusiastic_3', 'animations/Stand/Gestures/Enthusiastic_4', 'animations/Stand/Gestures/Enthusiastic_5', 'animations/Stand/Gestures/Everything_1', 'animations/Stand/Gestures/Everything_2', 'animations/Stand/Gestures/Everything_3', 'animations/Stand/Gestures/Everything_4', 'animations/Stand/Gestures/Everything_6', 'animations/Stand/Gestures/Excited_1', 'animations/Stand/Gestures/Explain_1', 'animations/Stand/Gestures/Explain_10', 'animations/Stand/Gestures/Explain_11', 'animations/Stand/Gestures/Explain_2', 'animations/Stand/Gestures/Explain_3', 'animations/Stand/Gestures/Explain_4', 'animations/Stand/Gestures/Explain_5', 'animations/Stand/Gestures/Explain_6', 'animations/Stand/Gestures/Explain_7', 'animations/Stand/Gestures/Explain_8', 'animations/Stand/Gestures/Far_1', 'animations/Stand/Gestures/Far_2', 'animations/Stand/Gestures/Far_3', 'animations/Stand/Gestures/Follow_1', 'animations/Stand/Gestures/Give_1', 'animations/Stand/Gestures/Give_2', 'animations/Stand/Gestures/Give_3', 'animations/Stand/Gestures/Give_4', 'animations/Stand/Gestures/Give_5', 'animations/Stand/Gestures/Give_6', 'animations/Stand/Gestures/Great_1', 'animations/Stand/Gestures/HeSays_1', 'animations/Stand/Gestures/HeSays_2', 'animations/Stand/Gestures/HeSays_3', 'animations/Stand/Gestures/Hey_1', 'animations/Stand/Gestures/Hey_10', 'animations/Stand/Gestures/Hey_2', 'animations/Stand/Gestures/Hey_3', 'animations/Stand/Gestures/Hey_4', 'animations/Stand/Gestures/Hey_6', 'animations/Stand/Gestures/Hey_7', 'animations/Stand/Gestures/Hey_8', 'animations/Stand/Gestures/Hey_9', 'animations/Stand/Gestures/Hide_1', 'animations/Stand/Gestures/Hot_1', 'animations/Stand/Gestures/Hot_2', 'animations/Stand/Gestures/IDontKnow_1', 'animations/Stand/Gestures/IDontKnow_2', 'animations/Stand/Gestures/IDontKnow_3', 'animations/Stand/Gestures/IDontKnow_4', 'animations/Stand/Gestures/IDontKnow_5', 'animations/Stand/Gestures/IDontKnow_6', 'animations/Stand/Gestures/Joy_1', 'animations/Stand/Gestures/Kisses_1', 'animations/Stand/Gestures/Look_1', 'animations/Stand/Gestures/Look_2', 'animations/Stand/Gestures/Maybe_1', 'animations/Stand/Gestures/Me_1', 'animations/Stand/Gestures/Me_2', 'animations/Stand/Gestures/Me_4', 'animations/Stand/Gestures/Me_7', 'animations/Stand/Gestures/Me_8', 'animations/Stand/Gestures/Mime_1', 'animations/Stand/Gestures/Mime_2', 'animations/Stand/Gestures/Next_1', 'animations/Stand/Gestures/No_1', 'animations/Stand/Gestures/No_2', 'animations/Stand/Gestures/No_3', 'animations/Stand/Gestures/No_4', 'animations/Stand/Gestures/No_5', 'animations/Stand/Gestures/No_6', 'animations/Stand/Gestures/No_7', 'animations/Stand/Gestures/No_8', 'animations/Stand/Gestures/No_9', 'animations/Stand/Gestures/Nothing_1', 'animations/Stand/Gestures/Nothing_2', 'animations/Stand/Gestures/OnTheEvening_1', 'animations/Stand/Gestures/OnTheEvening_2', 'animations/Stand/Gestures/OnTheEvening_3', 'animations/Stand/Gestures/OnTheEvening_4', 'animations/Stand/Gestures/OnTheEvening_5', 'animations/Stand/Gestures/Please_1', 'animations/Stand/Gestures/Please_2', 'animations/Stand/Gestures/Please_3', 'animations/Stand/Gestures/Reject_1', 'animations/Stand/Gestures/Reject_2', 'animations/Stand/Gestures/Reject_3', 'animations/Stand/Gestures/Reject_4', 'animations/Stand/Gestures/Reject_5', 'animations/Stand/Gestures/Reject_6', 'animations/Stand/Gestures/Salute_1', 'animations/Stand/Gestures/Salute_2', 'animations/Stand/Gestures/Salute_3', 'animations/Stand/Gestures/ShowFloor_1', 'animations/Stand/Gestures/ShowFloor_2', 'animations/Stand/Gestures/ShowFloor_3', 'animations/Stand/Gestures/ShowFloor_4', 'animations/Stand/Gestures/ShowFloor_5', 'animations/Stand/Gestures/ShowSky_1', 'animations/Stand/Gestures/ShowSky_10', 'animations/Stand/Gestures/ShowSky_11', 'animations/Stand/Gestures/ShowSky_12', 'animations/Stand/Gestures/ShowSky_2', 'animations/Stand/Gestures/ShowSky_3', 'animations/Stand/Gestures/ShowSky_4', 'animations/Stand/Gestures/ShowSky_5', 'animations/Stand/Gestures/ShowSky_6', 'animations/Stand/Gestures/ShowSky_7', 'animations/Stand/Gestures/ShowSky_8', 'animations/Stand/Gestures/ShowSky_9', 'animations/Stand/Gestures/ShowTablet_1', 'animations/Stand/Gestures/ShowTablet_2', 'animations/Stand/Gestures/ShowTablet_3', 'animations/Stand/Gestures/Shy_1', 'animations/Stand/Gestures/Stretch_1', 'animations/Stand/Gestures/Stretch_2', 'animations/Stand/Gestures/Surprised_1', 'animations/Stand/Gestures/Take_1', 'animations/Stand/Gestures/TakePlace_1', 'animations/Stand/Gestures/TakePlace_2', 'animations/Stand/Gestures/Thinking_1', 'animations/Stand/Gestures/Thinking_2', 'animations/Stand/Gestures/Thinking_3', 'animations/Stand/Gestures/Thinking_4', 'animations/Stand/Gestures/Thinking_5', 'animations/Stand/Gestures/Thinking_6', 'animations/Stand/Gestures/Thinking_7', 'animations/Stand/Gestures/Thinking_8', 'animations/Stand/Gestures/This_1', 'animations/Stand/Gestures/This_10', 'animations/Stand/Gestures/This_11', 'animations/Stand/Gestures/This_12', 'animations/Stand/Gestures/This_13', 'animations/Stand/Gestures/This_14', 'animations/Stand/Gestures/This_15', 'animations/Stand/Gestures/This_2', 'animations/Stand/Gestures/This_3', 'animations/Stand/Gestures/This_4', 'animations/Stand/Gestures/This_5', 'animations/Stand/Gestures/This_6', 'animations/Stand/Gestures/This_7', 'animations/Stand/Gestures/This_8', 'animations/Stand/Gestures/This_9', 'animations/Stand/Gestures/WhatSThis_1', 'animations/Stand/Gestures/WhatSThis_10', 'animations/Stand/Gestures/WhatSThis_11', 'animations/Stand/Gestures/WhatSThis_12', 'animations/Stand/Gestures/WhatSThis_13', 'animations/Stand/Gestures/WhatSThis_14', 'animations/Stand/Gestures/WhatSThis_15', 'animations/Stand/Gestures/WhatSThis_16', 'animations/Stand/Gestures/WhatSThis_2', 'animations/Stand/Gestures/WhatSThis_3', 'animations/Stand/Gestures/WhatSThis_4', 'animations/Stand/Gestures/WhatSThis_5', 'animations/Stand/Gestures/WhatSThis_6', 'animations/Stand/Gestures/WhatSThis_7', 'animations/Stand/Gestures/WhatSThis_8', 'animations/Stand/Gestures/WhatSThis_9', 'animations/Stand/Gestures/Whisper_1', 'animations/Stand/Gestures/Wings_1', 'animations/Stand/Gestures/Wings_2', 'animations/Stand/Gestures/Wings_3', 'animations/Stand/Gestures/Wings_4', 'animations/Stand/Gestures/Wings_5', 'animations/Stand/Gestures/Yes_1', 'animations/Stand/Gestures/Yes_2', 'animations/Stand/Gestures/Yes_3', 'animations/Stand/Gestures/You_1', 'animations/Stand/Gestures/You_2', 'animations/Stand/Gestures/You_3', 'animations/Stand/Gestures/You_4', 'animations/Stand/Gestures/You_5', 'animations/Stand/Gestures/YouKnowWhat_1', 'animations/Stand/Gestures/YouKnowWhat_2', 'animations/Stand/Gestures/YouKnowWhat_3', 'animations/Stand/Gestures/YouKnowWhat_4', 'animations/Stand/Gestures/YouKnowWhat_5', 'animations/Stand/Gestures/YouKnowWhat_6', 'animations/Stand/Gestures/Yum_1', 'animations/Stand/Reactions/EthernetOff_1', 'animations/Stand/Reactions/EthernetOn_1', 'animations/Stand/Reactions/Heat_1', 'animations/Stand/Reactions/Heat_2', 'animations/Stand/Reactions/LightShine_1', 'animations/Stand/Reactions/LightShine_2', 'animations/Stand/Reactions/LightShine_3', 'animations/Stand/Reactions/LightShine_4', 'animations/Stand/Reactions/SeeColor_1', 'animations/Stand/Reactions/SeeColor_2', 'animations/Stand/Reactions/SeeColor_3', 'animations/Stand/Reactions/SeeSomething_1', 'animations/Stand/Reactions/SeeSomething_3', 'animations/Stand/Reactions/SeeSomething_4', 'animations/Stand/Reactions/SeeSomething_5', 'animations/Stand/Reactions/SeeSomething_6', 'animations/Stand/Reactions/SeeSomething_7', 'animations/Stand/Reactions/SeeSomething_8', 'animations/Stand/Reactions/ShakeBody_1', 'animations/Stand/Reactions/ShakeBody_2', 'animations/Stand/Reactions/ShakeBody_3', 'animations/Stand/Reactions/TouchHead_1', 'animations/Stand/Reactions/TouchHead_2', 'animations/Stand/Reactions/TouchHead_3', 'animations/Stand/Reactions/TouchHead_4', 'animations/Stand/Waiting/AirGuitar_1', 'animations/Stand/Waiting/BackRubs_1', 'animations/Stand/Waiting/Bandmaster_1', 'animations/Stand/Waiting/Binoculars_1', 'animations/Stand/Waiting/BreathLoop_1', 'animations/Stand/Waiting/BreathLoop_2', 'animations/Stand/Waiting/BreathLoop_3', 'animations/Stand/Waiting/CallSomeone_1', 'animations/Stand/Waiting/Drink_1', 'animations/Stand/Waiting/DriveCar_1', 'animations/Stand/Waiting/Fitness_1', 'animations/Stand/Waiting/Fitness_2', 'animations/Stand/Waiting/Fitness_3', 'animations/Stand/Waiting/FunnyDancer_1', 'animations/Stand/Waiting/HappyBirthday_1', 'animations/Stand/Waiting/Helicopter_1', 'animations/Stand/Waiting/HideEyes_1', 'animations/Stand/Waiting/HideHands_1', 'animations/Stand/Waiting/Innocent_1', 'animations/Stand/Waiting/Knight_1', 'animations/Stand/Waiting/KnockEye_1', 'animations/Stand/Waiting/KungFu_1', 'animations/Stand/Waiting/LookHand_1', 'animations/Stand/Waiting/LookHand_2', 'animations/Stand/Waiting/LoveYou_1', 'animations/Stand/Waiting/Monster_1', 'animations/Stand/Waiting/MysticalPower_1', 'animations/Stand/Waiting/PlayHands_1', 'animations/Stand/Waiting/PlayHands_2', 'animations/Stand/Waiting/PlayHands_3', 'animations/Stand/Waiting/Relaxation_1', 'animations/Stand/Waiting/Relaxation_2', 'animations/Stand/Waiting/Relaxation_3', 'animations/Stand/Waiting/Relaxation_4', 'animations/Stand/Waiting/Rest_1', 'animations/Stand/Waiting/Robot_1', 'animations/Stand/Waiting/ScratchBack_1', 'animations/Stand/Waiting/ScratchBottom_1', 'animations/Stand/Waiting/ScratchEye_1', 'animations/Stand/Waiting/ScratchHand_1', 'animations/Stand/Waiting/ScratchHead_1', 'animations/Stand/Waiting/ScratchLeg_1', 'animations/Stand/Waiting/ScratchTorso_1', 'animations/Stand/Waiting/ShowMuscles_1', 'animations/Stand/Waiting/ShowMuscles_2', 'animations/Stand/Waiting/ShowMuscles_3', 'animations/Stand/Waiting/ShowMuscles_4', 'animations/Stand/Waiting/ShowMuscles_5', 'animations/Stand/Waiting/ShowSky_1', 'animations/Stand/Waiting/ShowSky_2', 'animations/Stand/Waiting/SpaceShuttle_1', 'animations/Stand/Waiting/Stretch_1', 'animations/Stand/Waiting/Stretch_2', 'animations/Stand/Waiting/TakePicture_1', 'animations/Stand/Waiting/Taxi_1', 'animations/Stand/Waiting/Think_1', 'animations/Stand/Waiting/Think_2', 'animations/Stand/Waiting/Think_3', 'animations/Stand/Waiting/Think_4', 'animations/Stand/Waiting/Waddle_1', 'animations/Stand/Waiting/Waddle_2', 'animations/Stand/Waiting/WakeUp_1', 'animations/Stand/Waiting/Zombie_1', 'asleep-update/animations/nok', 'asleep-update/interactive', 'boot-config', 'boot-config/animations/onNextPage', 'boot-config/animations/onPrevPage', 'boot-config/animations/poseInit', 'boot-config/animations/ok', 'boot-config/animations/success', 'boot-config/animations/poseInitUp', 'boot-config/animations/turnTabletOn_end', 'boot-config/animations/turnTabletOn_start', 'boot-config/animations/warning', 'boot-config/animations/warningValidate', 'boot-config/animations/nok', 'boot-config/animations/updateLoop', 'boot-config/animations/updateOut', 'boot-config/animations/networkLoop', 'boot-config/animations/networkOut', 'boot-config/animations/inviteTablet', 'boot-config/animations/hello', 'boot-config/animations/updateFailed', 'boot-config/animations/finishWizard', 'boot-config/animations/onPlugged', 'boot-config/animations/onUnPlugged', 'boot-config/animations/shutdown', 'boot-config/animations/bipGentle', 'boot-config/animations/endReco', 'dialog_applauncher', 'dialog_lexicon', 'dialog_lexicon/behavior_1', 'ft_seeandlisten_cctv/behavior_1', 'ipepperserver-qishanshi/iPepperServer', 'j-tablet-browser', 'naospyserver/NAOSpyServer', 'push-recovered/animations/pushed_0', 'push-recovered/animations/pushed_1', 'push-recovered/animations/pushed_2', 'push-recovered/solitary', 'push-recovered/animations/searchHumans_1', 'run_dialog_dev', 'run_dialog_dev/init', 'sbr_8641813c-6336-41ef-b317-140d85039314_ets/resident', 'sleep-reactions/Animations/Start_ShakeHead', 'sleep-reactions/Animations/End_ShakeHead', 'sleep-reactions/TouchHand', 'sleep-reactions/RandomHand', 'three_musketeers_story-ad31f7', 'three_musketeers_story-ad31f7/animations/acclaimed', 'three_musketeers_story-ad31f7/animations/cardinal', 'three_musketeers_story-ad31f7/animations/brass-band', 'three_musketeers_story-ad31f7/animations/fierce-duel', 'three_musketeers_story-ad31f7/animations/horse-riding', 'three_musketeers_story-ad31f7/animations/adventure', 'three_musketeers_story-ad31f7/animations/bravest', 'three_musketeers_story-ad31f7/animations/defeated', 'three_musketeers_story-ad31f7/animations/louis', 'zzzzzz_c9da7da9-3524-4dc3-867b-7505bf884f55_b2bral/behavior_1', 'zzzzzz_c9da7da9-3524-4dc3-867b-7505bf884f55_b2bral/resident', 'zzzzzz_c9da7da9-3524-4dc3-867b-7505bf884f55_b2bral/editmode', '.lastUploadedChoregrapheBehavior/behavior_1']
Running behaviors:
['.lastUploadedChoregrapheBehavior/behavior_1', 'dialog_applauncher/.', 'zzzzzz_c9da7da9-3524-4dc3-867b-7505bf884f55_b2bral/behavior_1', 'zzzzzz_c9da7da9-3524-4dc3-867b-7505bf884f55_b2bral/editmode']
Default behaviors:
['zzzzzz_c9da7da9-3524-4dc3-867b-7505bf884f55_b2bral/behavior_1', 'zzzzzz_c9da7da9-3524-4dc3-867b-7505bf884f55_b2bral/editmode', 'zzzzzz_c9da7da9-3524-4dc3-867b-7505bf884f55_b2bral/resident']
Default behaviors:
['run_dialog_dev/.', 'zzzzzz_c9da7da9-3524-4dc3-867b-7505bf884f55_b2bral/behavior_1', 'zzzzzz_c9da7da9-3524-4dc3-867b-7505bf884f55_b2bral/editmode', 'zzzzzz_c9da7da9-3524-4dc3-867b-7505bf884f55_b2bral/resident']
Default behaviors:
['zzzzzz_c9da7da9-3524-4dc3-867b-7505bf884f55_b2bral/behavior_1', 'zzzzzz_c9da7da9-3524-4dc3-867b-7505bf884f55_b2bral/editmode', 'zzzzzz_c9da7da9-3524-4dc3-867b-7505bf884f55_b2bral/resident']

NAOqi Core之ALConnectionManager

ALConnectionManager提供了管理網(wǎng)絡(luò)連接的方法:它包含了允許您配置或連接網(wǎng)絡(luò)的命令,也包含了獲取網(wǎng)絡(luò)屬性或創(chuàng)建網(wǎng)絡(luò)的命令。 ALConnectionManager支持以太網(wǎng),WiFi和藍(lán)牙等多種技術(shù)。

主要功能有:
列出可用的網(wǎng)絡(luò)服務(wù)。
連接到網(wǎng)絡(luò)服務(wù)。
創(chuàng)建網(wǎng)絡(luò)服務(wù)(支持WiFi接入點(diǎn)和藍(lán)牙PAN)。
列出可用的網(wǎng)絡(luò)技術(shù)。
配置網(wǎng)絡(luò)服務(wù)。

此模塊可以訪問不同網(wǎng)絡(luò)服務(wù)的有用信息,例如WiFi服務(wù)的強(qiáng)度,其當(dāng)前狀態(tài)或其安全性要求。
此模塊通過事件通知有關(guān)網(wǎng)絡(luò)連接的更改。

ALConnectionManager基于開源軟件ConnMan獲取有關(guān)所有網(wǎng)絡(luò)服務(wù)的信息并與之連接。
SoftBank Robotics是ConnMan項(xiàng)目的貢獻(xiàn)者,我們的ConnMan源代碼位于github http://github.com/aldebaran上,只有幾個(gè)補(bǔ)丁與官方ConnMan版本不同。
WiFi服務(wù)由WPA Supplicant提供。藍(lán)牙服務(wù)由BlueZ提供。

局限性:
ALConnectionManager僅在機(jī)器人上可用。
ALConnectionManager目前不支持WPA企業(yè)安全。
啟用網(wǎng)絡(luò)共享模式(tethering mode)時(shí),WiFi服務(wù)列表不可用。
ALConnectionManager不處理藍(lán)牙設(shè)備配對(duì)。

示例:獲取網(wǎng)絡(luò)連接的全局狀態(tài)

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

"""Example: Use state Method"""

import qi
import argparse
import sys


def main(session):
    """
        This example uses the state method.
        """
    # Get the service ALConnectionManager.
    
    con_mng_service = session.service("ALConnectionManager")
    
    # Get network state.
    print "Network state: " + con_mng_service.state()


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)

運(yùn)行結(jié)果:Network state: online

示例:獲取網(wǎng)絡(luò)服務(wù)列表


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

"""Example: Use scan and services Methods"""

import qi
import argparse
import sys


def main(session):
    """
        This example uses the scan and services method.
        """
    # Get the service ALConnectionManager.
    
    con_mng_service = session.service("ALConnectionManager")
    
    #Scanning is required to update the services list
    con_mng_service.scan()
    services = con_mng_service.services()
    
    for service in services:
        network = dict(service)
        if network["Name"] == "":
            print "{hidden} " + network["ServiceId"]
        else:
            print network["Name"] + " " + network["ServiceId"]


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)

運(yùn)行結(jié)果:

ARC-5G wifi_48a9d2969a99_4152432d3547_managed_psk
alibaba-inc wifi_48a9d2969a99_616c69626162612d696e63_managed_ieee8021x
alibaba-guest wifi_48a9d2969a99_616c69626162612d6775657374_managed_none
ARC24G wifi_48a9d2969a99_415243323447_managed_psk
360免費(fèi)WiFi-C3 wifi_48a9d2969a99_333630e5858de8b4b9576946692d4333_managed_psk
U+Net869B wifi_48a9d2969a99_552b4e657438363942_managed_psk

NAOqi Core之Extractors

Extractors模塊作為視覺和感知模塊的基類。

從ALExtractor繼承的模塊列表:

?   ALCloseObjectDetection
?   ALEngagementZones
?   ALFaceDetection
?   ALGazeAnalysis
?   ALLandMarkDetection
?   ALPeoplePerception
?   ALRedBallDetection
?   ALSittingPeopleDetection
?   ALSonar
?   ALVisualSpaceHistory
?   ALWavingDetection
?   ALVisionRecognition

從ALExtractor和ALVisionExtractor繼承的模塊列表:

?   ALBacklightingDetection
?   ALBarcodeReader
?   ALDarknessDetection
?   ALMovementDetection
?   ALSegmentation3D
?   ALVisualCompass

任何ALExtractor從ALModule API繼承方法,它還具有以下自己特有的方法:

參數(shù)更新

?   ALExtractor::subscribe
?   ALExtractor::unsubscribe
?   ALExtractor::updatePeriod
?   ALExtractor::updatePrecision

自我檢查

?   ALExtractor::getCurrentPeriod
?   ALExtractor::getCurrentPrecision
?   ALExtractor::getEventList
?   ALExtractor::getMemoryKeyList
?   ALExtractor::getMyPeriod
?   ALExtractor::getMyPrecision
?   ALExtractor::getOutputNames
?   ALExtractor::getSubscribersInfo

任何ALVisionExtractor繼承自ALExtractor API和ALModule API的方法。它還具有自己特有的方法:

參數(shù)更新

?   ALVisionExtractor::setFrameRate
?   ALVisionExtractor::setResolution
?   ALVisionExtractor::setActiveCamera
?   ALVisionExtractor::pause

自我檢查

?   ALVisionExtractor::getFrameRate
?   ALVisionExtractor::getResolution
?   ALVisionExtractor::getActiveCamera
?   ALVisionExtractor::isPaused
?   ALVisionExtractor::isProcessing

NAOqi Core之ALMemory

ALMemory模塊用于存儲(chǔ)與機(jī)器人的硬件配置相關(guān)的所有關(guān)鍵信息。
更具體地說,ALMemory提供有關(guān)執(zhí)行器和傳感器的當(dāng)前狀態(tài)的信息。

ALMemory是一個(gè)互斥和無序的升級(jí)map。map包含變體(ALValue)。
Mutex是讀/寫互斥體,從性能上,可以保護(hù):
? The map
? A value
? The value history (only for events)
例如:
? Remove a data blocks all readers/writers.
? Insert an existing data only blocks the modified data.
? Read data blocks only writers of read data.

notifications由線程池(本地)或唯單獨(dú)的通知線程(遠(yuǎn)程)管理。

事件與微型事件

事件是將他的歷史存儲(chǔ)到ALMemory中的MicroEvent。它們基本相同,但MicroEvent更快。
可以使用ALMemoryProxy :: getEventHistory訪問事件歷史記錄。
此外,當(dāng)某人訂閱一個(gè)活動(dòng)時(shí),模塊可以自動(dòng)啟動(dòng)。此功能可以使用ALMemoryProxy :: declareEvent訪問,其中包含兩個(gè)參數(shù)。

插入和獲取數(shù)據(jù)示例:

from naoqi import ALProxy

try:
  # create proxy on ALMemory
  memProxy = ALProxy("ALMemory","localhost",9559)

  #insertData. Value can be int, float, list, string
  memProxy.insertData("myValueName1", "myValue1")

  #getData
  print "The value of myValueName1 is", memProxy.getData("myValueName1")

except RuntimeError,e:
  # catch exception
  print "error insert data", e

訂閱一個(gè)事件示例:

"""
with sample of python documentation
"""

from naoqi import *
import time
check = 0


# create python module
class myModule(ALModule):
  """python class myModule test auto documentation: comment needed to create a new python module"""


  def pythondatachanged(self, strVarName, value):
    """callback when data change"""
    print "datachanged", strVarName, " ", value, " ", strMessage
    global check
    check = 1

  def _pythonPrivateMethod(self, param1, param2, param3):
    global check


broker = ALBroker("pythonBroker","10.0.252.184",9999,"naoverdose.local",9559)


# call method
try:

  pythonModule = myModule("pythonModule")
  prox = ALProxy("ALMemory")
  #prox.insertData("val",1) # forbidden, data is optimized and doesn't manage callback
  prox.subscribeToEvent("FaceDetected","pythonModule", "pythondatachanged") #  event is case sensitive !

except Exception,e:
  print "error"
  print e
  exit(1)

while (1):
  time.sleep(2)

NAOqi Core之ALModule

ALModule可以用作用戶模塊的基類,以幫助他們提供和宣傳他們的方法。
每個(gè)模塊都會(huì)將其希望向參與網(wǎng)絡(luò)的客戶端提供的方法通告給同一進(jìn)程中的broker。
然后,broker透明地處理目錄服務(wù),以便客戶端不需要知道提供服務(wù)的模塊是否處于同一進(jìn)程,同一臺(tái)機(jī)器上或同一tcp網(wǎng)絡(luò)上。
在同一的進(jìn)程中,直接方法調(diào)用用于提供最佳速度,而無需更改方法簽名。
任務(wù)管理
? ALModule::isRunning
? ALModule::wait
? ALModule::stop
? ALModule::exit
自我檢查
? ALModule::getBrokerName
? ALModule::getMethodList
? ALModule::getMethodHelp
? ALModule::getModuleHelp
? ALModule::getUsage
? ALModule::ping
? ALModule::version
事件列表
? ClientConnected()
? ClientDisconnected()

NAOqi Core之ALNotificationManager

ALNotificationManager模塊提供了管理機(jī)器人通知的方法。

當(dāng)應(yīng)用程序發(fā)送通知時(shí):
- 它被附加到待處理通知的列表中。
- 通知最終用戶有待處理的通知,并可以要求機(jī)器人讀取它。

在以下情況下,通知將從待處理通知列表中刪除:
- 它已被讀取
- 它被應(yīng)用程序刪除,例如,它不再有效。

ALValue NotificationInfo
ALValue NotificationInfo是n對(duì)(key,value)的數(shù)組。
為了與其他模塊交換此對(duì)象,Notification對(duì)象可以用以下結(jié)構(gòu)表示為ALValue:

key value type default value
"id" int -1
"message" string ""
"severity" string "info"
"removeOnRead" bool true

添加一個(gè)通知示例:

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

"""Example: Use add Method"""

import qi
import argparse
import sys


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

    notif_mng_service = session.service("ALNotificationManager")

    # Add a notification.
    notificationId = notif_mng_service.add({"message": "Hello World!", "severity": "info", "removeOnRead": True})
    print "Notification ID: " + str(notificationId)


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)

打印所有通知消息的示例:

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

"""Example: Use notifications Method"""

import qi
import argparse
import sys


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

    notif_mng_service = session.service("ALNotificationManager")

    # Get the notifications.
    notifications = notif_mng_service.notifications()
    for notification in notifications:
        notifDict = dict(notification)
        print "Notification ID: " + str(notifDict["id"])
        print "\tMessage: " + notifDict["message"]
        print "\tSeverity: " + notifDict["severity"]
        print "\tRemove On Read: " + str(notifDict["removeOnRead"])
        print "-----------\n"


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)

NAOqi Core之ALPreferenceManager

ALPreferenceManager允許管理機(jī)器人的首選項(xiàng)。 機(jī)器人首選項(xiàng)用于存儲(chǔ)機(jī)器人上運(yùn)行的應(yīng)用程序的所有設(shè)置。

存儲(chǔ)
機(jī)器人首選項(xiàng)存儲(chǔ)在機(jī)器人和Aldebaran Cloud上的數(shù)據(jù)庫(kù)中; ALPreferenceManager確保不同副本之間的一致性。

格式化
一個(gè)首選項(xiàng)如下定義:

- 域:它可以是使用首選項(xiàng)設(shè)置的應(yīng)用程序的名稱。 
- 名稱:它是設(shè)置的名稱。 
- 值:目前僅支持字符串值。

例如,如果您正在開發(fā)國(guó)際象棋應(yīng)用程序,則可以具有以下首選項(xiàng):

?   Domain: “com.aldebaran.apps.chess”
?   Name: “/game/level/default”
?   Value: “medium”

性能與限制

存儲(chǔ)
在機(jī)器人上,首選項(xiàng)存儲(chǔ)在SQLite數(shù)據(jù)庫(kù)的路徑下:
/home/nao/.local/share/PreferenceManager/prefs.db

只有當(dāng)機(jī)器人與Aldebaran用戶帳戶相關(guān)聯(lián)時(shí),首選項(xiàng)才能同步并保存在Aldebaran Cloud中。如果沒有,首選項(xiàng)只會(huì)在本地存儲(chǔ)。

字符限制:

- 僅使用字母數(shù)字字符
- 禁止使用'\'

NAOqi Core之ALResourceManager

ALResourceManager提供了一種管理資源的方法。資源可以是:電機(jī),麥克風(fēng),LED,CPU,剛度參數(shù),相機(jī)設(shè)置,球體...

ALResourceManager允許你:

?   避免另一種行為使用您需要的資源
?   同步運(yùn)動(dòng),LED,聲音...
?   當(dāng)另一個(gè)行為想要你的資源時(shí),運(yùn)行特定的操作。例如,在其他行為操作行走行為之前,停止現(xiàn)在的行走行為。

資源遵循資源層次結(jié)構(gòu)。
資源管理器使用對(duì)象行為層次結(jié)構(gòu):假設(shè)你創(chuàng)造一種踢足球的行為。首先,機(jī)器人應(yīng)該在沒有移動(dòng)的情況下搜索球。如果機(jī)器人發(fā)現(xiàn)球并需要走路,您需要確保在行走前有足夠的資源。 資源管理器允許在根對(duì)象或根行為中獲取資源,所有子對(duì)象將自動(dòng)將資源轉(zhuǎn)移到父級(jí),但是子對(duì)象之間可以彼此沖突。

資源管理器允許同步一組資源
您可以預(yù)留頭部電機(jī),文字,語音和LED,以確保同步運(yùn)動(dòng),語音和LED。
這組資源的管理與一個(gè)資源完全一樣:

?   在請(qǐng)求期間,丟失一個(gè)資源會(huì)釋放所有資源。
?   所有的資源等待都有超時(shí)機(jī)制。
?   請(qǐng)求組不能死鎖。

創(chuàng)建一個(gè)資源示例:

# create proxy on resource manager
proxy = ALProxy("ALResourceManager","localhost",9559)

#createResource in root (parent resource is "")
proxy.createResource("newResource","")

檢查資源是否可用:

#check resource is free
free = proxy.areResourcesFree(["newResource"])

等待資源變?yōu)榭捎茫ㄗ枞{(diào)用)

# take resource
# acquireResource(resource name, owner name, callback to notify you that someone want the resource, timeout)
proxy.acquireResource("newResource", "myFooModule", "", 1)

回調(diào)沖突

class MyFooModule:
  def myFooCallback(self, resource, currentOwner):
    #decide what to do with the ressource.
    #either call releaseResource or pass
    if iwanttoreleasetheresource:
      releaseResource(resource, currentOwner)

# alternatively, you can specify a callback on myFooModule as third parameter that will be called in case of conflict.
proxy.acquireResource("newResource", "MyFooModule", "myFooCallback", 1)

釋放waitForResource占用的資源

#release resource
proxy.releaseResource("newResource", "myFooModule")

NAOqi Core之ALSystem

ALSystem提供可用于配置系統(tǒng)并執(zhí)行關(guān)閉或重新啟動(dòng)等操作的原語。

ALSystem從ALModule API繼承方法。它還具有自己特有的方法:
class ALSystemProxy

?   ALSystemProxy::robotName
?   ALSystemProxy::robotIcon
?   ALSystemProxy::setRobotName
?   ALSystemProxy::shutdown
?   ALSystemProxy::reboot
?   ALSystemProxy::systemVersion
?   ALSystemProxy::timezone
?   ALSystemProxy::setTimezone
?   ALSystemProxy::freeMemory
?   ALSystemProxy::totalMemory
?   ALSystemProxy::diskFree
?   ALSystemProxy::previousSystemVersion
?   ALSystemProxy::changePassword
?   ALSystemProxy::upgrade
?   ALSystemProxy::factoryReset

Event list

?   ALSystem/RobotNameChanged()

NAOQI VISION

視頻與圖片管理:

USE To ...
ALPhotoCapture 拍照并將其保存在磁盤
ALVideoDevice 管理視頻輸入
ALVideoRecorder 記錄視頻

視頻檢測(cè):

USE To ...
ALBacklightingDetection 檢查相機(jī)的圖像是否背光
ALBarcodeReader 檢測(cè)并讀取圖像中的條形碼
ALColorBlobDetection 檢測(cè)給定顏色的斑點(diǎn)(圓形或非圓形)
ALDarknessDetection 檢查環(huán)境是否黑暗
ALLandMarkDetection 檢測(cè)具體的視覺地標(biāo)
ALMovementDetection 檢測(cè)一些運(yùn)動(dòng),并告知它來自哪里
ALRedBallDetection 檢測(cè)紅色和圓形物體

視覺記憶工具:

USE To ...
ALVisionRecognition 使機(jī)器人學(xué)習(xí)和識(shí)別視覺模式:對(duì)象,圖片...
ALVisualSpaceHistory 構(gòu)建頭部位置的帶有時(shí)間戳的地圖

視覺作為導(dǎo)航工具:

USE To ...
ALLocalization 給機(jī)器人回到一個(gè)家的能力(家:已學(xué)習(xí))
ALVisualCompass 使用圖像作為指南針

3D傳感器相關(guān):

USE To ...
ALCloseObjectDetection 檢測(cè)要被3D傳感器直接感知的物體
ALSegmentation3D 分割由3D傳感器返回的深度圖像

NAOQI VISION之ALBacklightingDetection

ALBacklightingDetection提取器檢查相機(jī)返回的圖像是否背光。當(dāng)光源(例如窗口)和觀察到的場(chǎng)景之間存在高對(duì)比度時(shí),背光打開。

為每個(gè)幀計(jì)算以下背光值:

?   0: no backlight
?   1: possible backlight
?   2: backlight identified

該值存儲(chǔ)在ALMemory中。當(dāng)?shù)谝淮螜z測(cè)到背光狀況(即背光值剛剛變?yōu)?)時(shí),會(huì)觸發(fā)事件。

為了計(jì)算背光值,提取器:
分析當(dāng)前幀是否超過2%的像素被裁剪(當(dāng)像素傳感器接收到更多的光可以“存儲(chǔ)”時(shí)發(fā)生的現(xiàn)象,導(dǎo)致該像素的數(shù)字轉(zhuǎn)換之后的值為“255”);
檢查超過60%的像素的亮度是否低于70;
最終結(jié)果是“255”處的像素百分比和低于“70”的像素百分比的加權(quán)組合。

NAOQI VISION之ALBarcodeReader

ALBarcodeReader掃描相機(jī)中的圖像并查找條形碼。如果在圖像中找到條形碼,模塊將嘗試解密它。

每當(dāng)讀取QR代碼時(shí)都會(huì)觸發(fā)事件。此事件還包含代碼數(shù)據(jù)和角位置,如圖所示。請(qǐng)注意,第一個(gè)角落(標(biāo)有“0”)總是與沒有黑色方塊的角落相對(duì)。剩下的角落被逆時(shí)針標(biāo)記。

image.png

ALBarcodeReader目前僅適用于QR碼??梢栽趩蝹€(gè)圖像中處理多條QR代碼。 由于條形碼由小元素(條形,正方形)構(gòu)成,所以圖像分辨率必須根據(jù)相機(jī)與代碼本身之間的距離進(jìn)行設(shè)置。檢測(cè)率也取決于打印的代碼質(zhì)量和尺寸。

NAOQI VISION之ALCloseObjectDetection

ALCloseObjectDetection允許您檢測(cè)到距機(jī)器人太近的對(duì)象,以便3D傳感器直接檢測(cè)到。

為了出現(xiàn)在由3D傳感器返回的深度圖像中,物體必須距離傳感器的距離最小。使用紅外圖像(也由3D傳感器返回),可以檢測(cè)物體何時(shí)太近并計(jì)算其位置,因?yàn)檫@些對(duì)象將對(duì)應(yīng)于紅外圖像中的飽和像素。

每次通過模塊ALCloseObjectDetection在3D傳感器的“近距離”范圍內(nèi)檢測(cè)到一個(gè)對(duì)象時(shí),將更新ALMemory鍵CloseObjectDetection / ObjectInfo,并觸發(fā)ALMemory事件CloseObjectDetection / ObjectDetected()。

存儲(chǔ)鍵包含有關(guān)最近對(duì)象檢測(cè)的信息。組織如下:

ObjectInfo =
[
  TimeStamp,
  CloseObjectInfo,
  CameraPose_InTorsoFrame,
  CameraPose_InRobotFrame,
  Camera_Id
]

TimeStamp: 該字段是用于執(zhí)行檢測(cè)的圖像的時(shí)間戳
TimeStamp [
  TimeStamp_Seconds,
  Timestamp_Microseconds
]
CloseObjectInfo: 這些字段中的每一個(gè)都包含檢測(cè)到的接近對(duì)象的描述
CloseObjectInfo =
[
  PositionOfCog,
  AngularRoi,
  PixelsProportion,
]

PositionOfCog = [x,y]包含對(duì)象重心的角坐標(biāo)(弧度)。
AngularRoi = [x,y,width,height]包含關(guān)于包含對(duì)象的最小矩形(ROI)的信息。 [x,y]對(duì)應(yīng)于當(dāng)前深度圖像中ROI的左上角的角坐標(biāo)(弧度)。 [寬度,高度]對(duì)應(yīng)于ROI的角度大?。ɑ《龋?。
PixelsProportion = [In_Frame,In_Roi]對(duì)應(yīng)于屬于接近對(duì)象的像素的比例。 In_Frame是相對(duì)于幀中像素總數(shù)的比例,In_Roi是相對(duì)于對(duì)象ROI的像素?cái)?shù)的比例。

CameraPose_InTorsoFrame:在FRAME_TORSO中描述拍攝圖像時(shí)深度相機(jī)的Position6D。
CameraPose_InRobotFrame:在FRAME_ROBOT中描述拍攝圖像時(shí)深度相機(jī)的Position6D。
Camera_Id:給出用于檢測(cè)的相機(jī)的ID,即深度相機(jī)。

注釋:
ROI(region of interest),感興趣區(qū)域。機(jī)器視覺、圖像處理中,從被處理的圖像以方框、圓、橢圓、不規(guī)則多邊形等方式勾勒出需要處理的區(qū)域,稱為感興趣區(qū)域。

NAOQI VISION之ALColorBlobDetection

ALColorBlobDetection是一個(gè)提供快速2D視覺彩色斑點(diǎn)檢測(cè)器的模塊。
ALColorBlobDetection基于快速搜索給定顏色的一組像素(在一定閾值內(nèi))??梢赃x擇顏色和它的threhsold,也可以定義對(duì)象跨度及其最小尺寸。

NAOQI VISION之ALDarknessDetection

ALDarknessDetection可以檢查機(jī)器人是否處于黑暗環(huán)境中。 為相機(jī)返回的每個(gè)幀計(jì)算一個(gè)暗度值。該值存儲(chǔ)在ALMemory中。當(dāng)機(jī)器人首次檢測(cè)到其周圍的環(huán)境較暗(即,暗度值大于閾值)時(shí),會(huì)觸發(fā)事件。

該功能首先計(jì)算對(duì)應(yīng)于機(jī)器人周圍環(huán)境的照明條件的0到100之間的值:
0:亮環(huán)境
100:暗環(huán)境

然后將該值與黑暗閾值進(jìn)行比較:
如果它小于閾值,周圍環(huán)境不被認(rèn)為是黑暗的。
如果它大于閾值,則周圍環(huán)境被認(rèn)為是黑暗的。

黑暗閾值可以使用ALDarknessDetectionProxy :: getDarknessThreshold函數(shù)訪問。它的默認(rèn)值為60,但可以使用ALDarknessDetectionProxy :: setDarknessThreshold函數(shù)進(jìn)行更改。

性能與限制
必須激活相機(jī)的相機(jī)AutoExposition參數(shù)才能正常工作。

NAOQI VISION之ALLandMarkDetection

ALLandMarkDetection是一個(gè)視覺模塊,其中機(jī)器人識(shí)別具有特定模式的特殊地標(biāo)。我們把這些地標(biāo)稱為Naomarks。

image.png

您可以使用ALLandMarkDetection模塊進(jìn)行各種應(yīng)用。例如,您可以將這些地標(biāo)放置在機(jī)器人操作區(qū)域的不同位置。根據(jù)機(jī)器人檢測(cè)到哪個(gè)地標(biāo),您可以獲取有關(guān)機(jī)器人位置的一些信息。與其他傳感器信息相結(jié)合,可以幫助您構(gòu)建更強(qiáng)大的本地化模塊。

NaoMarks包括以圓圈為中心的白色三角形粉絲的黑色圓圈。不同三角形風(fēng)扇的具體位置用于區(qū)分不同的Naomark。

性能與限制
光照:地標(biāo)檢測(cè)已經(jīng)在辦公室照明條件下測(cè)試通過,即低于100到500 lux。由于檢測(cè)本身依賴于對(duì)比度差異,所以只要輸入圖像中的標(biāo)記對(duì)比度高一些,實(shí)際表現(xiàn)會(huì)好一些。
檢測(cè)到的標(biāo)記的尺寸范圍:
最小值:?0.035 rad = 2 deg它對(duì)應(yīng)于QVGA圖像中的?14像素
最大值:?0.40 rad = 23度它對(duì)應(yīng)于QVGA圖像中?160個(gè)像素
傾斜:+/- 60度(0度對(duì)應(yīng)于面向相機(jī)的標(biāo)記)
圖像平面中的旋轉(zhuǎn):不變。

使用監(jiān)視器查看檢測(cè)結(jié)果:
了解ALLandMarkDetection可以做什么,您可以使用Monitor并啟動(dòng)視覺插件。激活LandMarkDetection復(fù)選框并開始攝像。然后,如果您將Naomark放置在攝像機(jī)的視野中,Monitor應(yīng)通過在視頻輸出窗格中盤點(diǎn)來報(bào)告檢測(cè)到的Naomarks。此外,Naomark標(biāo)識(shí)符顯示在圓圈旁邊,應(yīng)該與真實(shí)的Naomark標(biāo)識(shí)符相對(duì)應(yīng)。

image.png

開始檢測(cè):

要啟動(dòng)Naomark檢測(cè)功能,請(qǐng)使用ALLandMarkDetection代理訂閱ALLandMarkDetection。在Python中,此訂閱的代碼是:

from naoqi import ALProxy
IP = "your_robot_ip"
PORT = 9559
# Create a proxy to ALLandMarkDetection
markProxy = ALproxy("ALLandMarkDetection", IP, PORT)
# Subscribe to the ALLandMarkDetection extractor
period = 500
markProxy.subscribe("Test_Mark", period, 0.0 )

period參數(shù)指定(以毫秒為單位)ALLandMarkDetection嘗試運(yùn)行其檢測(cè)方法的頻率,并將結(jié)果輸出到名為L(zhǎng)andmarkDetected的ALMemory輸出變量中。

至少對(duì)ALLandMarkDetection模塊訂閱一次,ALLandMarkDetection才能開始運(yùn)行。

獲取結(jié)果:

ALLandMarkDetection模塊將其結(jié)果寫入ALMemory(LandmarkDetected)中的變量。 您確定要直接在代碼中使用檢測(cè)結(jié)果,您可以定期檢查ALMemory的變量。
為此,只需創(chuàng)建一個(gè)代理到ALMemory,并從ALMemory代理中使用getData(“LandmarkDetected”)檢索Landmark變量。

變量結(jié)果解析:

如果沒有檢測(cè)到Naomarks,變量為空。它是一個(gè)零元素的陣列(即在python中打印為[])。
如果檢測(cè)到N Naomarks,則可變結(jié)構(gòu)由兩個(gè)字段組成: [[TimeStampField] [Mark_info_0,Mark_info_1,。 。 。 ,Mark_info_N-1]]

TimeStampField = [TimeStamp_seconds,Timestamp_microseconds]。該字段是用于執(zhí)行檢測(cè)的圖像的時(shí)間戳。
Mark_info = [ShapeInfo,ExtraInfo]。對(duì)于每個(gè)檢測(cè)到的標(biāo)記,我們有一個(gè)Mark_info字段。 ShapeInfo = [1,alpha,beta,sizeX,sizeY,heading]。 alpha和beta表示Naomark在相機(jī)角度方面的位置;sizeX和sizeY是相機(jī)角度的標(biāo)記尺寸;heading角度描述了關(guān)于機(jī)器人頭部的Naomark是如何面向垂直軸的。
ExtraInfo = [MarkID]。標(biāo)記ID是寫在Naomark上的數(shù)字,對(duì)應(yīng)于其圖案。

NAOQI VISION之ALMovementDetection

ALMovementDetection允許您檢測(cè)Aldebaran機(jī)器人的視野中的移動(dòng)。
Aldebaran機(jī)器人使用3D相機(jī)(如果有的話),否則它們使用RGB相機(jī)。

以定期的間隔收集幀,并將每個(gè)新幀與前一幀進(jìn)行比較。差異高于閾值的像素被標(biāo)識(shí)為“移動(dòng)像素”。然后所有的“移動(dòng)像素”都使用它們的物理接近度和它們的值差異進(jìn)行聚類。

對(duì)于沒有3d相機(jī)的Aldebaran機(jī)器人,可以使用以下方式更改閾值: - ALMovementDetectionProxy :: setColorSensitivity
對(duì)于具有3d相機(jī)的Aldebaran機(jī)器人,可以使用以下方式更改閾值: - ALMovementDetectionProxy :: setDepthSensitivity

ALMemory KEY
每次檢測(cè)到一些移動(dòng)時(shí),ALMemory鍵的MoveDetection / MovementInfo被更新,并且觸發(fā)了一個(gè)ALMemory事件MoveDetection / MovementDetected。

存儲(chǔ)鍵包含有關(guān)“移動(dòng)”像素的不同簇的信息。它的組織如下:

MovementInfo =
[
  TimeStamp,
  [ClusterInfo_1, ClusterInfo_2, ... ClusterInfo_n],
  CameraPose_InTorsoFrame,
  CameraPose_InRobotFrame,
  Camera_Id
]

Timestamp:該字段是用于執(zhí)行檢測(cè)的圖像的時(shí)間戳。

TimeStamp [
  TimeStamp_Seconds,
  Timestamp_Microseconds
]

這些字段中的每一個(gè)都包含“移動(dòng)”集群的描述。它具有以下結(jié)構(gòu),具體取決于相機(jī)的類型:
RGB Camera

ClusterInfo_i(RGB) =
[
  PositionOfCog,
  AngularRoi,
  ProportionMovingPixels,
]

Depth Camera

ClusterInfo_i(Depth) =
[
  PositionOfCog,
  AngularRoi,
  ProportionMovingPixels,
  MeanDistance,
  RealSizeRoi,
  PositionOfAssociatedPoint
]

All cameras:

?   PositionOfCog = [x,y] 包含相對(duì)于相機(jī)中心的集群重心的角坐標(biāo)(弧度)。
?   AngularRoi = [x,y,width, height] 包含關(guān)于包含集群的最小矩形(ROI)的信息。 [x,y]對(duì)應(yīng)于當(dāng)前深度圖像中ROI的左上角的角坐標(biāo)(弧度)。 [寬度,高度]對(duì)應(yīng)于ROI的角度大小(弧度)。
?   ProportionMovingPixels = [In_Frame, In_Roi] 對(duì)應(yīng)于“移動(dòng)”像素的比例。 In_Frame是相對(duì)于幀中像素總數(shù)的比例,In_Roi是相對(duì)于群集ROI的像素?cái)?shù)的比例。

Depth camera only:

?   MeanDistance 是相對(duì)于深度相機(jī)(僅用于3D檢測(cè))的聚類點(diǎn)的平均距離。
?   RealSizeRoi = [realwidth,realheight]給出了集群ROI的實(shí)際大?。ㄒ悦子?jì))(僅用于3D檢測(cè))。
?   [X,Y]。使用初始深度圖像的分割(參見模塊ALSegmentation3D的描述),可以提取移動(dòng)的斑點(diǎn)。然后可以通過從其重心向上移動(dòng)來找到該斑點(diǎn)的頂點(diǎn)像素。 [x,y]是該像素的角坐標(biāo)(弧度)。例如,這些坐標(biāo)可以非常有用地觀察剛剛移動(dòng)的人的頭部,而不是觀察運(yùn)動(dòng)的重心(僅用于3D檢測(cè))。

CameraPose_InTorsoFrame: 在FRAME_TORSO中描述拍攝圖像時(shí)相機(jī)的Position6D。
CameraPose_InRobotFrame: 在FRAME_ROBOT中描述拍攝圖像時(shí)相機(jī)的Position6D。
Camera_Id: 給出用于檢測(cè)的相機(jī)的ID。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容