- Every behavior is a subclass of what class?
Answer
BehaviorBase
- What are the four essential methods that define a behavior?
Answer
constructor, DoStart, DoStop, processEvent
- What are the parent classes of BehaviorBase?
Answer
EventListener and ReferenceCounter
- How can a behavior retrieve its name?
Answer
getName()
- Every event is a subclass of what class?
Answer
EventBase
- What are the three essential components that define an event?
Answer
generator ID, source ID, and event type
- 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.
- What are the three event type IDs, called ETIDs?
Answer
activateETID, statusETID, and deactivateETID
- 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.
- What is the class name of the event that is generated when you press one of the robot's buttons?
Answer
EventBase
- What class of event is generated when you type !msg in the ControllerGUI's message box?
Answer
TextMsgEvent
- When you receive a button press event, how do you know which button was pressed?
Answer
the event's source ID indicates the button
- Name two event classes that are subclasses of EventBase.
Answer
TextMsgEvent and VisionObjectEvent
- 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.")"
- 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.
- 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.
- Given an event, how do you access its generator ID?
Answer
event.getGeneratorID()
- Given an event, write an expression to check if it's an activate type of event.
Answer
event.getTypeID() == EventBase::activateETID
- 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
- What name does Tekkotsu use for the Create's left bump sensor?
Answer
BumpLeftButOffset
- In what file are things like PlayButOffset and NumLEDs defined?
Answer
Shared/CreateInfo.h
- 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.
- What does the source ID of a TextMsgEvent indicate?
Answer
nothing; it's always -1U, i.e., an unsigned int equal to -1.
- 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.
- 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
- Why is the argument to processEvent declared const?
Answer
Because it should not be modified by processEvent
- 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.
- 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.")"
- In what file is buttonEGID defined?
Answer
Events/EventBase.h
- In what file is activateETID defined?
Answer
Events/EventBase.h
- What is Tekkotsu's name for the pink ball vision object?
Answer
ProjectInterface::visPinkBallSID
- Where is the pink ball vision object source ID defined?
Answer
Shared/ProjectInterface.h
- What other colors of ball vision objects are defined by default?
Answer
blue, green, yellow, orange -- see Shared/ProjectInterface.h
- What tool in the ControllerGUI lets you watch for events?
Answer
The event logger: Root Control > Status Reports > Event Logger
- What file must you include if you want to subscribe to events?
Answer
Events/EventRouter.h
- 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.")"
- 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.")"
- 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.
- 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.
- 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.
- In what units does Tekkotsu measure time?
Answer
milliseconds
- What function is used to set up a timer?
Answer
addTImer
- 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")"
- How would you set up a timer if you wanted to wait half a second?
Answer
erouter->addTimer(this, 999, 500, false);
- How would you set up a repeating timer to issue an event every two seconds?
Answer
erouter->addTimer(this, 999, 2000, true);
- 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
- 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.
- 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.")"
- Given an event as input, write an expression to determine whether it's a vision object event.
Answer
event.getGeneratorID() == EventBase::visObjEGID
- 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 ")"
- What does a VisionObjectEvent of type statusETID mean?
Answer
the robot still sees the object, and is updating its position and size.
- What does a VisionObjectEvent of type deactivateETID mean?
Answer
the robot has lost sight of the object