Knowledge of Python is essential for developing Pepper and NAO. Therefore, I will continue to aim to be able to create and use Python boxes, especially functions. Also, I haven't met many people who handle Choreographe who originally used python, so I would like to write an explanation so that even such people can improve the python box.
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
python2.7
Let's go to the main subject quickly.
Basically, the project is:
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
#put initialization code here
pass
def onUnload(self):
#put clean-up code here
pass
def onInput_onStart(self):
#I need output, so self.onStopped()Enable
self.onStopped() #activate the output of the box
#pass #Comment out because it is not necessary
def onInput_onStop(self):
self.onUnload() #it is recommended to reuse the clean-up as the box is stopped
self.onStopped() #activate the output of the box
I will start playing with it from here.
First, let's create a simple function.
def testFunc(self):
pass
I think it's okay to feel like this.
def testFunc(self):
This is what I call an argumentless function. Be sure to write the self variable because it is a variable that is passed to any function.
pass
This shows an empty function.
def onInput_onStart(self):
self.testFunc() #In this way, you can specify the method of your class as ◯◯.
self.onStopped() #activate the output of the box
First, let's create a simple function.
def testFunc2(self,a,b):
c=a*b
self.logger.info(c)
I think it's okay to feel like this.
def testFunc(self):
This is what I call an argumentless function. Be sure to write the self variable because it is a variable that is passed to any function.
def onInput_onStart(self):
self.testFunc2(10,20) #In this way, you can specify the method of your class as ◯◯.
self.onStopped() #activate the output of the box
Output result
200
For the time being, it will end around here.
Recommended Posts