template<typename EventType>
class drake::systems::EventCollection< EventType >
There are three concrete event types for any System: publish, discrete state update, and unrestricted state update, listed in order of increasing ability to change the state (i.e., zero to all).
EventCollection is an abstract base class that stores simultaneous events of the same type that occur at the same time (i.e., simultaneous events).
The Simulator promises that for each set of simultaneous events of the same type, the public event handling method (e.g., System::Publish(context, publish_events)) will be invoked exactly once.
The System API provides several functions for customizable event generation such as System::DoCalcNextUpdateTime() or System::DoGetPerStepEvents(). These functions can return any number of events of arbitrary types, and the resulting events are stored in separate CompositeEventCollection instances. Before calling the event handlers, all of these CompositeEventCollection objects must be merged to generate a complete set of simultaneous events. Then, only events of the appropriate type are passed to the event handlers. e.g. sys.Publish(context, combined_event_collection.get_publish_events()). For example, the Simulator executes this collation process when it is applied to simulate a system.
Here is a complete example. For some LeafSystem sys
at time t
, its System::DoCalcNextUpdateTime() generates the following CompositeEventCollection (events1
):
PublishEvent: {event1(kPeriodic, callback1)}
DiscreteUpdateEvent: {event2(kPeriodic, callback2)}
UnrestrictedUpdateEvent: {}
This LeafSystem also desires per-step event processing(events2
), generated by its implementation of System::DoGetPerStepEvents():
PublishEvent: {event3(kPerStep, callback3)}
DiscreteUpdateEvent: {}
UnrestrictedUpdateEvent: {event4(kPerStep,callback4)}
These collections of "simultaneous" events, events1
and events2
, are then merged into the composite event collection all_events
:
PublishEvent: {event1, event3}
DiscreteUpdateEvent: {event2}
UnrestrictedUpdateEvent: {event4}
This heterogeneous event collection can be processed by calling the appropriate handler on the appropriate homogeneous subcollection:
sys.CalcUnrestrictedUpdate(context,
all_events.get_unrestricted_update_events(), state);
sys.CalcDiscreteVariableUpdate(context,
all_events.get_discrete_update_events(), discrete_state);
sys.Publish(context, all_events.get_publish_events())
- Template Parameters
-