如何在 Choregraphe 的应用程序中导入模块(在其中使用相对较大的包)?

How to import modules(using relatively big packages inside them) in application in Choregraphe?

这些天我正在努力处理我在 Github 项目的帮助下生成的应用程序:Pepper Project robot-jumpstarter

一开始效果很好,但在我在名为“scripts”的文件夹中添加了一些模块后(如图1)就不行了。我的基本想法是将 class 从“IntersectionPointOfTwoCircles.py”导入到“main_localization.py”以使主要工作正常。

并且因为“IntersectionPointOfTwoCircles.py”中需要“sympy”和“numpy”包,所以我首先尝试将这两个包放在“scripts”文件夹中,但是导致了Choregraphe通常只在大约 5 到 10 分钟后才有反应,有时甚至没有反应。 这是 Choregraphe pml 文件“本地化”的路径:

然后我现在让包在应用程序文件夹之外。

“Main_localization”的代码是:

class MyClass(GeneratedClass):
    executable_id = "localization"
    def onLoad(self):
        self.listener_id = None
        self.executable_manager = self.session().service("ALServiceManager")
        executable_name = self.getParameter("Executable Name")
        if ALProxy("ALSystem").systemVersion() < "2.3":
            self.executable_id = executable_name
        if "." not in executable_name:
            self.logger.info("Warning: You will have conflicts if several packages have executables called '%s'" % executable_name)
            self.logger.info("Use a newer version of NAOqi to have executables prefixed with the package ID, or prefix it yourself, in the form with <package>.<executable ID>")
        else:
            self.executable_id = self.packageUid() + "." + executable_name

    def disconnect(self):
        try:
            self.executable_manager.serviceStopped.disconnect(self.listener_id)
        except Exception as e:
            pass

    def onUnload(self):
        self.executable_manager.stopService(self.executable_id)
        self.disconnect()

    def onInput_onStart(self):
        self.listener_id = self.executable_manager.serviceStopped.connect(self.onExecutableStopped)
        if not self.executable_manager.startService(self.executable_id):
            self.logger.info("Failed to start App Executable '%s', stopping." % repr(self.executable_id))
            self.onStopped()
            self.disconnect()

    def onExecutableStopped(self, stopped_executable, reason):
        if stopped_executable == self.executable_id:
            self.logger.info("App Executable Stopped: " + self.executable_id)
        self.onStopped()
        self.disconnect()

    def onInput_onStop(self):
        self.onUnload()
        self.onStopped()

错误信息:

[INFO ] .box :onInput_onStart:29 _Behavior__lastUploadedChoregrapheBehavior1081224720:/Localization_19: Failed to start App Executable ''.lastUploadedChoregrapheBehavior.output.localization'', stopping. 
[INFO ] behavior.box :onInput_onStart:29 _Behavior__lastUploadedChoregrapheBehavior1069884112:/Localization_19: Failed to start App Executable ''.lastUploadedChoregrapheBehavior.output.localization'', stopping. 
[INFO ] behavior.box :onInput_onStart:29 _Behavior__lastUploadedChoregrapheBehavior1149770056:/Localization_19: Failed to start App Executable ''.lastUploadedChoregrapheBehavior.output.localization'', stopping. 

有人知道我现在能做什么吗?

你的 python 库确实应该在你的包中,最好是在你的 "scripts" 文件夹中和你的其他 python 模块,这样你就可以导入它们。

如果库很大,这可能确实会使您的项目变得很大,因此使用 Choregraphe 安装会很慢,但如果您想包含这些库,这必然会发生。当您将这些库放在 "app" 文件夹之外时,它们将不会包含在复制到机器人的包中,因此一旦安装到机器人上就无法使用。

但是 - numpy 应该已经安装在您的机器人上,无需将其包含在您的包中!这可能足以使您的包更小(numpy 相当大)。

(edit) 您还可以使用 PIP 安装库,如此处的答案中所述:Install things on Pepper

pip install --user --upgrade pip

/home/nao/.local/bin/pip install --user whatever-package-you-need

尽管如此,您需要对要在其上使用包裹的每个机器人执行相同的细化。