Pepper Robot: How to port Python landmark detection to Choregraphe?

僤鯓⒐⒋嵵緔 提交于 2019-12-06 12:14:50

问题


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

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

This code

gives this error message :

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

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

Greetings Frederik


回答1:


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.

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.

So some approaches:

  • 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.

(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).



来源:https://stackoverflow.com/questions/50929031/pepper-robot-how-to-port-python-landmark-detection-to-choregraphe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!