美文网首页NAO机器人科技
NAOQI API之学习笔记

NAOQI API之学习笔记

作者: 郭少悲 | 来源:发表于2017-06-06 15:09 被阅读1545次

    NAOQI OS是软银pepper和nao机器人的核心操作系统,NAOQI API提供了访问机器人的各种传感器设备接口以及应用接口。

    NAOqi Core之ALBehaviourManager

    ALBehaviorManager旨在管理行为(Behaviour)。有了这个模块,你可以:

    • 加载,启动,停止一个行为;
    • 管理默认行为;
    • 获取有关行为的信息;

    默认行为:一些行为可以被标记为“默认”,这意味着它们在NAOqi启动时自动启动。 ALBehaviorManager允许用户添加或删除这些行为,或启动和停止它们。

    行为名字:一个行为的名称由其来包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)
    
    
    

    示例运行步骤:运行python脚本,给出NAO的IP和行为名称作为参数,如下
    python albehaviormanager_example.py robotIp behaviorName

    运行结果:

    [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提供了管理网络连接的方法:它包含了允许您配置或连接网络的命令,也包含了获取网络属性或创建网络的命令。 ALConnectionManager支持以太网,WiFi和蓝牙等多种技术。

    主要功能有:
    列出可用的网络服务。
    连接到网络服务。
    创建网络服务(支持WiFi接入点和蓝牙PAN)。
    列出可用的网络技术。
    配置网络服务。

    此模块可以访问不同网络服务的有用信息,例如WiFi服务的强度,其当前状态或其安全性要求。
    此模块通过事件通知有关网络连接的更改。

    ALConnectionManager基于开源软件ConnMan获取有关所有网络服务的信息并与之连接。
    SoftBank Robotics是ConnMan项目的贡献者,我们的ConnMan源代码位于github http://github.com/aldebaran上,只有几个补丁与官方ConnMan版本不同。
    WiFi服务由WPA Supplicant提供。蓝牙服务由BlueZ提供。

    局限性:
    ALConnectionManager仅在机器人上可用。
    ALConnectionManager目前不支持WPA企业安全。
    启用网络共享模式(tethering mode)时,WiFi服务列表不可用。
    ALConnectionManager不处理蓝牙设备配对。

    示例:获取网络连接的全局状态

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

    运行结果:Network state: online

    示例:获取网络服务列表

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

    运行结果:

    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免费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继承方法,它还具有以下自己特有的方法:

    参数更新

    •   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的方法。它还具有自己特有的方法:

    参数更新

    •   ALVisionExtractor::setFrameRate
    •   ALVisionExtractor::setResolution
    •   ALVisionExtractor::setActiveCamera
    •   ALVisionExtractor::pause
    

    自我检查

    •   ALVisionExtractor::getFrameRate
    •   ALVisionExtractor::getResolution
    •   ALVisionExtractor::getActiveCamera
    •   ALVisionExtractor::isPaused
    •   ALVisionExtractor::isProcessing
    

    NAOqi Core之ALMemory

    ALMemory模块用于存储与机器人的硬件配置相关的所有关键信息。
    更具体地说,ALMemory提供有关执行器和传感器的当前状态的信息。

    ALMemory是一个互斥和无序的升级map。map包含变体(ALValue)。
    Mutex是读/写互斥体,从性能上,可以保护:
    • 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由线程池(本地)或唯单独的通知线程(远程)管理。

    事件与微型事件

    事件是将他的历史存储到ALMemory中的MicroEvent。它们基本相同,但MicroEvent更快。
    可以使用ALMemoryProxy :: getEventHistory访问事件历史记录。
    此外,当某人订阅一个活动时,模块可以自动启动。此功能可以使用ALMemoryProxy :: declareEvent访问,其中包含两个参数。

    插入和获取数据示例:

    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
    
    

    订阅一个事件示例:

    """
    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可以用作用户模块的基类,以帮助他们提供和宣传他们的方法。
    每个模块都会将其希望向参与网络的客户端提供的方法通告给同一进程中的broker。
    然后,broker透明地处理目录服务,以便客户端不需要知道提供服务的模块是否处于同一进程,同一台机器上或同一tcp网络上。
    在同一的进程中,直接方法调用用于提供最佳速度,而无需更改方法签名。
    任务管理
    • 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模块提供了管理机器人通知的方法。

    当应用程序发送通知时:
    - 它被附加到待处理通知的列表中。
    - 通知最终用户有待处理的通知,并可以要求机器人读取它。

    在以下情况下,通知将从待处理通知列表中删除:
    - 它已被读取
    - 它被应用程序删除,例如,它不再有效。

    ALValue NotificationInfo
    ALValue NotificationInfo是n对(key,value)的数组。
    为了与其他模块交换此对象,Notification对象可以用以下结构表示为ALValue:

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

    添加一个通知示例:

    #! /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允许管理机器人的首选项。 机器人首选项用于存储机器人上运行的应用程序的所有设置。

    存储
    机器人首选项存储在机器人和Aldebaran Cloud上的数据库中; ALPreferenceManager确保不同副本之间的一致性。

    格式化
    一个首选项如下定义:

    - 域:它可以是使用首选项设置的应用程序的名称。 
    - 名称:它是设置的名称。 
    - 值:目前仅支持字符串值。
    

    例如,如果您正在开发国际象棋应用程序,则可以具有以下首选项:

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

    性能与限制

    存储
    在机器人上,首选项存储在SQLite数据库的路径下:
    /home/nao/.local/share/PreferenceManager/prefs.db

    只有当机器人与Aldebaran用户帐户相关联时,首选项才能同步并保存在Aldebaran Cloud中。如果没有,首选项只会在本地存储。

    字符限制:

    - 仅使用字母数字字符
    - 禁止使用'\'
    

    NAOqi Core之ALResourceManager

    ALResourceManager提供了一种管理资源的方法。资源可以是:电机,麦克风,LED,CPU,刚度参数,相机设置,球体...

    ALResourceManager允许你:

    •   避免另一种行为使用您需要的资源
    •   同步运动,LED,声音...
    •   当另一个行为想要你的资源时,运行特定的操作。例如,在其他行为操作行走行为之前,停止现在的行走行为。
    

    资源遵循资源层次结构。
    资源管理器使用对象行为层次结构:假设你创造一种踢足球的行为。首先,机器人应该在没有移动的情况下搜索球。如果机器人发现球并需要走路,您需要确保在行走前有足够的资源。 资源管理器允许在根对象或根行为中获取资源,所有子对象将自动将资源转移到父级,但是子对象之间可以彼此冲突。

    资源管理器允许同步一组资源
    您可以预留头部电机,文字,语音和LED,以确保同步运动,语音和LED。
    这组资源的管理与一个资源完全一样:

    •   在请求期间,丢失一个资源会释放所有资源。
    •   所有的资源等待都有超时机制。
    •   请求组不能死锁。
    

    创建一个资源示例:

    # 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"])
    
    

    等待资源变为可用(阻塞调用)

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

    回调冲突

    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提供可用于配置系统并执行关闭或重新启动等操作的原语。

    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 记录视频

    视频检测:

    USE To ...
    ALBacklightingDetection 检查相机的图像是否背光
    ALBarcodeReader 检测并读取图像中的条形码
    ALColorBlobDetection 检测给定颜色的斑点(圆形或非圆形)
    ALDarknessDetection 检查环境是否黑暗
    ALLandMarkDetection 检测具体的视觉地标
    ALMovementDetection 检测一些运动,并告知它来自哪里
    ALRedBallDetection 检测红色和圆形物体

    视觉记忆工具:

    USE To ...
    ALVisionRecognition 使机器人学习和识别视觉模式:对象,图片...
    ALVisualSpaceHistory 构建头部位置的带有时间戳的地图

    视觉作为导航工具:

    USE To ...
    ALLocalization 给机器人回到一个家的能力(家:已学习)
    ALVisualCompass 使用图像作为指南针

    3D传感器相关:

    USE To ...
    ALCloseObjectDetection 检测要被3D传感器直接感知的物体
    ALSegmentation3D 分割由3D传感器返回的深度图像

    NAOQI VISION之ALBacklightingDetection

    ALBacklightingDetection提取器检查相机返回的图像是否背光。当光源(例如窗口)和观察到的场景之间存在高对比度时,背光打开。

    为每个帧计算以下背光值:

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

    该值存储在ALMemory中。当第一次检测到背光状况(即背光值刚刚变为2)时,会触发事件。

    为了计算背光值,提取器:
    分析当前帧是否超过2%的像素被裁剪(当像素传感器接收到更多的光可以“存储”时发生的现象,导致该像素的数字转换之后的值为“255”);
    检查超过60%的像素的亮度是否低于70;
    最终结果是“255”处的像素百分比和低于“70”的像素百分比的加权组合。

    NAOQI VISION之ALBarcodeReader

    ALBarcodeReader扫描相机中的图像并查找条形码。如果在图像中找到条形码,模块将尝试解密它。

    每当读取QR代码时都会触发事件。此事件还包含代码数据和角位置,如图所示。请注意,第一个角落(标有“0”)总是与没有黑色方块的角落相对。剩下的角落被逆时针标记。

    image.png

    ALBarcodeReader目前仅适用于QR码。可以在单个图像中处理多条QR代码。 由于条形码由小元素(条形,正方形)构成,所以图像分辨率必须根据相机与代码本身之间的距离进行设置。检测率也取决于打印的代码质量和尺寸。

    NAOQI VISION之ALCloseObjectDetection

    ALCloseObjectDetection允许您检测到距机器人太近的对象,以便3D传感器直接检测到。

    为了出现在由3D传感器返回的深度图像中,物体必须距离传感器的距离最小。使用红外图像(也由3D传感器返回),可以检测物体何时太近并计算其位置,因为这些对象将对应于红外图像中的饱和像素。

    每次通过模块ALCloseObjectDetection在3D传感器的“近距离”范围内检测到一个对象时,将更新ALMemory键CloseObjectDetection / ObjectInfo,并触发ALMemory事件CloseObjectDetection / ObjectDetected()。

    存储键包含有关最近对象检测的信息。组织如下:

    ObjectInfo =
    [
      TimeStamp,
      CloseObjectInfo,
      CameraPose_InTorsoFrame,
      CameraPose_InRobotFrame,
      Camera_Id
    ]
    
    TimeStamp: 该字段是用于执行检测的图像的时间戳
    TimeStamp [
      TimeStamp_Seconds,
      Timestamp_Microseconds
    ]
    CloseObjectInfo: 这些字段中的每一个都包含检测到的接近对象的描述
    CloseObjectInfo =
    [
      PositionOfCog,
      AngularRoi,
      PixelsProportion,
    ]
    
    PositionOfCog = [x,y]包含对象重心的角坐标(弧度)。
    AngularRoi = [x,y,width,height]包含关于包含对象的最小矩形(ROI)的信息。 [x,y]对应于当前深度图像中ROI的左上角的角坐标(弧度)。 [宽度,高度]对应于ROI的角度大小(弧度)。
    PixelsProportion = [In_Frame,In_Roi]对应于属于接近对象的像素的比例。 In_Frame是相对于帧中像素总数的比例,In_Roi是相对于对象ROI的像素数的比例。
    
    CameraPose_InTorsoFrame:在FRAME_TORSO中描述拍摄图像时深度相机的Position6D。
    CameraPose_InRobotFrame:在FRAME_ROBOT中描述拍摄图像时深度相机的Position6D。
    Camera_Id:给出用于检测的相机的ID,即深度相机。
    
    

    注释:
    ROI(region of interest),感兴趣区域。机器视觉、图像处理中,从被处理的图像以方框、圆、椭圆、不规则多边形等方式勾勒出需要处理的区域,称为感兴趣区域。

    NAOQI VISION之ALColorBlobDetection

    ALColorBlobDetection是一个提供快速2D视觉彩色斑点检测器的模块。
    ALColorBlobDetection基于快速搜索给定颜色的一组像素(在一定阈值内)。可以选择颜色和它的threhsold,也可以定义对象跨度及其最小尺寸。

    NAOQI VISION之ALDarknessDetection

    ALDarknessDetection可以检查机器人是否处于黑暗环境中。 为相机返回的每个帧计算一个暗度值。该值存储在ALMemory中。当机器人首次检测到其周围的环境较暗(即,暗度值大于阈值)时,会触发事件。

    该功能首先计算对应于机器人周围环境的照明条件的0到100之间的值:
    0:亮环境
    100:暗环境

    然后将该值与黑暗阈值进行比较:
    如果它小于阈值,周围环境不被认为是黑暗的。
    如果它大于阈值,则周围环境被认为是黑暗的。

    黑暗阈值可以使用ALDarknessDetectionProxy :: getDarknessThreshold函数访问。它的默认值为60,但可以使用ALDarknessDetectionProxy :: setDarknessThreshold函数进行更改。

    性能与限制
    必须激活相机的相机AutoExposition参数才能正常工作。

    NAOQI VISION之ALLandMarkDetection

    ALLandMarkDetection是一个视觉模块,其中机器人识别具有特定模式的特殊地标。我们把这些地标称为Naomarks。

    image.png

    您可以使用ALLandMarkDetection模块进行各种应用。例如,您可以将这些地标放置在机器人操作区域的不同位置。根据机器人检测到哪个地标,您可以获取有关机器人位置的一些信息。与其他传感器信息相结合,可以帮助您构建更强大的本地化模块。

    NaoMarks包括以圆圈为中心的白色三角形粉丝的黑色圆圈。不同三角形风扇的具体位置用于区分不同的Naomark。

    性能与限制
    光照:地标检测已经在办公室照明条件下测试通过,即低于100到500 lux。由于检测本身依赖于对比度差异,所以只要输入图像中的标记对比度高一些,实际表现会好一些。
    检测到的标记的尺寸范围:
    最小值:〜0.035 rad = 2 deg它对应于QVGA图像中的〜14像素
    最大值:〜0.40 rad = 23度它对应于QVGA图像中〜160个像素
    倾斜:+/- 60度(0度对应于面向相机的标记)
    图像平面中的旋转:不变。

    使用监视器查看检测结果:
    了解ALLandMarkDetection可以做什么,您可以使用Monitor并启动视觉插件。激活LandMarkDetection复选框并开始摄像。然后,如果您将Naomark放置在摄像机的视野中,Monitor应通过在视频输出窗格中盘点来报告检测到的Naomarks。此外,Naomark标识符显示在圆圈旁边,应该与真实的Naomark标识符相对应。

    image.png

    开始检测:

    要启动Naomark检测功能,请使用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参数指定(以毫秒为单位)ALLandMarkDetection尝试运行其检测方法的频率,并将结果输出到名为LandmarkDetected的ALMemory输出变量中。

    至少对ALLandMarkDetection模块订阅一次,ALLandMarkDetection才能开始运行。

    获取结果:

    ALLandMarkDetection模块将其结果写入ALMemory(LandmarkDetected)中的变量。 您确定要直接在代码中使用检测结果,您可以定期检查ALMemory的变量。
    为此,只需创建一个代理到ALMemory,并从ALMemory代理中使用getData(“LandmarkDetected”)检索Landmark变量。

    变量结果解析:

    如果没有检测到Naomarks,变量为空。它是一个零元素的阵列(即在python中打印为[])。
    如果检测到N Naomarks,则可变结构由两个字段组成: [[TimeStampField] [Mark_info_0,Mark_info_1,。 。 。 ,Mark_info_N-1]]

    TimeStampField = [TimeStamp_seconds,Timestamp_microseconds]。该字段是用于执行检测的图像的时间戳。
    Mark_info = [ShapeInfo,ExtraInfo]。对于每个检测到的标记,我们有一个Mark_info字段。 ShapeInfo = [1,alpha,beta,sizeX,sizeY,heading]。 alpha和beta表示Naomark在相机角度方面的位置;sizeX和sizeY是相机角度的标记尺寸;heading角度描述了关于机器人头部的Naomark是如何面向垂直轴的。
    ExtraInfo = [MarkID]。标记ID是写在Naomark上的数字,对应于其图案。

    NAOQI VISION之ALMovementDetection

    ALMovementDetection允许您检测Aldebaran机器人的视野中的移动。
    Aldebaran机器人使用3D相机(如果有的话),否则它们使用RGB相机。

    以定期的间隔收集帧,并将每个新帧与前一帧进行比较。差异高于阈值的像素被标识为“移动像素”。然后所有的“移动像素”都使用它们的物理接近度和它们的值差异进行聚类。

    对于没有3d相机的Aldebaran机器人,可以使用以下方式更改阈值: - ALMovementDetectionProxy :: setColorSensitivity
    对于具有3d相机的Aldebaran机器人,可以使用以下方式更改阈值: - ALMovementDetectionProxy :: setDepthSensitivity

    ALMemory KEY
    每次检测到一些移动时,ALMemory键的MoveDetection / MovementInfo被更新,并且触发了一个ALMemory事件MoveDetection / MovementDetected。

    存储键包含有关“移动”像素的不同簇的信息。它的组织如下:

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

    Timestamp:该字段是用于执行检测的图像的时间戳。

    TimeStamp [
      TimeStamp_Seconds,
      Timestamp_Microseconds
    ]
    

    这些字段中的每一个都包含“移动”集群的描述。它具有以下结构,具体取决于相机的类型:
    RGB Camera

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

    Depth Camera

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

    All cameras:

    •   PositionOfCog = [x,y] 包含相对于相机中心的集群重心的角坐标(弧度)。
    •   AngularRoi = [x,y,width, height] 包含关于包含集群的最小矩形(ROI)的信息。 [x,y]对应于当前深度图像中ROI的左上角的角坐标(弧度)。 [宽度,高度]对应于ROI的角度大小(弧度)。
    •   ProportionMovingPixels = [In_Frame, In_Roi] 对应于“移动”像素的比例。 In_Frame是相对于帧中像素总数的比例,In_Roi是相对于群集ROI的像素数的比例。
    

    Depth camera only:

    •   MeanDistance 是相对于深度相机(仅用于3D检测)的聚类点的平均距离。
    •   RealSizeRoi = [realwidth,realheight]给出了集群ROI的实际大小(以米计)(仅用于3D检测)。
    •   [X,Y]。使用初始深度图像的分割(参见模块ALSegmentation3D的描述),可以提取移动的斑点。然后可以通过从其重心向上移动来找到该斑点的顶点像素。 [x,y]是该像素的角坐标(弧度)。例如,这些坐标可以非常有用地观察刚刚移动的人的头部,而不是观察运动的重心(仅用于3D检测)。
    

    CameraPose_InTorsoFrame: 在FRAME_TORSO中描述拍摄图像时相机的Position6D。
    CameraPose_InRobotFrame: 在FRAME_ROBOT中描述拍摄图像时相机的Position6D。
    Camera_Id: 给出用于检测的相机的ID。

    相关文章

      网友评论

      • Havoc_Zhang:请问笔者能否把关于pepper相关放入到pepper机器人收录里面呢
        郭少悲:@Havoc_Zhang 可以
        郭少悲:@Havoc_Zhang , 可以的
      • shyern:请问笔者是否继续写NAO API中的相关内容呢?我正在学习NAO的情绪识别方面的信息,希望笔者能提供一些参考信息,谢谢。
        郭少悲:可以参考:http://doc.aldebaran.com/2-5/index_dev_guide.html

      本文标题:NAOQI API之学习笔记

      本文链接:https://www.haomeiwen.com/subject/bgzbxxtx.html