Exploring Tekkotsu Programming on Mobile Robots:

Behaviors

Prev: Files and directories
Up: Contents
Next: Events

The applications that users create on the AIBO, called Behaviors, are implemented as classes that inherit from the base class BehaviorBase. Tekkotsu instantiates the class when the behavior is to be activated, and normally destroys the instance when the behavior is deactivated. There are quite a few behaviors already built in to Tekkotsu, which you can activate and deactivate using the ControllerGUI.

Exercise: Talking to the AIBO

Boot the AIBO using the standard Tekkotsu memory stick and then open a telnet connection to it on port 59000. For example, if your AIBO is named fido, you would type "telnet fido 59000". When the connection is made you will see some startup messages that were generated by Tekkotsu and the AIBO's operating system, Aperios.

Start the ControllerGUI by typing "ControllerGUI fido". (Note: if your search path is not set up properly, you may have to type something like "/usr/local/Tekkotsu/tools/mon/ControllerGUI fido".) Click on "Raw Cam" to call up a viewer for the AIBO's camera image.

Double click on "Background Behaviors" and then "StareAtBallBehavior", and activate it by double clicking. The name will change to #StareAtBallBehavior and its color will change to red, indicating that the behavior is active. Un-pause the AIBO by clicking on the Stop/Go icon. Now, move the pink ball back and forth in front of the AIBO and it should move its head to keep the ball centered in the camera image.

Behaviors provide four essential member functions: a constructor, DoStart(), DoStop(), and processEvent(). DoStart() is called when the Behavior is activated; its job is to allocate and initialize whatever structures the Behavior requires, and to subscribe the Behavior instance to whichever event streams the Behavior cares about. DoStop() is called when the Behavior is deactivated, and is expected to undo whatever was done in DoStart(). The processEvent() method handles event notifications as they are received; this is where much of the real work of the Behavior gets done. Behaviors also require at least one constructor function, and in the most general case they have three constructors.

Exercise: Writing Your First Behavior

Name your first behavior using your initials, to keep it distinct from behaviors others in your work group may write. If your initials are dst, copy the code below into the file DstBehavior.h in your ~/project directory:

#ifndef INCLUDED_DstBehavior_h_
#define INCLUDED_DstBehavior_h_
 
#include "Behaviors/BehaviorBase.h"

class DstBehavior : public BehaviorBase {
public:
  DstBehavior() : BehaviorBase("DstBehavior") {}
 
  virtual void DoStart() {
    BehaviorBase::DoStart();
    std::cout << getName() << " is starting up." << std::endl;
  }
 
  virtual void DoStop() {
    std::cout << getName() << " is shutting down." << std::endl;
    BehaviorBase::DoStop();
  }

};

#endif

In order to include your Behavior in the Tekkotsu system, you must add it to the menu of behaviors in the file StartupBehavior_SetupModeSwitch.cc. This requires inserting two lines into that file. First, insert the following line in the list of #include statements at the beginning:

#include "DstBehavior.h"

Second, insert the following line just before the corresponding line for SampleBehavior:

addItem(new BehaviorSwitchControl<DstBehavior>("DstBehavior",bg,false));

After completing these edits, put the memory stick in the writer and type "make update". Once compilation completes and the memory stick has been succesfully updated, place it back in the AIBO and reboot. If ControllerGUI is still running it should reconnect automatically; otherwise, start it up again. Also open a telnet connection to the AIBO on port 59000.

Now go to ControllerGUI and, from the Root Control menu, double click on Mode Switch, then double click on DstBehavior to activate your behavior. You should see the "starting up" message in the telnet window. Click on DstBehavior again to deactivate it.

Explore more:

  1. Skim the documentation for BehaviorBase, which is a subclass of EventListener. What else is it a subclass of? What other member functions does it provide?

  2. Look up the source code for BehaviorBase::DoStart() and BehaviorBase::DoStop(). What do these functions do? A link to the source for each function can be found in the "Member Function Documentation" section of the BehaviorBase documentation.

Prev: Files and directories
Up: Contents
Next: Events

Last modified: Wed Jan 16 00:55:22 EST 2008