This tutorial describes an example of the use of 2 logical boxes that you can find in Choregraphe: For and Wait For Signals. Logical boxes are very useful when you want to create more complex behaviors. In Choregraphe, you can find ready-to-use logical boxes but you can also create your own.
Note
You can find For and Wait For Signals boxes in Flow Control in the default box library, but you can also find them and all others using the Search tab!
Example: you would like to create a simple behavior with NAO nodding two times while introducing himself and then starting to wave. The most efficient way to create this behavior is to use the For and Wait for Signals boxes.
Note
If you do not know how to create a movement, please refer to the Movements tutorial.
Note
If you do not know how to customize the sentence said by NAO with the say box, see How to make NAO say something.
If you click on Play, NAO will nod once and introduce himself.
Note
If you are on a real robot, you have to stiffen your robot first (see How to stiffen NAO).
Add a For box to your behavior and set the Final value to 2. Then, connect it to your nodding box.
NAO will nod two times and talk. It’s not bad but we also want NAO to start waving after he has finished nodding and talking. This is quite simple: a Wait For Signals box should be used.
Drag and drop a Wait For Signals box onto the diagram and connect it to the Say and For boxes.
The Wait For Signals box stimulates its output once the two inputs are stimulated.
And finally, add a Hello box to your behavior.
And there you go, NAO starts waving after he has finished nodding and talking!
Note
As a final exercise, you could create a single box that perform all these actions. For this, consult the How to group several boxes into a single one.
All the boxes in Choregraphe have their own script, so you can easily edit them and modify the script.
The script programming language in Choregraphe is Python. Each box in Choregraphe is a module. Briefly, a module is like an application, completely independent, that can run on its own and communicate easily with other modules.
The box creation is done in several steps:
The first two steps are automatic: you have no control over the script. But you have full control over the third step. Actually, this step executes some part of code you have written in the box script.
To examine a box script, drag and drop the “Set LEDs” box onto the diagram panel and double-click on it.
The script window is displayed, showing the following script:
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
#~ puts code for box initialization here
pass
def onUnload(self):
#~ puts code for box cleanup here
pass
def onInput_onSet(self):
ALLeds.fade(self.getParameter("LEDs group"), self.getParameter("Intensity (%)")/100., self.getParameter("Duration (s)"))
self.onReady() # activate output of the box
This box orders the LEDs of a group of LEDs (ear LEDs by default) to switch on (onStart input) in the given amount of time (default 1 second).
When writing script, you must remember that you are defining methods of a module class. A method is a function the program calls to execute each time the same action.
There are 4 methods in the “Set LEDs” script:
In Python, you don’t need to create a proxy (for more information on proxies, see Proxy) to call certain NAOqi modules. This is done automatically. A proxy is an object that allows you to connect to a module on the robot and execute its “bound methods”. For example, ALMemory, ALMotion etc. are modules. ALLeds is the module which controls the LEDs of the robot.
Note
To see a list of the modules and the methods you can use in Choregraphe, you can click on Help->API Reference when connected to a robot or a local NAOqi.
When the behavior starts to play, the initialize method is executed first : GeneratedClass.__init__(self). It is a function which resets the basic box parameters that are common to all the boxes in Choregraphe. After that, the box is a “module” running in NAOqi, on the robot. The box has also initialized all its “parameters” so they are now available in the script. This method is called once per behavior. You can initialize objects that you want to have during the whole behavior (proxies for instance).
Warning
You should never modify the first 3 lines of a script box as they are mandatory.
onLoad method: This method is called when the box flow diagram is loading. It is necessarily called after the __init__ method of all the boxes of the current behavior. When a flow diagram is loading, this method is called on each box of current level before any IO can be stimulated.
onUnload method: This method is called when the box flow diagram is unloading. When a flow diagram is unloading, this method is called on each box of current level. After the flow diagram unloading, boxes are disabled and cannot receive any event on their inputs. Note that the method usually stop everything running in the script, that is what you expect of the onStop input. That is why the latter calls onUnload by default.
onInput_onSet method: This method is called when the onStart is stimulated. It calls ALLeds.fade(self.getParameter(“Leds name”), self.getParameter(“Intensity”), self.getParameter(“Duration”)) . This call to the ALLeds module orders the given group of LEDs to switch on, in a given time, to the geiven intensity. See that we never use hardcoded values, as we want the user to be able to change those values easily through Choregraphe interface. At the end of the onStart method, self.onStopped() stimulates the onStopped output of the “Switch Leds” box.
Now, let’s modify the script a bit. We want to modify the “Set LEDs” box script in order to make NAO’s LEDs group flash five times before switching off. To do so:
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
self.max = 5
def onLoad(self):
#~ puts code for box initialization here
pass
def onUnload(self):
self.i = self.max
#~ puts code for box cleanup here
pass
def onInput_onSet(self):
self.i = 1
while (self.i < self.max):
ALLeds.fade(self.getParameter("LEDs group"), self.getParameter("Intensity (%)")/100., self.getParameter("Duration (s)"))
ALLeds.fade(self.getParameter("LEDs group"), 0, self.getParameter("Duration (s)"))
i += 1
self.onUnload() # activate output of the box
pass
We have used a “while” function in the onStart method to achieve our goal.
When the onSet input is stimulated, NAO will blink 5 times and switch off its LEDs.
Note that a lot of things could be improved in this box: prevent the box from entering the while loop several times (if onSet is stimulated more than once), make the “self.max” count appears as a parameter... Try to modify the scripts of Choregraphe’s default library to create awesome behaviors!
In Choregraphe, it is possible to write your own box, defining their complete workings.
We have already seen how a script works in the Simple modifications of a box script tutorial. As explained above, the first two steps are automatic, the user has no control over it from the script. The second step is done from the links the user has created. But, you have full control over the third step which executes some part of the code you have written in the script.
When writing script, you must remember that you are defining methods of a module class. Attributes, subscribing on ALMemory events... the possibilities are wide open.
Once the box is initialized, the box is ready to be loaded. Whenever the box is loaded and an input is stimulated, a method is called in your script: “onInput_<name>”. This is how you decide what to do when an input is stimulated.
When writing script, you can decide at any time to stimulate an output. The method name that is called is <outputName>(parameter).
For instance:
The generated script of a new box would look like this:
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
#~ puts code for box initialization here
pass
def onUnload(self):
#~ puts code for box cleanup here
pass
def onInput_onStart(self):
#~ self.onStopped() #~ activate output of the box
pass
def onInput_onStop(self):
self.onUnload() #~ it is recommended to call onUnload of this box in a onStop method, as the code written in onUnload is used to stop the box as well
pass
Beyond the initialize method, you have one method associated with each of the box inputs.
The first 3 lines are completely mandatory, and modifying then will lead to strange behavior. What you should modify is the content of the initialize method. You can initialize attributes (such as variables, or proxies to other modules). You should do everything that you only want to do once, because this box will not be destroyed before the end of this behavior.
You will see an “onLoad” method. This is called whenever the box is loaded, which can be caused by one of the three following events:
The behavior is started and the box is at the root level. The box is contained in a behavior keyframe that is being loaded. The box is contained in another box (meaning the latter box has a “flow diagram” offspring), and we stimulated an input of nature “onStart” on the parent box.
Note
This method is called when the box is loaded, so it is strongly advised to avoid heavy code here. Meaning that if a box loading takes too long, the whole behavior will be slowed down. If you are in a timeline, you may even lose real-time.
You can also see an “onUnload” method. This is called whenever the box is unloaded, which can be caused by one of the two events:
The behavior is stopped. The box is contained in a behavior keyframe, and another keyframe of the same layer is being loaded (as the keyframe parent of the current box needs to be unloaded). The box is contained in another box (meaning the latter box has a “flow diagram” offspring), and we stimulated an input of nature “onStop” on the parent box.
Note
This allows you to warn other modules that your box is about to be unloaded and can therefore be very useful. For now you can probably forget about it, you will not need to use this function for simple boxes.
And what about the inputs method? Well the possibilities are unlimited. You are running in separate threads, so take your time, do heavy calculation, it should not affect the playing behavior... Remember that your output(s) will not be stimulated unless you explicitly do so. Meaning you write “onStopped” somewhere in your code. So if you use several script boxes that you have written, and you do not understand why the signal never comes out one of your box, the cause should not be hard to find: you forgot to call the output once your processing is done! Yes it is painful, but this way you can really decide when you want it to be stimulated, which allows you to do powerful things (and also use several outputs as you wish).
So, what about running a little script to increase and decrease intensity over time, with self.step = 0.02 for instance. A classic Python script would look like this:
r = 0
while (r+ self.step < 1):
r = r +self.step
ALLeds.setIntensity ("LeftFootLeds", r)
time.sleep(0.01)
while (r - self.step > 0):
r = r - self.step
ALLeds.setIntensity ("LeftFootLeds", r)
time.sleep(0.01)
Note
If you do not know how to do this, please see How to create a script box.
Note
Three standard entries to your box are automatically created: onStart input, onStop input and onStopped output. You can modify these entries and create new ones by editing the box.
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
self.ledsName = "RightEarLeds"
self.step = 0.01
def onLoad(self):
#~ puts code for box initialization here
self.isRunning = False
pass
def onUnload(self):
#~ puts code for box cleanup here
pass
def onInput_onStart(self):
#~ self.onStopped() #~ activate output of the box
if(self.isRunning):
return
self.isRunning = True
r = 0
while (r + self.step < 1 and self.isRunning):
r += self.step
ALLeds.setIntensity(self.ledsName, r)
time.sleep(self.step)
while (r - self.step > 0 and self.isRunning):
r -= self.step
ALLeds.setIntensity(self.ledsName, r)
time.sleep(self.step)
self.isRunning = False
self.onStopped()
def onInput_onStop(self):
self.onStopped() #~ it is recommended to call onUnload of this box in a onStop method, as the code written in onUnload is used to stop the box as well
pass
Note
Note the code that we had to put in onUnload to make sure the box exits its loop if we call onStop or if the flow diagram is unloaded.
Parameters allow you to customize the way the box works. After having created the parameters of the box, you will not have to edit a single line of script to use it.
To create the parameters of the box:
Right click on the box and select the “Edit box” option.
First, we want to be able to change the group of Leds we are working on, the left or right ear leds for instance. To do so, add a new parameter by clicking on the “+” icon, on the right side of the parameters list which should be empty.
Its name can be “Leds name” for instance. A quick tooltip to explain what it is going to do would be good. The parameter we want to add is a “string”, so select the ‘String’ option in the “Type” field.
In the Content area, you can just enter “RightEarLeds” as a default value but it would not be very nice, as you have actually various other possibilities. It is better to enter several choices in the “Multiple choices” field. To do so, click on the “+” icon then enter “RightEarLeds”. Click on OK then click again on the “+” icon to add the “LeftEarLEds” option for instance.
As we cannot enter all the possibilities (there are too many), we can also check the “Custom string possible” option, which will allow you to enter manually another group directly from the box, without entering again on its properties.
Now, the only thing to do is to enter the script. To do so, right click on the bow then select the “Edit box script” option.
Remove the self.ledsName reference, and replace it with an access to a parameter. To do so, select the reference then right click on it to select “Insert Function > Get parameter > leds name. It should write the following script:
> self.getParameter(“Leds name”)
The script should look like this at the end:
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
self.step = 0.01
def onLoad(self):
#~ puts code for box initialization here
self.isRunning = False
pass
def onUnload(self):
#~ puts code for box cleanup here
pass
def onInput_onStart(self):
#~ self.onStopped() #~ activate output of the box
if(self.isRunning):
return
self.isRunning = True
r = 0
while (r + self.step < 1 and self.isRunning):
r += self.step
ALLeds.setIntensity(self.getParameter("Leds name"), r)
time.sleep(self.step)
while (r - self.step > 0 and self.isRunning):
r -= self.step
ALLeds.setIntensity(self.getParameter("Leds name"), r)
time.sleep(self.step)
self.isRunning = False
self.onStopped()
def onInput_onStop(self):
self.onStopped() #~ it is recommended to call onUnload of this box in a onStop method, as the code written in onUnload is used to stop the box as well
pass
Warning
Make sure you are connected to a real NAO.
This tutorial will show you how to retrieve an ALMemory value directly from your behavior.
Create a flow diagram box, see How to create a new flow diagram box section.
Link it to the beginning of the root behavior.
Your diagram should look like that:
Right click on the box and click on Edit box in the context menu.
Add an input to the box, see How to add/remove inputs, outputs, parameters in a box section.
In the following Add a new input menu, change the input nature to ALMemory Input.
In the AlMemory Value name, select the RightBumperPressed value.
Click on Ok.
Note
Another way to do it is to get into the box, right click on the left were the onStart input is, click on Add input from ALMemory, select the event name and click on Ok.
Now we will use the input value in the box with a simple behavior, double click on the box if you are not already in.
You can see that the created input were added on the left of the flow diagram.
Drag and drop the Flow Control > If box onto your diagram and link it to the RightBumper input.
Note
This box is used to filter the event, the event will be transmitted to the rest of the diagram only if the value is equal to one so the rest of the diagram is executed only when the right bumper is pressed and not released.
Drag and drop the Audio > Voice > Say box onto the diagram and link the onStart inputs to the second output of the if box.
Your diagram should look like that:
Get into the say box and change the text in the Localized Text box into “This is my right bumper”.
Go back to the root diagram and click on the following play button to start the behavior:
Push the right bumper of the robot.
Your nao detects that its bumper were touched.
You are now capable to retrieve an AlMemory value from any behavior.
Congratulation !
Note
If you want, you can get the .crg files here: /your intallation directory/doc/sample/choregraphe/tutorial_almemory_bumper_behavior.crg
Warning
Make sure you are connected to a real NAO.
In this tutorial we will see how to use ALMemory module to transmit your own values between two behaviors.
First, if you want to have more information about the ALMemory module, see the ALMemory API section.
In this tutorial we will create two behaviors, a sender that will raise the event, and a receiver that will receive the event and will make NAO say the value associated to it.
Let’s start with the sender:
Create a new script box, see How to create a new script box section.
Add a parameter to the box, see How to add/remove inputs, outputs, parameters in a box section.
In the following Add a new parameter menu, change the name into “my parameter” and change the parameter type to Integer.
Click on Ok.
Get into the box script by double clicking on the box.
You can see that the structure of the box were automatically generated.
In the onLoad method, create a proxy to the ALMemory module.
In the onStart method, raise an event called myParameterValue with the parameter : “my Parameter”.
The code of the box should look like that:
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
self.memoryProxy = ALProxy("ALMemory")
pass
def onUnload(self):
#~ puts code for box cleanup here
pass
def onInput_onStart(self):
self.memoryProxy.raiseEvent("myParameterValue",self.getParameter("my parameter"))
pass
def onInput_onStop(self):
self.onUnload() #~ it is recommanded to call onUnload of this box in a onStop method, as the code written in onUnload is used to stop the box as well
pass
Close the script editor.
In your diagram, drag and drop the Flow Control > Timer > Time box.
Link it to the beginning of the root behavior.
Link the second output of the timer box to the onStart input of the box that raise the event.
Your diagram should look like that:
Note
The timer box will trigger the raise event each second.
The first behavior is finished, save it using the file menu.
Let’s create the second behavior, click on New using the file menu in the menu bar , be sure that the previous one was correctly saved.
On the left of the root diagram, right click on the input part, click on Add input from AlMemory.
In the event name, write the name you have defined as first attribut of the method raiseEvent, in our case it is “myParameterValue”.
Click on ok.
Drag and drop the Audio > Voice > Say box into the diagram and link it the input you have just created.
Your diagram should look like that:
Save the receiver behavior using the file menu.
Now we will execute the sender and the receiver together, to do it, we will need to execute the receiver using the behavior manager.
Display the behavior manager if it is not displayed, see How to display/hide panels section.
In the Behavior manager panel, click on the following Add current behavior button:
This will add the receiver into the list of behavior that are on the robot.
In the behavior list start the receiver behavior by clicking on its play button.
Open the Sender behavior.
Start the Sender behavior by clicking on the the following play button in the tool bar:
The sender raise the event each second and the receiver retrieve the value.
You can change the value by clicking on the adjustable wrench and by moving the slider.
You can hear your NAO saying the value.
You are now capable to send values from a behavior to another using AlMemory module.
Congratulation !
Note
If you want, you can get the .crg files here: /your intallation directory/doc/sample/choregraphe/tutorial_almemory_sender_behavior.crg
and /your intallation directory/doc/sample/choregraphe/tutorial_almemory_receiver_behavior.crg
Warning
Make sure you are connected to a real NAO.
In this tutorial will see, over an example, how to attach a file to a behavior and how to use it in the box.
Display the Project content, see How to display/hide panels section.
In the Projet content panel click on the following Import file button:
Select the file to attach to the behavior.
When the behavior will be send to the robot, this file will be sent as well.
Now we will create a simple box that will play a music in order to use an attached file as parameter.
Create a new script box in your diagram, see How to create a new script box section.
Add a parameter to the box, see see How to add/remove inputs, outputs, parameters in a box section.
In the Add new parameter menu change the parameter type into Attached file.
Click on Ok.
Right Click on the box and click on Set Parameters in the context menu.
You can now set the attached file by clicking on the browse button in the following Set parameter menu:
Select a .mp3 music file on your disk and click on Ok.
You can see that your file has been added to the Project content.
Now we will edit the script of the box in order to read the music, double click on the box to display the script editor.
As you can see, the structure of the code were automatically generated.
In the onLoad method, create a proxy to AlAudioPlayer module.
If you want to have mode information about the ALAudioPlayer module, see the ALAudioPlayer API section.
In the onStart method, call the method playFile() with the path to the attached file as parameter.
The attached file will be send to the robot when you will start the behavior, so the path has to lead to the attached file on the robot.
The path has to be: ALFrameManager.getBehaviorPath(self.behaviorId) + self.getParameter(“File name”)
It is a concatenation of the behavior path on the robot and the file name.
In the onUnload method, call the method stopAll().
The code of the box should look like that:
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
self.player = ALProxy('ALAudioPlayer')
def onUnload(self):
self.player.stopAll()
def onInput_onStart(self):
self.player.playFile(ALFrameManager.getBehaviorPath(self.behaviorId) + self.getParameter("File name"))
def onInput_onStop(self):
self.onUnload()
In your root diagram, link the onStart input of the box to the beginning of the behavior.
Start the behavior by clicking on the following play button in the tool bar:
Your robot is playing the music given as an attached file.
You are now able to attach a file to a box.
Congratulation !
Note
If you want, you can get the .crg files here: /your intallation directory/doc/sample/choregraphe/tutorial_attached_file.crg
The resources manager is an efficient tool to manage resources between behaviors.
For example, if two behaviors using the audio player resource are executed at the same time, you will want them to obey to a certain priority rule such as “if the first behvior is using the resource, the second has to wait the end of the first behavior.
In this tutorial will see how to manage this kind of situation over several examples.
Let’s create the behavior on which we will be working all along the tutorial.
Drag and drop two Audio > Sound > Play sound box onto your root diagram.
Drag and drop a ** Flow Control > Time > Wait** box onto your root diagram and set the timeout parameter to 4 seconds by cliking on the ajustable wrench in the bottom left corner of the box.
Link the input of the first Play Sound box to the beginning of the root diagram.
Link the input of the second Play Sound box to the output of the Wait box and link the input of the wait box to the beginning of the root diagram.
Your diagram should look like that:
Note
The Wait box is here to delay the second Play Sound box in order to start its execution when the first Play Sound box has taken the audio player resource.
For both Play Sound box set the music file.
Warning
They have to be different and long to detect wich box is executed.
Start the behavior using the following play button in the tool bar:
Without using the resources manager NAO plays both music together.
Let’s see how we can fix this problem:
In this part of the tutorial we will see the effect of taking resources in both Play Sound box.
For both play sound box:
Right click on the box, click on Set Resources in the context menu.
In the resources list select the Audio player resources.
Note
If you want to select several resources you can continiously press the Ctrl key and select other resources.
Click on Ok.
Start the behavior using the following play button in the tool bar:
The first Play Sound box is executed and the second is not because the first one has locked the resource.
Note
If you want, you can get the .crg files here: /your intallation directory/doc/sample/choregraphe/tutorial_resource_manager_lock.crg
In this part will see how we can stop a box that has already locked the resource.
On the first Play Sound box, go to the Resource editor as we did before.
Change Lock to Stop on demand.
On the second Audio player box, go to the Resource editor.
Change the timeout(s) into Wait n seconds....
Set the number of second to 1.
Click on Ok.
Start the behavior using the following play button in the tool bar:
The first Play Sound box is executed and stopped by the execution of the second Play Sound box after one second.
Note
If you want, you can get the .crg files here: /your intallation directory/doc/sample/choregraphe/tutorial_resource_manager_stop_on_demand.crg
With the resource manager, when a resource is locked by a behavior it is possible to call a method when another behavior tries to take the resource too.
In this section will see how it works:
On the first Play Sound box, go to the Resource editor as we did before.
Change Stop on demand to Callback on demand.
Click on Ok.
Right click on the same box and click on Edit box script in the context menu to open the script editor.
You can see that the structure of the code was automatically generated.
Add an onResource method to the script and make NAO says something using the TextToSpeech module see, see the ALTextToSpeech API section.
The code of the box should look like that:
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
self.bIsRunning = False
self.tts = ALProxy('ALTextToSpeech')
def onUnload(self):
self.bIsRunning = False
def onInput_onStart(self):
self.bIsRunning = True
def onResource(self, resource):
self.tts.say("Someone wants to take my resource " + resource)
def onInput_onStop(self):
if( self.bIsRunning ):
self.onUnload()
self.onStopped()
The method onResource will be called when another behavior will want to take the resource.
Start the behavior using the following play button in the tool bar:
The first behavior is executed and when the second behavior tries to lock the resource, the first one call the onResource() method.
You can hear your robot talking.
Note
If you want, you can get the .crg files here: /your intallation directory/doc/sample/choregraphe/tutorial_resource_manager_callback_on_demand.crg
The pause on demand option can be apply only on timeline box.
In this section, will see how to pause an animation because another behavior wants to take the a resource already taken by the animation.
Drag and drop the Motion > Animation > Hello box onto your diagram.
Right click on it and click on Edit resources in the context menu.
In the resources list select the Audio player resource, this should deselect all the resources already selected.
Change Lock to Pause on demand.
Click on Ok.
Replace the first Play sound box by the Hello box.
Your diagram should look like that:
Start the behavior using the following play button in the tool bar:
The animation is started, paused when the Play sound box is executed, and restarted when the resource is released.
Note
If you want, you can get the .crg files here: /your intallation directory/doc/sample/choregraphe/tutorial_resource_manager_pause_on_demand.crg
This tutorial will show you how to enrich your NAO’s possibilities by adding behaviors to its behaviors list using the Choregraphe’s Behavior Manager.
In this section you will learn how to add a behavior to your robot using the Behavior manager, and then we will see how to call it inside a script box.
Let’s create a simple behavior that we will add to the robot:
Drag and drop the Motion > Stand Up and the Motion > Sit Down boxes into your diagram.
Link those two boxes to make it look like this:
Save the behavior.
Display the behavior manager panel if it is not already displayed, see How to display/hide panels section.
To add the behavior on your robot, click on the following Add current behavior in the Manager toolbar:
Set the name of the behavior.
Click on Ok.
You can see that the behavior is added in the list of behaviors that are on the robot.
Congratulation! You have added your first behavior on your robot.
In the behavior list of the Behavior manager click on the play icon to start the behavior.
Your robot executes the behavior.
Note
If you want, you can get the .crg files here: /your intallation directory/doc/sample/choregraphe/tutorial_behavior_manager_behavior_to_call.crg
In this part will see how to call a behavior directly from a box script using the Behavior Manager API.
First, if you want to have more information about the Behavior Manager module, see Behavior Manager API section.
Create a new project.
In the diagram, create a box script, see How to create a new script box section.
Double click on the box to display the script editor.
You can see that the structure of the code was automatically generated.
In the onLoad method, creates a proxy to the BehaviorManager module.
In the onStart method, call the method runBehavior with the name of the behavior previously added to the behavior manager.
In the onUnload method, call the method stopBehavior with the name of the behavior previously added to the behavior manager.
The code of the box should look like that:
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
self.behaviorManagerProxy = ALProxy("ALBehaviorManager")
def onUnload(self):
self.behaviorManagerProxy.stopBehavior("Put here the name of the behavior")
pass
def onInput_onStart(self):
self.behaviorManagerProxy.runBehavior("Put here the name of the behavior")
pass
def onInput_onStop(self):
self.onUnload()
#~ it is recommanded to call onUnload of this box in a onStop method, as the code written in onUnload is used to stop the box as well
pass
Link the input of the box to the beginning of the root behavior.
Start the behavior using the following play button in the tool bar:
Your robot executes the behavior called in the script.
Note
If you look at the Behavior manager during the execution, you can see that the behavior called is running and that you can stop it by clicking on the stop icon.
Congratulation! You have succeed your first call of a behavior added to your robot.
Note
If you want, you can get the .crg files here: /your intallation directory/doc/sample/choregraphe/tutorial_behavior_manager_behavior_that_calls.crg