Lab: Events and the Event Logger
From Tekkotsu Wiki
Learning Goal: This lab will show you how events are represented in Tekkotsu, and introduce you to a tool called the Event Logger that you can use to watch events as they occur on your robot.
Components of an Event
You've already encountered two kinds of events in previous labs. Button press events occur when a button is pressed or released. The =B=> transition looks for these events. Timer events occur when a timer expires. The timeout transition =T(n)=> starts a timer for n milliseconds and then listens for a timer event indicating that the timer has expired.
The major components of an event are the generator ID, the source ID, and the type. These are described in the table below. There are also some less important components, such as the magnitude and duration, which we'll skip for now.
|The thing that generated this event, such as a button press or a timer expiration.|
|source ID||PlayButOffset||For button events, this indicates which button was involved. For timer events, this is the ID number of the timer. (Several timers may be running simultaneously; each will have a different ID number.)|
|The type of event. Pressing a button causes an activate event; releasing the button causes a deactivate event. A status event indicates that something has changed state. Timer events are always status events.|
The letters EGID in the examples above stand for Event Generator ID. The letters ETID stand for Event Type ID.
The Event Logger
You can observe Tekkotsu events using a tool called the Event Logger:
- Run Tekkotsu and connect to it using the ControllerGUI.
- Starting from the ControllerGUI's root menu, go to Root Control > Status Reports Event Logger.
- Click on the buttonEGID checkbox, then press and hold one of the robot's buttons. You should see a button event reported on the Tekkotsu console (in the terminal window); the A stands for activate. Note: if you're running on a simulated robot instead of a real one, you can simulate a button press by typing
post buttonEGID 0 A
in the Tekkotsu terminal window.
- Release the button and you should see a deactivate event. (To simulate a deactivate event, change the "A" to a "D" above.)
- Press a different button and you should see a button event with a different source ID. On the Create and Calliope robots, the Play button has ID 0, Advance has ID 1, and the left and right bumpers have IDs 6 and 7.
- Click on the timerEGID checkbox in the Event Logger menu and you will see that a Tekkotsu background process called Free Memory Report has a timer running once a second. Uncheck the box to stop logging timer events.
- Click on the locomotionEGID checkbox, then use the Walk Control to drive the robot around. You will see that every time the robot changes speed, there is a locmotionEGID event.
- Click on the stateMachineEGID checkbox. Then go to Root Control > User Behaviors and run one of the state machines you created in a previous lab. Notice that when a state node ie entered, this causes an activate event; when a state node deactivates (normally due to a transition firing), this causes a deactivate event.
The EventBase Class
EventBase is the base class for all event types in Tekkotsu. Most events (e.g., timer, button, and state machine events) are instances of EventBase, but some are instances of derived classes that hold additional types of information, such as LocomotionEvent.
Browse the EventBase class documentation. You will see that event generator IDs such as buttonEGID and timerEGID are instances of EventGeneratorID_t, and event type IDs such as activateETID are instances of EventTypeID_t.
EventBase is defined in the file /usr/local/Tekkotsu/Events/EventBase.h.
Logging Events in the Storyboard
You can use the Storyboard with the event logger to graphically display events on a timeline. The event logger selects the events to listen for, as above, and the Storyboard handles the display part. The Lab: Storyboard Tool explains how to do it.
- How many event different generators does Tekkotsu contain? (Count them.)
- How many subclasses of EventBase does Tekkotsu define?
- What is the C++ type of an event source ID?
- In the Event Logger, check the stateTransitionEGID box and run the Annoying Dog state machine from Tutorial: State Machine Intro. In the question below, describe an event by giving the generator ID and event type ID.
- When does a timeout transition activate (not the same as firing)?
- Describe the event that occurs that causes a timeout transition to fire?
- When the transition does fire, describe the event that occurs.
- When does a timeout transition deactivate?
- What is the magnitude of a button press event? (Read the documentation to find out.)
- What information is provided by a LocomotionEvent that is not included in EventBase?
- List three other event class definition files besides EventBase.h that can be found in the Events subdirectory.