Pepper Robot:如何将Python界标检测移植到Choregraphe? [英] Pepper Robot: How to port Python landmark detection to Choregraphe?

查看:189
本文介绍了Pepper Robot:如何将Python界标检测移植到Choregraphe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个小程序,让Pepper通过Choregraphe检查房间内的地标.用于地标检测的常规Python代码可以正常工作,但是我无法将其移植到Choregraphe.

I'm trying to write a small programm to have Pepper check for landmarks inside a room through Choregraphe. The regular Python code for landmark detection works just fine, but i can't port it to Choregraphe.http://doc.aldebaran.com/2-5/dev/python/examples/vision/landmark.html

根据该视频,我已经可以在Choregraphe中导入简单的Python文件,但是在进行地标检测时始终会出现错误. https://www.youtube.com/watch?v=orDWxHQxw5s

I could already import the simple Python File in Choregraphe according to this video, but there's always an error when doing it with the landmark detection. https://www.youtube.com/watch?v=orDWxHQxw5s

此代码

给出此错误消息:

[ERROR] behavior.box :createPythonModule:0
_Behavior__lastUploadedChoregrapheBehaviorbehavior_11118986952:/Landmark 
Detektor_1: Box creation failed with the error: <type 
'exceptions.RuntimeError'> Application was already initialized

如何将Python界标检测成功移植到Choregraphe代码?

How do i successfully port the Python landmark detection to Choregraphe code?

问候 弗雷德里克

推荐答案

我不建议直接在Choregraphe中进行过多的自定义Python.当然,这是可能,但是通常很难调试和维护.

I wouldn't recommended doing too much custom Python directly in Choregraphe. It's possible, sure, but it's often difficult to debug and maintain.

这两个工作原理不同的原因是,独立的Python脚本必须处理与机器人的连接,会话管理等.所有这些工作都已经在Choregraphe中执行Python时处理了.

The reason the two work differently is that standalone Python scripts have to take care of the connection to the robot, session management, etc. all of which is already handled when the Python is being executed in Choregraphe.

一些方法:

  • 尝试像在做的那样在Choregraphe框内完成这项工作.我不推荐这样做,但是基本上您不需要qi.Application,并且在一个盒子内您可以使用self.session()进行会话(而不是独立Python中的application.session或ALProxy).这可以工作,但是很难用源代码控制来跟踪您的项目,也很难对其进行调试(例如,如果某个地方存在无限循环,即使行为停止了,它也可以继续运行,并且所有日志都可以获取)在所有其他NAOqi原木中间丢失了.)
  • 将代码保存在外部库(没有qi.Application等)中和Choregraphe内部:将该库的路径附加到sys.path中,以便可以导入和使用它.这将使代码更易于维护和组织,但仍然存在调试问题(但我仍然看到它已在成功的应用程序中使用).
  • 在Choregraphe之外将代码作为进程执行-这次,您需要保留qi.Application()等,并从Choregraphe触发该脚本.您可以在 robot-jumpstarter (特别是"pythonapp"项目)中看到一个示例,名义上这是Choregraphe的行为,但是它所做的只是启动包含所有逻辑的外部脚本(如果脚本崩溃,它将停止应用程序;如果应用程序停止,它将停止脚本,仍然不会出现幻影python代码就像您使用Choregraphe一样运行,并且您的日志位于/var/log/naoqi/servicemanager/中自己的文件中).这是我通常要做的.
  • Try to make this work inside a Choregraphe box, like you're doing. I don't recommend it, but basically you don't need qi.Application, and inside a box you can get the session with self.session() (instead of application.session or ALProxy in standalone Python). This will work, but it will be hard to keep track of your project with source control, and hard to debug it (e.g. if you have an infinite loop somewhere, it can keep running even if the behavior is stopped, and all your logs get lost in the middle of all the other NAOqi logs).
  • Have your code in an external library (without qi.Application etc.) and inside Choregraphe: append that library's path to sys.path so that you can import it and use it. This will make the code easier to maintain and organize, but still has the same issues for debbuging (but I've still seen it used in successful apps).
  • Have your code executed as a process outside Choregraphe - this time you'll need to keep qi.Application() etc. and trigger that script from Choregraphe. You can see an example of that working in robot-jumpstarter, specifically the "pythonapp" project, which is nominally a Choregraphe behavior but all it does is start the external script, that contains all the logic (and if the script crashes it stops the app, and if the app stop it stops the script, with no chances of ghost python code still running like you might get with Choregraphe, and your logs are in their own file in /var/log/naoqi/servicemanager/). This is what I usually do.

(编辑以添加)这最后一种方法的一个优点是,您可以在工作计算机上运行独立的Python脚本(通过将--qi-url your-peppers-ip作为命令行参数传递)(因此,您可以直接在自己喜欢的IDE中获取所有日志,并且仅 这些日志),对结果满意后,即可使用Choregraphe将其安装在机器人上.

(edit to add) One advantage to this last approach is that you can run your standalone Python script on your work computer (passing --qi-url your-peppers-ip as a command-line parameter) while testing it (so you get all your logs directly in your favourite IDE, and only those logs), and once you're satisfied with the result, install it on the robot with Choregraphe).

这篇关于Pepper Robot:如何将Python界标检测移植到Choregraphe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆