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, processEvent
  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 processEvent for your behavior?
    Answer
    It inherits the parent's processEvent. If the parent is BehaviorBase or StateNode, then any events your behavior receives will be ignored, since BehaviorBase::processEvent() 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 processEvent(const EventBase &event)
    Answer
    \"virtual\" means this method may be overridden in subclasses; \"void\" is the return type; this method is called for effect; \"processEvent\" is the method behaviors use to handle events; \"(\" indicates the beginning of the method's argument list; \"const\" means the argument will not be modified; \"EventBase\" is the parent class for all events; \"&\" means the argument is passed as a reference, not copied; \"event\" is the (arbitrary) name of the method's argument; \")\" indicates the end of the argument list
  26. Why is the argument to processEvent declared const?
    Answer
    Because it should not be modified by processEvent
  27. Why is the argument to processEvent passed by reference?
    Answer
    For efficiency reasons, as some types of events can contain large amounts of data. Copying them would be slow.
  28. Why isn't the argument to processEvent passed as a pointer?
    Answer
    This is a stylistic decision. You should use a reference when the argument must always be valid. You should use a pointer argument when you need a way to express a missing or invalid argument; pass a null pointer in that situation.")"
  29. In what file is buttonEGID defined?
    Answer
    Events/EventBase.h
  30. In what file is activateETID defined?
    Answer
    Events/EventBase.h
  31. What is Tekkotsu's name for the pink ball vision object?
    Answer
    ProjectInterface::visPinkBallSID
  32. Where is the pink ball vision object source ID defined?
    Answer
    Shared/ProjectInterface.h
  33. What other colors of ball vision objects are defined by default?
    Answer
    blue, green, yellow, orange -- see Shared/ProjectInterface.h
  34. What tool in the ControllerGUI lets you watch for events?
    Answer
    The event logger: Root Control > Status Reports > Event Logger
  35. What file must you include if you want to subscribe to events?
    Answer
    Events/EventRouter.h
  36. 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.")"
  37. 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.")"
  38. In order to access the string stored in a TextMsgEvent, what must your processEvent method first do?
    Answer
    It must cast the argument from an EventBase reference to a TextMsgEvent reference.
  39. Suppose your behavior is subscribed to both button press events and timer events. What is the first thing that processEvent() should do?
    Answer
    Use a switch statement to dispatch on the event generator ID.
  40. 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 processEvent() code.
  41. In what units does Tekkotsu measure time?
    Answer
    milliseconds
  42. What function is used to set up a timer?
    Answer
    addTImer
  43. 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")"
  44. How would you set up a timer if you wanted to wait half a second?
    Answer
    erouter->addTimer(this, 999, 500, false);
  45. How would you set up a repeating timer to issue an event every two seconds?
    Answer
    erouter->addTimer(this, 999, 2000, true);
  46. 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
  47. 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.
  48. 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.")"
  49. Given an event as input, write an expression to determine whether it's a vision object event.
    Answer
    event.getGeneratorID() == EventBase::visObjEGID
  50. 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;)"
  51. What does a VisionObjectEvent of type statusETID mean?
    Answer
    the robot still sees the object, and is updating its position and size.
  52. What does a VisionObjectEvent of type deactivateETID mean?
    Answer
    the robot has lost sight of the object