Managing the resources between behaviors

A resource is an element needed for executing a task or a program. To speak, NAO uses the TextToSpeech resource. To speak and move the left hand at the same time, NAO uses the TextToSpeech and left arm and hand motors resources. NAO has got many resources such as LEDs, microphones, motors, TextToSpeech, camera settings. You can set for each box the resources that can be used and how to manage the resources between behaviors. Managing the resources is important when exchanging behaviors for two reasons:

For resolving conflicts


You have two behaviors: one makes NAO dance on a music (Tai Chi Chuan box). The second makes NAO walk when the left bumper is touched (Walk Toward + Bumper boxes). As the legs are used for the dance and the walk, you should manage the resources in order to avoid sending contradictory commands to NAO's legs when the 2 behaviors are on NAO.

For synchronizing the resources


Your behavior makes NAO greet with the left hand and say Hello. The two resources need to be available at the same time for the behavior to start.

Setting the Resource Manager


The Resource Manager is an improved solution compared to the Resources Acquisition (in the Timeline). We recommend you to update your older behaviors to replace the Resources Acquisition setting by the Resource Manager.

  1. Right-click a box.
  2. Select Edit resources in the contextual menu.
  3. Define the first setting: i.e. what happens when the same resources are called by another behavior:

    - Lock: the ongoing behavior is not be stopped.

    - Stop on demand: the ongoing behavior is stopped (the OnStop entry of the ongoing box is stimulated).

    - Callback on demand: (for advanced user only) apply the onResource function. You should define the onResource function in the script of the box (see below for more information).

    - Pause on demand (beta): the ongoing behavior is interrupted and starts again when the resources are released. It should be used only for moves (i.e. with timeline).

  4. Define the Timeout: i.e. how long does a behavior should wait for available resources

    - Immediate: if the resources are not immediately available, the box does not play.

    - Wait n seconds: define how long the behavior should wait for available resources. Set how many seconds below.

    - Infinite: this setting should be used only in particular cases when it is possible to wait forever. The behavior does not release the resources and does not stop.

  5. Select in the list the impacted resources (multiple selection is recommended). In a timeline box, you can detect and select the resources used by clicking the Detect button
  6. Click OK.

Setting the onResource function

When set to Callback on demand, the onResource function is called.


Here is an example of the code:

def onResource(self, resource): print "another behavior asks for your resource ", resource

Copyright © 2010 Aldebaran-Robotics - All rights reserved