Knowledge of Python is essential for developing Pepper and NAO. So, briefly, I would like to explain the Python box in Naoqi.
Model name: MacBook Pro OS : Yosemite 10.10.3 Processor name: Intel Core i5 2.6 GHz Memory: 16 GB Graphics: Intel Iris 1536MB Choreographe : 2.3.1
First of all, I would like to briefly explain about Python boxes. The Python box can be found at the following in the box library:
If not, please search from the magnifying glass mark.
** [Programming]-> [Template]-> Python Box **
input : "onStart" "onStop" output : "onStopped"
It is a box consisting of.
All the boxes in Choreographe are basically created based on the following configuration. The script looks like this:
#You can see that the derived class of GeneratedClass is MyClass.
class MyClass(GeneratedClass):
#The first thing that is called when the behavior is loaded__init__(self)is.
def __init__(self):
#Generated Class__init__(self)You can see that we are overriding.
GeneratedClass.__init__(self)
#Let's put what is called when the behavior is loaded here.
def onLoad(self):
#put initialization code here
#Let's put in the initialization process here.
#Called after behavior is loaded and all init is called.
pass
def onUnload(self):
#put clean-up code here
#When the application is closed, onInput_Called when there is an input to onStop.
pass
def onInput_onStart(self):
#self.onStopped() #activate the output of the box
#Called when there is an input to onStart.
#self.onStopped()Please note that the output will not be made unless is described.
pass
def onInput_onStop(self):
#Called when there is an input to onStop.
self.onUnload() #it is recommended to reuse the clean-up as the box is stopped
self.onStopped() #activate the output of the box
Check how the Python box is called. I put Logger in each function and checked the execution order.
Arranged the unconnected boxes.
[INFO] init 0 [INFO] init 1 [INFO] init 2 [INFO] init 3 [INFO] onLoad 0 [INFO] onLoad 1 [INFO] onLoad 2 [INFO] onLoad 3 #Double click on root onStop here [INFO] onUnload 0 [INFO] onUnload 1 [INFO] onUnload 2 [INFO] onUnload 3 ``` You can see that init is called and onLoad is called. After that, onUnload is called in order and ends. 2. I tried to connect in series.
```
[INFO] init 0 [INFO] init 1 [INFO] init 2 [INFO] init 3 [INFO] onLoad 0 [INFO] onLoad 1 [INFO] onLoad 2 [INFO] onLoad 3 [INFO] onInput_onStart 0 ``` As I wrote above, if you do not add self.onStopped () to the "onInput_onStart" method, no output will be made. So, next, let's verify with the one with self.onStopped (). 3.2 with self.onStopped () in 2. Added self.onStopped () to "onInput_onStart" method.
```
[INFO] init 0 [INFO] init 1 [INFO] init 2 [INFO] init 3 [INFO] onLoad 0 [INFO] onLoad 1 [INFO] onLoad 2 [INFO] onLoad 3 [INFO] onInput_onStart 0 [INFO] onInput_onStart 1 [INFO] onInput_onStart 2 [INFO] onInput_onStart 3 [INFO] onUnload 0 [INFO] onUnload 1 [INFO] onUnload 2 [INFO] onUnload 3 ``` It was output correctly to the end. 4. I left the script as it was and connected it to ☓.
```
[INFO] init 0 [INFO] init 1 [INFO] init 2 [INFO] init 3 [INFO] onLoad 0 [INFO] onLoad 1 [INFO] onLoad 2 [INFO] onLoad 3 [INFO] onInput_onStop 0 [INFO] onUnload 0 [INFO] onInput_onStop 1 [INFO] onUnload 1 [INFO] onInput_onStop 2 [INFO] onUnload 2 #Attention [INFO] onUnload 3 [INFO] onInput_onStop 3 [INFO] onUnload 0 [INFO] onUnload 1 [INFO] onUnload 2 [INFO] onUnload 3 ``` I have just described it as attention, but you can see that the order of onInput_onStop and onUnload is reversed and called. I've repeated it several times, but I don't know if the writing order is reversed or the calling order is reversed, but sometimes it works in the correct order, such as 0 ~ 2, and 3 It may be reversed as in the case of. ** The cause is unknown. ** It may be a bug in Choreographe.
Also note that onUnload is called twice. It is called twice, when you input to ☓ and when the behavior ends.
As a continuation of the article, I would like to write how to use my own functions and how to use external libraries.
Recommended Posts