Understand Python for Pepper development. -Introduction to Python Box-

Preface

Knowledge of Python is essential for developing Pepper and NAO. So, briefly, I would like to explain the Python box in Naoqi.

Development environment

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

Main subject

Python box

What is a Python box?

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 **

Untitled_-Choregraphe__バーチャルロボットに接続.png

input : "onStart" "onStop" output : "onStopped"

It is a box consisting of.

script

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

Verification

Check how the Python box is called. I put Logger in each function and checked the execution order.

  1. Arranged the unconnected boxes. スクリーンショット 2015-07-17 15.44.12.png

[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. Screenshot 2015-07-17 15.54.44.png

```

[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 ☓. Screenshot 2015-07-17 16.05.47.png

```

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

Impressions

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

Understand Python for Pepper development. -Introduction to Python Box-
Understand Python for Pepper development. -Python box self-made function-
Introduction to Python For, While
An introduction to Python for non-engineers
An introduction to Python for machine learning
An introduction to Python for C programmers
Introduction to Python Let's prepare the development environment
Introduction to Python language
Introduction to OpenCV (python)-(2)
[Introduction to Udemy Python3 + Application] 43. for else statement
Introduction to Programming (Python) TA Tendency for beginners
Python development environment construction 2020 [From Python installation to poetry introduction]
Try to understand Python self
Introduction to serial communication [Python]
[Introduction to Python] <list> [edit: 2020/02/22]
[For organizing] Python development environment
~ Tips for beginners to Python ③ ~
[Introduction to Udemy Python3 + Application] 42. for statement, break statement, and continue statement
An introduction to Python that even monkeys can understand (Part 3)
Introduction to Python for VBA users-Calling Python from Excel with xlwings-
[Python] Introduction to graph creation using coronavirus data [For beginners]
An introduction to Python that even monkeys can understand (Part 1)
An introduction to Python that even monkeys can understand (Part 2)
[Introduction to Udemy Python 3 + Application] 58. Lambda
[Introduction to Udemy Python 3 + Application] 31. Comments
Introduction to Python Numerical Library NumPy
An introduction to Mercurial for non-engineers
Practice! !! Introduction to Python (Type Hints)
[Introduction to Python3 Day 1] Programming and Python
Make a Tweet box for Pepper
[Introduction to Python] <numpy ndarray> [edit: 2020/02/22]
[Introduction to Udemy Python 3 + Application] 57. Decorator
Introduction to Python Hands On Part 1
[Introduction to Python3 Day 13] Chapter 7 Strings (7.1-7.1.1.1)
[Introduction to Python] How to parse JSON
[Introduction to Udemy Python 3 + Application] 56. Closure
[Introduction to Python3 Day 14] Chapter 7 Strings (7.1.1.1 to 7.1.1.4)
Introduction to Protobuf-c (C language ⇔ Python)
[Introduction to Udemy Python3 + Application] 59. Generator
Python development environment options for May 2020
[Introduction to Python3 Day 15] Chapter 7 Strings (7.1.2-7.1.2.2)
[Introduction to Python] Let's use pandas
Emacs settings for Python development environment
[Introduction to Python] Let's use pandas
[Introduction to Udemy Python 3 + Application] Summary
Introduction to image analysis opencv python
[Introduction to Python] Let's use pandas
Record of Python introduction for newcomers
Introduction to Python Django (2) Mac Edition
[AWS SAM] Introduction to Python version
[Introduction to Python3 Day 21] Chapter 10 System (10.1 to 10.5)
[Python Tutorial] An Easy Introduction to Python
Python learning memo for machine learning by Chainer Chapter 8 Introduction to Numpy
Python learning memo for machine learning by Chainer Chapter 10 Introduction to Cupy
[Introduction to Python3 Day 9] Chapter 5 Py's Cosmetic Box: Modules, Packages, Programs (5.1-5.4)
How to use an external editor for Python development with Grasshopper
Python learning memo for machine learning by Chainer Chapter 9 Introduction to scikit-learn
[Introduction to Udemy Python3 + Application] 18. List methods
[Introduction to Udemy Python3 + Application] 63. Generator comprehension
[Introduction to Udemy Python3 + Application] 28. Collective type
Updated "Introduction to Python Web Application Homebrew for Slow 3rd Year Web Engineers"