Tekkotsu Behaviors and Events Drill

  1. Every behavior is a subclass of what class?
    Answer
    BehaviorBase
  2. What are the four essential methods that define a behavior?
    Answer
    constructor, doStart, doStop, doEvent
  3. What are the parent classes of BehaviorBase?
    Answer
    EventListener and ReferenceCounter
  4. How can a behavior retrieve its name?
    Answer
    getName()
  5. Every event is a subclass of what class?
    Answer
    EventBase
  6. What are the three essential components that define an event?
    Answer
    generator ID, source ID, and event type
  7. Define EGID and give an example.
    Answer
    EGID stands for Event Generator ID; it specifies the nature of the event. Examples include buttonEGID for button presses, and timerEGID for timer events.
  8. What are the three event type IDs, called ETIDs?
    Answer
    activateETID, statusETID, and deactivateETID
  9. What is the difference between an EGID and an ETID?
    Answer
    EGID is the generator ID; there are many event generators in Tekkotsu. ETID is the type ID; there are only three types.
  10. What is the class name of the event that is generated when you press one of the robot's buttons?
    Answer
    EventBase
  11. What class of event is generated when you type !msg in the ControllerGUI's message box?
    Answer
    TextMsgEvent
  12. When you receive a button press event, how do you know which button was pressed?
    Answer
    the event's source ID indicates the button
  13. Name two event classes that are subclasses of EventBase.
    Answer
    TextMsgEvent and VisionObjectEvent
  14. What happens if you don't define a doStop method for your behavior?
    Answer
    It inherits the parent class' doStop. This is fine, unless your behavior does things that require cleanup, such as adding persistent motion commands that need to be removed.")"
  15. What happens if you don't define a doStart method for your behavior?
    Answer
    It inherits the parent's doStart. If the parent ie BehaviorBase or StateNode, its doStart does nothing, so your behavior will be a no-op.
  16. What happens if you don't define a doEvent for your behavior?
    Answer
    It inherits the parent's doEvent. If the parent is BehaviorBase or StateNode, then any events your behavior receives will be ignored, since BehaviorBase::doEvent() ignores all events.
  17. Given an event, how do you access its generator ID?
    Answer
    event->getGeneratorID()
  18. Given an event, write an expression to check if it's an activate type of event.
    Answer
    event->getTypeID() == EventBase::activateETID
  19. Name at least three essential subdirectories of the Tekkotsu source tree and describe what each one holds.
    Answer
    Behaviors -- the BehaviorBase class and its subclasses; Events -- the event router and event class definitions; Motion -- the motion manager, and motion command classes; Shared -- model-specific robot information and interface definitions; tools -- monitoring tools like ControllerGUI and SketchGUI
  20. What name does Tekkotsu use for the Create's left bump sensor?
    Answer
    BumpLeftButOffset
  21. In what file are things like PlayButOffset and NumLEDs defined?
    Answer
    Shared/CreateInfo.h
  22. What is the difference between these two expressions?
         1) erouter->addListener(this, EventBase::buttonEGID, RobotInfo::PlayButOffset)
         2) erouter->addListener(this, EventBase::buttonEGID, RobotInfo::PlayButOffset, EventBase::activateETID)
    Answer
    The first one will subscribe to all left front paw button events, so it will be invoked both when the button is pressed (activate) and when it is released (deactivate). The second one only subscribes to activate events.
  23. What does the source ID of a TextMsgEvent indicate?
    Answer
    nothing; it's always -1U, i.e., an unsigned int equal to -1.
  24. What does the source ID of a VisionObjectEvent indicate?
    Answer
    the type of object that was recognized; the default objects are colored balls of various types, such as the pink ball.
  25. Explain every word and special character on the following line:
    virtual void doEvent()
    Answer
    \"virtual\" means this method may be overridden in subclasses; \"void\" is the return type; this method is called for effect; \"doEvent\" is the method behaviors use to handle events; \"()\" indicates that the the method takes no arguments.
  26. In what file is buttonEGID defined?
    Answer
    Events/EventBase.h
  27. In what file is activateETID defined?
    Answer
    Events/EventBase.h
  28. What is Tekkotsu's name for the pink ball vision object?
    Answer
    ProjectInterface::visPinkBallSID
  29. Where is the pink ball vision object source ID defined?
    Answer
    Shared/ProjectInterface.h
  30. What other colors of ball vision objects are defined by default?
    Answer
    blue, green, yellow, orange -- see Shared/ProjectInterface.h
  31. What tool in the ControllerGUI lets you watch for events?
    Answer
    The event logger: Root Control > Status Reports > Event Logger
  32. What file must you include if you want to subscribe to events?
    Answer
    Events/EventRouter.h
  33. How many arguments does addListener take, and what are they?
    Answer
    Between 2 and 4. The first argument should be "this". The next is the generator ID. The last two are optional: source ID and type ID.")"
  34. Why is the first argument to addListener always "this"?
    Answer
    "this" is the address of the behavior instance. We want to add the currently running behavior to the list of event listeners maintained by the event router, so we must pass its address to the event router.")"
  35. In order to access the string stored in a TextMsgEvent, what must your doEvent method first do?
    Answer
    It must cast the event from *EventBase to *TextMsgEvent.
  36. Suppose your behavior is subscribed to both button press events and timer events. What is the first thing that doEvent() should do?
    Answer
    Use a switch statement to dispatch on the event generator ID.
  37. How can your behavior stop listening for vision events as soon as it receives the first one?
    Answer
    Add a call to removeListener in your doEvent() code.
  38. In what units does Tekkotsu measure time?
    Answer
    milliseconds
  39. What function is used to set up a timer?
    Answer
    addTImer
  40. What are the arguments to addTimer?
    Answer
    the behavior's address, the timer id, the timer duration in milliseconds, and a flag indicating whether the timer should repeat")"
  41. How would you set up a timer if you wanted to wait half a second?
    Answer
    erouter->addTimer(this, 999, 500, false);
  42. How would you set up a repeating timer to issue an event every two seconds?
    Answer
    erouter->addTimer(this, 999, 2000, true);
  43. Suppose you set up two repeating timers, one with a period of 2 seconds and one with a period of 3 seconds. When you receive a timer event, how can you tell which timer generated it?
    Answer
    look at the source ID of the event
  44. Why don't you need to use addListener to receive timer events?
    Answer
    The system assumes that the behavior that created a timer is the one that wants to listen for it, so addTimer automatically adds the behavior as a listener.
  45. Why are braces needed in the following code fragment?
         case textmsgEGID: {
           const TextMsgEvent &txtev = dynamic_cast<const TextMsgEvent&>(event);
           cout << "Message received: " << txtev.getText() << endl;
           }
           break;
    Answer
    The braces limit the scope of the variable txtev so that it does not cross case statement boundaries.")"
  46. Given an event as input, write an expression to determine whether it's a vision object event.
    Answer
    event->getGeneratorID() == EventBase::visObjEGID
  47. Given an event as input, write an expression to return the area of a vision object if it's a vision object event, else zero.
    Answer
    event->getGeneratorID() == EventBase::visObjEGID ? dynamic_cast<const VisionObjectEvent&>(event).getObjectArea() : 0 &quot;)"
  48. What does a VisionObjectEvent of type statusETID mean?
    Answer
    the robot still sees the object, and is updating its position and size.
  49. What does a VisionObjectEvent of type deactivateETID mean?
    Answer
    the robot has lost sight of the object