首页 > 解决方案 > 如何从 Choregraphe 项目中打开/关闭自主生活

问题描述

自主生活可以从 Choregraphe 的 UI 中控制,也可以通过按机器人上的胸部按钮两次来控制,但是,如何从 Choregraphe 项目中做到这一点?在浏览了 Box Library 中的工具列表后,不清楚可以使用哪个工具。

当自主生命开启时,机器人为了看起来还活着,会用头部、手臂和腿做一些小动作。我正在发展的行为是微妙的,很难与自主生命运动区分开来,所以我试图让机器人在我的行为运行之前保持静止。

标签: robotpepper

解决方案


ALAutonomousLife API 提供方法setState

在 Choregraph 中,您可以使用以下内容制作一个 python 框:

class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)
        self.al = ALProxy("ALAutonomousLife")

    def onLoad(self):
        #put initialization code here
        pass

    def onUnload(self):
        #put clean-up code here
        pass

    def onInput_onStart(self):
        self.al.setState("disabled")
        #self.onStopped() #activate the output of the box
        pass

    def onInput_onStop(self):
        self.onUnload() #it is recommended to reuse the clean-up as the box is stopped
        self.onStopped() #activate the output of the box

然后激活此框以禁用 AutonomousLife。

你也可以像这样在 python 控制台中测试它:

import naoqi
from naoqi import ALProxy
al = ALProxy("ALAutonomousLife", "pepper.local", 9559)
al.setState("diabled")

这将与按下胸部按钮两次具有相同的效果。

要仅禁用微妙的自主运动,请查看自主能力

setEnabled提供了一种方法


推荐阅读