How to Upload a Behavior to Nao Robot?

Boxes¶

Using logical boxes¶

This tutorial describes an case of the use of 2 logical boxes that yous can discover in Choregraphe: For and Wait For Signals. Logical boxes are very useful when you want to create more complex behaviors. In Choregraphe, y'all tin find ready-to-use logical boxes but you can also create your own.

Notation

Yous tin find For and Look For Signals boxes in Flow Control in the default box library, but you can also discover them and all others using the Search tab!

How to apply these logical boxes together?¶

Example: yous would similar to create a simple behavior with NAO nodding ii times while introducing himself and then starting to moving ridge. The most efficient way to create this behavior is to use the For and Wait for Signals boxes.

  1. Create a new box and make it of timeline type (refer to How to create a Timeline box), and create a elementary nodding movement behavior with the motion timeline. Connect its input to the main input of the behavior.

Note

If you exercise non know how to create a movement, please refer to the Movements tutorial.

  1. Drag and drop the Say box, write NAO's introduction judgement (e.yard. "Howdy I am NAO the little robot and I am gear up to serve you lot, master!") and connect its input to the main input of the behavior.

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 starting time (meet How to stiffen NAO).

  1. Add together a For box to your behavior and set the Concluding value to 2. And then, connect it to your nodding box.

    ../../../_images/chore_tuto_loop.png

    NAO will nod two times and talk. Information technology'southward not bad only we besides desire NAO to start waving after he has finished nodding and talking. This is quite unproblematic: a Wait For Signals box should be used.

  2. Drag and driblet 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 in one case the two inputs are stimulated.

  3. And finally, add a Hullo box to your beliefs.

    ../../../_images/chore_tuto_motionloopwaitwalk.png

    And in that location you get, NAO starts waving after he has finished nodding and talking!

Uncomplicated modifications of a box script¶

All the boxes in Choregraphe have their own script, so you lot can hands edit them and alter the script.

Clarification of the script logic¶

The script programming language in Choregraphe is Python. Each box in Choregraphe is a module. Briefly, a module is similar an application, completely contained, that tin run on its own and communicate easily with other modules.

The box cosmos is done in several steps:

  1. Instantiation of the box
  2. Registration of the box as a module then it tin can be called from other boxes through linking
  3. Box initialization

The offset ii steps are automated: yous have no control over the script. But you accept full command over the third step. Really, this step executes some role of code you have written in the box script.

Description of a box script¶

To examine a box script, drag and drop the "Set LEDs" box onto the diagram console and double-click on it.

The script window is displayed, showing the following script:

                form                MyClass                (                GeneratedClass                ):                def                __init__                (                self                ):                GeneratedClass                .                __init__                (                cocky                )                def                onLoad                (                self                ):                #~ puts code for box initialization here                laissez passer                def                onUnload                (                self                ):                #~ puts lawmaking for box cleanup here                pass                def                onInput_onSet                (                self                ):                ALLeds                .                fade                (                self                .                getParameter                (                "LEDs group"                ),                cocky                .                getParameter                (                "Intensity (%)"                )                /                100.                ,                cocky                .                getParameter                (                "Elapsing (south)"                ))                self                .                onReady                ()                # activate output of the box              

This box orders the LEDs of a grouping 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 aforementioned action.

There are iv methods in the "Set LEDs" script:

  • initialize
  • onLoad
  • onUnload
  • onInput_onSet

How does the Fix LEDs script work?¶

In Python, y'all don't need to create a proxy (for more than data on proxies, come across Proxy) to call certain NAOqi modules. This is washed 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 come across a list of the modules and the methods y'all can use in Choregraphe, you can click on Assist->API Reference when connected to a robot or a local NAOqi.

  1. When the behavior starts to play, the initialize method is executed outset : GeneratedClass.__init__(cocky). Information technology 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 likewise initialized all its "parameters" so they are now available in the script. This method is called one time per behavior. You can initialize objects that you want to have during the whole behavior (proxies for instance).

    Warning

    You should never alter the first 3 lines of a script box as they are mandatory.

  2. 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 beliefs. When a menses diagram is loading, this method is called on each box of current level before any IO tin exist stimulated.

  3. 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. Subsequently the flow diagram unloading, boxes are disabled and cannot receive whatsoever event on their inputs. Note that the method usually cease everything running in the script, that is what y'all await of the onStop input. That is why the latter calls onUnload by default.

  4. onInput_onSet method: This method is called when the onStart is stimulated. It calls ALLeds.fade(self.getParameter("Leds name"), cocky.getParameter("Intensity"), self.getParameter("Duration")) . This phone 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 hands through Choregraphe interface. At the cease of the onStart method, self.onStopped() stimulates the onStopped output of the "Switch Leds" box.

Modifying the script¶

Now, let'due south alter the script a bit. Nosotros want to modify the "Set LEDs" box script in lodge to make NAO's LEDs group flash five times earlier switching off. To do so:

  1. Modify the script box every bit follows:
                class                MyClass                (                GeneratedClass                ):                def                __init__                (                self                ):                GeneratedClass                .                __init__                (                self                )                self                .                max                =                v                def                onLoad                (                self                ):                #~ puts code for box initialization here                laissez passer                def                onUnload                (                cocky                ):                self                .                i                =                self                .                max                #~ puts lawmaking for box cleanup here                pass                def                onInput_onSet                (                self                ):                cocky                .                i                =                1                while                (                self                .                i                <                self                .                max                ):                ALLeds                .                fade                (                cocky                .                getParameter                (                "LEDs grouping"                ),                self                .                getParameter                (                "Intensity (%)"                )                /                100.                ,                self                .                getParameter                (                "Duration (southward)"                ))                ALLeds                .                fade                (                self                .                getParameter                (                "LEDs group"                ),                0                ,                cocky                .                getParameter                (                "Elapsing (s)"                ))                i                +=                i                self                .                onUnload                ()                # activate output of the box                laissez passer              
  1. 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.

  2. Notation that a lot of things could exist improved in this box: prevent the box from entering the while loop several times (if onSet is stimulated more than once), make the "cocky.max" count appears equally a parameter... Try to modify the scripts of Choregraphe's default library to create awesome behaviors!

Creating a box script from scratch using parameters¶

Introduction¶

In Choregraphe, it is possible to write your ain box, defining their complete workings.

  • We accept already seen how a script works in the Simple modifications of a box script tutorial. Every bit explained to a higher place, the beginning two steps are automatic, the user has no control over it from the script. The 2nd step is done from the links the user has created. But, you accept full control over the third step which executes some part of the code you have written in the script.

    When writing script, yous must remember that you lot 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 exist loaded. Whenever the box is loaded and an input is stimulated, a method is called in your script: "onInput_<name>". This is how yous determine what to do when an input is stimulated.

  • When writing script, you can determine at any time to stimulate an output. The method name that is chosen is <outputName>(parameter).

How does it piece of work?¶

For case:

  • If you have an onStopped output that is of "bang" type, calling onStopped() should exercise the chore.
  • If you have a faceDetected(string) output, you tin call faceDetected("Robert") to warn that Robert has been detected.

The generated script of a new box would look like this:

                form                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 hither                pass                def                onInput_onStart                (                self                ):                #~ self.onStopped() #~ activate output of the box                pass                def                onInput_onStop                (                self                ):                self                .                onUnload                ()                #~ it is recommended to phone call onUnload of this box in a onStop method, as the code written in onUnload is used to end the box also                laissez passer              
  • Beyond the initialize method, you take 1 method associated with each of the box inputs.

  • The first 3 lines are completely mandatory, and modifying then volition atomic number 82 to foreign behavior. What you should modify is the content of the initialize method. You can initialize attributes (such every bit variables, or proxies to other modules). You should practise everything that you simply want to exercise in one case, because this box volition non be destroyed before the end of this behavior.

  • You volition see an "onLoad" method. This is called whenever the box is loaded, which can be caused by one of the 3 following events:

    The beliefs 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 independent in another box (pregnant the latter box has a "menses diagram" offspring), and we stimulated an input of nature "onStart" on the parent box.

    Note

    This method is called when the box is loaded, then it is strongly brash to avoid heavy lawmaking hither. Meaning that if a box loading takes as well long, the whole beliefs volition be slowed down. If you are in a timeline, yous may fifty-fifty lose real-fourth dimension.

  • You can also see an "onUnload" method. This is called whenever the box is unloaded, which tin can be acquired past one of the two events:

    The behavior is stopped. The box is contained in a behavior keyframe, and another keyframe of the aforementioned 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 "menstruation 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 exist unloaded and tin can therefore exist very useful. For now you can probably forget most it, you will not need to apply this function for simple boxes.

  • And what nigh the inputs method? Well the possibilities are unlimited. You are running in separate threads, so take your fourth dimension, do heavy calculation, it should not affect the playing behavior... Call back that your output(s) volition non be stimulated unless you explicitly practise so. Meaning you write "onStopped" somewhere in your lawmaking. So if you use several script boxes that you have written, and you do non understand why the signal never comes out ane of your box, the cause should not exist hard to find: you forgot to call the output one time your processing is washed! Yeah it is painful, only this fashion y'all can actually decide when you lot want it to exist stimulated, which allows you to do powerful things (and besides utilise several outputs as you wish).

Instance¶

  • You lot find the LEDs of your robot very nice, but you would like to use script to switch them on. Well, what should you exercise? First, read the ALLeds documentation: this is the module that allows the user to plough on/off the LEDs. If you lot read the documentation, y'all should find that the methods are quite uncomplicated. For instance, turning the left anxiety LEDs requires the following control: setIntensity("LeftFootLeds", r) with r between 0 and i.

So, what near running a little script to increment and decrease intensity over time, with self.footstep = 0.02 for case. A classic Python script would look like this:

                r                =                0                while                (                r                +                self                .                step                <                1                ):                r                =                r                +                cocky                .                pace                ALLeds                .                setIntensity                (                "LeftFootLeds"                ,                r                )                time                .                slumber                (                0.01                )                while                (                r                -                cocky                .                step                >                0                ):                r                =                r                -                self                .                step                ALLeds                .                setIntensity                (                "LeftFootLeds"                ,                r                )                fourth dimension                .                sleep                (                0.01                )              
  • Now, create a new box called "RightEarLeds".

Note

Iii standard entries to your box are automatically created: onStart input, onStop input and onStopped output. You can modify these entries and create new ones past editing the box.

  1. Double-click on the box to edit its script box.
  2. Write the script to increment and subtract intensity over fourth dimension. The "RightEarLeds" script should await similar this:
                class                MyClass                (                GeneratedClass                ):                def                __init__                (                self                ):                GeneratedClass                .                __init__                (                self                )                self                .                ledsName                =                "RightEarLeds"                self                .                footstep                =                0.01                def                onLoad                (                cocky                ):                #~ puts code for box initialization here                self                .                isRunning                =                False                pass                def                onUnload                (                self                ):                #~ puts lawmaking for box cleanup here                laissez passer                def                onInput_onStart                (                cocky                ):                #~ self.onStopped() #~ activate output of the box                if                (                self                .                isRunning                ):                render                self                .                isRunning                =                Truthful                r                =                0                while                (                r                +                self                .                step                <                1                and                self                .                isRunning                ):                r                +=                self                .                step                ALLeds                .                setIntensity                (                self                .                ledsName                ,                r                )                time                .                slumber                (                cocky                .                step                )                while                (                r                -                cocky                .                step                >                0                and                self                .                isRunning                ):                r                -=                self                .                step                ALLeds                .                setIntensity                (                self                .                ledsName                ,                r                )                time                .                slumber                (                self                .                stride                )                self                .                isRunning                =                Fake                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                laissez passer              

Annotation

Note the code that we had to put in onUnload to brand certain the box exits its loop if nosotros call onStop or if the flow diagram is unloaded.

Using parameters¶

Parameters allow you to customize the way the box works. Later on having created the parameters of the box, you will non have to edit a unmarried line of script to use it.

To create the parameters of the box:

  1. Right click on the box and select the "Edit box" choice.

  2. Starting time, we desire to exist able to alter 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 correct side of the parameters list which should exist empty.

  3. Its name can be "Leds name" for instance. A quick tooltip to explain what information technology is going to practice would be expert. The parameter we want to add is a "string", so select the 'Cord' pick in the "Type" field.

  4. In the Content surface area, you tin just enter "RightEarLeds" as a default value but information technology would not exist very nice, as you have actually diverse other possibilities. It is better to enter several choices in the "Multiple choices" field. To practise so, click on the "+" icon then enter "RightEarLeds". Click on OK and then click again on the "+" icon to add the "LeftEarLEds" option for instance.

  5. Every bit we cannot enter all the possibilities (there are besides many), we can also cheque the "Custom string possible" choice, which volition let you lot to enter manually another group directly from the box, without inbound again on its backdrop.

  6. At present, the only thing to do is to enter the script. To do then, right click on the bow and so select the "Edit box script" option.

  7. Remove the self.ledsName reference, and replace it with an access to a parameter. To exercise and so, select the reference then correct click on it to select "Insert Part > Get parameter > leds proper noun. It should write the post-obit script:

    > self.getParameter("Leds name")

  8. The script should look similar this at the cease:

                class                MyClass                (                GeneratedClass                ):                def                __init__                (                self                ):                GeneratedClass                .                __init__                (                self                )                self                .                pace                =                0.01                def                onLoad                (                self                ):                #~ puts code for box initialization here                self                .                isRunning                =                False                laissez passer                def                onUnload                (                self                ):                #~ puts lawmaking for box cleanup here                pass                def                onInput_onStart                (                self                ):                #~ self.onStopped() #~ activate output of the box                if                (                self                .                isRunning                ):                return                self                .                isRunning                =                Truthful                r                =                0                while                (                r                +                self                .                pace                <                one                and                self                .                isRunning                ):                r                +=                self                .                footstep                ALLeds                .                setIntensity                (                self                .                getParameter                (                "Leds proper name"                ),                r                )                fourth dimension                .                sleep                (                cocky                .                step                )                while                (                r                -                self                .                step                >                0                and                self                .                isRunning                ):                r                -=                self                .                step                ALLeds                .                setIntensity                (                self                .                getParameter                (                "Leds proper name"                ),                r                )                fourth dimension                .                sleep                (                self                .                step                )                self                .                isRunning                =                False                self                .                onStopped                ()                def                onInput_onStop                (                cocky                ):                cocky                .                onStopped                ()                #~ information technology is recommended to call onUnload of this box in a onStop method, as the code written in onUnload is used to cease the box too                laissez passer              
  1. At present, you just have to on the wrench of the box to alter the side of ear leds that will fade over time. As you tin can see, creating a box from scratch is not besides complicated!

Creating a box to retrieve right bumper value using ALMemory¶

Warning

Make certain you are connected to a existent NAO.

This tutorial will show you how to retrieve an ALMemory value directly from your behavior.

  1. Create a flow diagram box, run across How to create a new flow diagram box department.

  2. Link it to the beginning of the root beliefs.

    Your diagram should look similar that:

    ../../../_images/right_bumper_root.png
  3. Right click on the box and click on Edit box in the context menu.

  4. Add an input to the box, come across How to add/remove inputs, outputs, parameters in a box section.

  5. In the following Add together a new input carte, alter the input nature to ALMemory Input.

    ../../../_images/chore_add_new_input.jpg
  6. In the AlMemory Value name, select the RightBumperPressed value.

  7. Click on Ok.

    Note

    Another mode 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 issue name and click on Ok.

  8. Now nosotros will use the input value in the box with a simple beliefs, double click on the box if you are not already in.

    You lot can meet that the created input were added on the left of the flow diagram.

  9. Elevate 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 effect will be transmitted to the rest of the diagram but if the value is equal to one so the residual of the diagram is executed only when the right bumper is pressed and non released.

  10. Drag and drib the Audio > Vocalization > Say box onto the diagram and link the onStart inputs to the 2d output of the if box.

    Your diagram should expect like that:

    ../../../_images/right_bumper_box_in.png
  11. Get into the say box and alter the text in the Localized Text box into "This is my correct bumper".

  12. Go back to the root diagram and click on the post-obit play button to showtime the behavior:

    ../../../_images/beginning_play_button1.png
  13. Push the right bumper of the robot.

    Your nao detects that its bumper were touched.

You lot are now capable to retrieve an AlMemory value from any beliefs.

Congratulation !

Annotation

If you desire, you can get the .crg files here: /your intallation directory/physician/sample/choregraphe/tutorial_almemory_bumper_behavior.crg

Transmit a value from a behavior to some other using ALMemory events¶

Warning

Make sure you are connected to a existent 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 data about the ALMemory module, see the ALMemory API section.

In this tutorial we will create two behaviors, a sender that will enhance the result, and a receiver that will receive the event and will make NAO say the value associated to it.

Permit'due south start with the sender:

  1. Create a new script box, meet How to create a new script box section.

  2. Add a parameter to the box, come across How to add/remove inputs, outputs, parameters in a box department.

  3. In the following Add a new parameter menu, change the proper name into "my parameter" and change the parameter type to Integer.

    ../../../_images/add_parameter_menu.png
  4. Click on Ok.

  5. Get into the box script by double clicking on the box.

    You tin see that the structure of the box were automatically generated.

  6. In the onLoad method, create a proxy to the ALMemory module.

  7. In the onStart method, enhance an effect called myParameterValue with the parameter : "my Parameter".

    The code of the box should look similar that:

    class MyClass(GeneratedClass):    def __init__(self):    GeneratedClass.__init__(self)     def onLoad(self):       self.memoryProxy = ALProxy("ALMemory")       pass     def onUnload(self):       #~ puts lawmaking for box cleanup hither       laissez passer     def onInput_onStart(self):       cocky.memoryProxy.raiseEvent("myParameterValue",self.getParameter("my parameter"))       laissez passer     def onInput_onStop(self):       cocky.onUnload() #~ it is recommanded to call onUnload of this box in a onStop method, as the lawmaking written in onUnload is used to stop the box as well       pass
  8. Close the script editor.

  9. In your diagram, drag and driblet the Flow Control > Timer > Time box.

  10. Link information technology to the showtime of the root behavior.

  11. Link the second output of the timer box to the onStart input of the box that heighten the event.

    Your diagram should look like that:

    ../../../_images/tuto_memory_sender.png

    Note

    The timer box will trigger the heighten event each 2nd.

  12. The first beliefs is finished, save information technology using the file card.

  13. Permit's create the second behavior, click on New using the file carte du jour in the menu bar , be certain that the previous one was correctly saved.

  14. On the left of the root diagram, right click on the input part, click on Add together input from AlMemory.

  15. In the event name, write the name you have divers as outset attribut of the method raiseEvent, in our instance it is "myParameterValue".

  16. Click on ok.

  17. Elevate and drop the Sound > Vox > Say box into the diagram and link it the input you lot have only created.

    Your diagram should wait like that:

    ../../../_images/tuto_memory_receiver.png
  18. Salve the receiver behavior using the file menu.

  19. Now we will execute the sender and the receiver together, to exercise it, we will need to execute the receiver using the behavior manager.

  20. Brandish the behavior manager if it is not displayed, run across How to brandish/hibernate panels section.

  21. In the Behavior director console, click on the following Add together electric current behavior button:

    ../../../_images/export2-logo-16.png

    This will add the receiver into the list of behavior that are on the robot.

  22. In the behavior listing commencement the receiver behavior by clicking on its play button.

  23. Open the Sender behavior.

  24. Start the Sender behavior by clicking on the the following play button in the tool bar:

    ../../../_images/beginning_play_button1.png

    The sender raise the event each second and the receiver retrieve the value.

    Yous can change the value by clicking on the adjustable wrench and by moving the slider.

    You tin 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 tin can become the .crg files here: /your intallation directory/doc/sample/choregraphe/tutorial_almemory_sender_behavior.crg

and /your intallation directory/medico/sample/choregraphe/tutorial_almemory_receiver_behavior.crg

Adhere a file to a beliefs¶

Warning

Make certain you are connected to a real NAO.

In this tutorial will see, over an instance, how to attach a file to a beliefs and how to use information technology in the box.

  1. Brandish the Projection content, see How to display/hide panels section.

  2. In the Projet content panel click on the following Import file button:

    ../../../_images/chore_project_content_import.png
  3. Select the file to attach to the behavior.

    When the behavior will be ship to the robot, this file volition be sent equally well.

At present we will create a simple box that will play a music in social club to use an fastened file as parameter.

  1. Create a new script box in your diagram, see How to create a new script box section.

  2. Add a parameter to the box, run across meet How to add together/remove inputs, outputs, parameters in a box section.

  3. In the Add new parameter menu alter the parameter type into Attached file.

  4. Click on Ok.

  5. Correct Click on the box and click on Set up Parameters in the context menu.

  6. You tin can now set the attached file by clicking on the browse push in the following Set up parameter carte du jour:

    ../../../_images/set_parameter_attached_file.png
  7. Select a .mp3 music file on your disk and click on Ok.

    You lot can see that your file has been added to the Projection content.

    ../../../_images/content_panel_attached_file.png
  8. At present nosotros volition edit the script of the box in society to read the music, double click on the box to display the script editor.

    Every bit you lot can see, the structure of the lawmaking were automatically generated.

  9. In the onLoad method, create a proxy to AlAudioPlayer module.

    If yous desire to have mode data virtually the ALAudioPlayer module, see the ALAudioPlayer API section.

  10. 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 offset the behavior, and 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.

  11. In the onUnload method, phone call the method stopAll().

    The code of the box should expect like that:

    class MyClass(GeneratedClass):    def __init__(self):    GeneratedClass.__init__(cocky)     def onLoad(self):       self.histrion = ALProxy('ALAudioPlayer')     def onUnload(cocky):       self.player.stopAll()     def onInput_onStart(self):       cocky.player.playFile(ALFrameManager.getBehaviorPath(self.behaviorId) + cocky.getParameter("File proper noun"))     def onInput_onStop(self):       self.onUnload()
  12. In your root diagram, link the onStart input of the box to the beginning of the beliefs.

  13. Starting time the behavior by clicking on the post-obit play button in the tool bar:

    ../../../_images/beginning_play_button1.png
  14. Your robot is playing the music given as an fastened file.

Yous are now able to attach a file to a box.

Congratulation !

Note

If you want, you tin can get the .crg files here: /your intallation directory/doc/sample/choregraphe/tutorial_attached_file.crg

Using the resource manager¶

The resources manager is an efficient tool to manage resources between behaviors.

For example, if two behaviors using the audio role player resource are executed at the aforementioned time, y'all will want them to obey to a certain priority dominion such as "if the first behvior is using the resource, the 2nd has to wait the finish of the starting time behavior.

In this tutorial will meet how to manage this kind of situation over several examples.

Let's create the behavior on which nosotros volition exist working all forth the tutorial.

  1. Elevate and drop two Sound > Sound > Play sound box onto your root diagram.

  2. Elevate and drib 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.

  3. Link the input of the commencement Play Sound box to the offset of the root diagram.

  4. Link the input of the second Play Sound box to the output of the Wait box and link the input of the look box to the offset of the root diagram.

    Your diagram should wait like that:

    ../../../_images/resource_manager_tuto_base.png

    Note

    The Look box is here to delay the 2nd Play Sound box in order to get-go its execution when the beginning Play Sound box has taken the sound player resources.

  5. For both Play Sound box fix the music file.

    Warning

    They have to be unlike and long to detect wich box is executed.

  6. Start the beliefs using the following play button in the tool bar:

    ../../../_images/beginning_play_button1.png

    Without using the resources manager NAO plays both music together.

Let's come across how we tin can ready this problem:

Lock the resource¶

In this function of the tutorial we will encounter the consequence of taking resource in both Play Audio box.

For both play sound box:

  1. Right click on the box, click on Set Resource in the context carte.

  2. In the resources list select the Sound player resources.

    Notation

    If yous desire to select several resources yous can continiously printing the Ctrl key and select other resources.

  3. Click on Ok.

  4. Starting time the behavior using the post-obit play button in the tool bar:

    ../../../_images/beginning_play_button1.png

The starting time Play Sound box is executed and the second is not because the outset one has locked the resource.

Note

If you want, you lot can get the .crg files here: /your intallation directory/doc/sample/choregraphe/tutorial_resource_manager_lock.crg

End on demand¶

In this part will see how we can stop a box that has already locked the resource.

  1. On the first Play Sound box, become to the Resource editor as nosotros did before.

  2. Change Lock to End on need.

  3. On the 2nd Audio thespian box, go to the Resource editor.

  4. Change the timeout(due south) into Expect n seconds....

  5. Set up the number of second to 1.

  6. Click on Ok.

  7. Get-go the behavior using the post-obit play button in the tool bar:

    ../../../_images/beginning_play_button1.png

The offset Play Sound box is executed and stopped by the execution of the second Play Sound box after one 2nd.

Notation

If you want, you tin can get the .crg files here: /your intallation directory/dr./sample/choregraphe/tutorial_resource_manager_stop_on_demand.crg

Callback on need¶

With the resource manager, when a resources is locked by a behavior it is possible to phone call a method when another beliefs tries to take the resource too.

In this section will run into how information technology works:

  1. On the first Play Sound box, go to the Resource editor as nosotros did earlier.

  2. Modify Stop on demand to Callback on demand.

  3. Click on Ok.

  4. Right click on the same box and click on Edit box script in the context carte du jour to open the script editor.

    You can encounter that the structure of the code was automatically generated.

  5. Add an onResource method to the script and make NAO says something using the TextToSpeech module see, see the ALTextToSpeech API section.

    The lawmaking of the box should look like that:

    form MyClass(GeneratedClass):    def __init__(self):    GeneratedClass.__init__(self)     def onLoad(cocky):       self.bIsRunning = False       self.tts = ALProxy('ALTextToSpeech')     def onUnload(self):       cocky.bIsRunning = Imitation     def onInput_onStart(self):       self.bIsRunning = True     def onResource(self, resources):       self.tts.say("Someone wants to accept my resource " + resource)     def onInput_onStop(self):       if( self.bIsRunning ):           cocky.onUnload()           self.onStopped()

    The method onResource volition be called when some other beliefs will want to accept the resource.

  6. Kickoff the beliefs using the following play button in the tool bar:

    ../../../_images/beginning_play_button1.png

The first behavior is executed and when the 2nd behavior tries to lock the resource, the first one call the onResource() method.

You can hear your robot talking.

Note

If you desire, you can get the .crg files hither: /your intallation directory/doc/sample/choregraphe/tutorial_resource_manager_callback_on_demand.crg

Pause on need¶

The pause on demand option tin can be apply only on timeline box.

In this section, will see how to pause an blitheness considering some other behavior wants to accept the a resource already taken past the blitheness.

  1. Elevate and drop the Movement > Animation > Hullo box onto your diagram.

  2. Correct click on it and click on Edit resource in the context menu.

  3. In the resources list select the Audio player resources, this should deselect all the resources already selected.

  4. Modify Lock to Intermission on demand.

  5. Click on Ok.

  6. Replace the first Play sound box by the Hello box.

    Your diagram should wait like that:

    ../../../_images/resource_manager_tuto_pause_on_demand.png
  7. Start the beliefs using the post-obit play push button in the tool bar:

    ../../../_images/beginning_play_button1.png

The animation is started, paused when the Play audio box is executed, and restarted when the resource is released.

Note

If you want, yous can become the .crg files here: /your intallation directory/doc/sample/choregraphe/tutorial_resource_manager_pause_on_demand.crg

Enrich Nao's behaviors list¶

This tutorial will testify you how to enrich your NAO'due south possibilities past adding behaviors to its behaviors list using the Choregraphe'due south Beliefs Director.

In this section you will learn how to add a behavior to your robot using the Behavior manager, so nosotros will see how to phone call it inside a script box.

Add together a behavior to your NAO using the Behavior manager¶

Let'south create a simple behavior that we volition add together to the robot:

  1. Drag and drop the Motion > Stand up Upwardly and the Motion > Sit down Down boxes into your diagram.

  2. Link those two boxes to brand information technology look similar this:

    ../../../_images/behavior_manager_behavior_to_call.png
  3. Save the behavior.

  4. Display the behavior managing director console if information technology is not already displayed, see How to display/hide panels section.

  5. To add together the beliefs on your robot, click on the post-obit Add current beliefs in the Manager toolbar:

    ../../../_images/behavior_manager_add_current.png
  6. Set the name of the behavior.

  7. Click on Ok.

    You tin can see that the beliefs is added in the list of behaviors that are on the robot.

    ../../../_images/behavior_to_call_added.png

    Congratulation! Y'all accept added your first behavior on your robot.

  8. In the behavior list of the Behavior manager click on the play icon to get-go the behavior.

    Your robot executes the beliefs.

Note

If y'all want, you can go the .crg files here: /your intallation directory/doc/sample/choregraphe/tutorial_behavior_manager_behavior_to_call.crg

Call a behavior from a box script¶

In this part volition meet how to telephone call a behavior directly from a box script using the Behavior Manager API.

Starting time, if you lot want to take more information well-nigh the Behavior Manager module, see Beliefs Director API department.

  1. Create a new project.

  2. In the diagram, create a box script, run across How to create a new script box section.

  3. Double click on the box to display the script editor.

    You tin run across that the structure of the code was automatically generated.

  4. In the onLoad method, creates a proxy to the BehaviorManager module.

  5. In the onStart method, call the method runBehavior with the name of the beliefs previously added to the beliefs director.

  6. In the onUnload method, telephone call the method stopBehavior with the proper name of the beliefs previously added to the behavior managing director.

    The lawmaking of the box should await like that:

    class MyClass(GeneratedClass):    def __init__(self):    GeneratedClass.__init__(cocky)     def onLoad(self):       self.behaviorManagerProxy = ALProxy("ALBehaviorManager")     def onUnload(self):       self.behaviorManagerProxy.stopBehavior("Put hither the name of the behavior")       laissez passer     def onInput_onStart(self):       cocky.behaviorManagerProxy.runBehavior("Put hither the proper noun of the behavior")       pass     def onInput_onStop(cocky):       self.onUnload()       #~ it is recommanded to phone call onUnload of this box in a onStop method, as the lawmaking written in onUnload is used to stop the box likewise       laissez passer
  7. Link the input of the box to the beginning of the root behavior.

  8. Beginning the behavior using the post-obit play push in the tool bar:

    ../../../_images/beginning_play_button1.png

    Your robot executes the beliefs chosen in the script.

Annotation

If you await at the Behavior managing director during the execution, you can come across that the behavior called is running and that yous can stop information technology past clicking on the stop icon.

Congratulation! You have succeed your first call of a beliefs added to your robot.

Note

If y'all desire, you tin become the .crg files here: /your intallation directory/dr./sample/choregraphe/tutorial_behavior_manager_behavior_that_calls.crg

hendersonflaved.blogspot.com

Source: http://www.cs.cmu.edu/~cga/nao/doc/reference-documentation/software/choregraphe/tutos/boxes.html

0 Response to "How to Upload a Behavior to Nao Robot?"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel