Drake
Drake C++ Documentation
EventCollection< EventType > Class Template Referenceabstract

Detailed Description

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
EventTypea concrete derived type of Event (e.g., PublishEvent).

#include <drake/systems/framework/event_collection.h>

Public Member Functions

virtual ~EventCollection ()
 
void SetFrom (const EventCollection< EventType > &other)
 Clears all the events maintained by this then adds all of the events in other to this. More...
 
void AddToEnd (const EventCollection< EventType > &other)
 Adds all of other's events to the end of this. More...
 
virtual void Clear ()=0
 Removes all events from this collection. More...
 
virtual bool HasEvents () const =0
 Returns false if and only if this collection contains no events. More...
 
virtual void AddEvent (EventType event)=0
 Adds an event to this collection, or throws if the concrete collection does not permit adding new events. More...
 
Does not allow copy, move, or assignment
 EventCollection (const EventCollection &)=delete
 
EventCollectionoperator= (const EventCollection &)=delete
 
 EventCollection (EventCollection &&)=delete
 
EventCollectionoperator= (EventCollection &&)=delete
 

Protected Member Functions

 EventCollection ()=default
 Constructor only accessible by derived class. More...
 
virtual void DoAddToEnd (const EventCollection< EventType > &other)=0
 

Constructor & Destructor Documentation

◆ EventCollection() [1/3]

EventCollection ( const EventCollection< EventType > &  )
delete

◆ EventCollection() [2/3]

EventCollection ( EventCollection< EventType > &&  )
delete

◆ ~EventCollection()

virtual ~EventCollection ( )
virtual

◆ EventCollection() [3/3]

EventCollection ( )
protecteddefault

Constructor only accessible by derived class.

Member Function Documentation

◆ AddEvent()

virtual void AddEvent ( EventType  event)
pure virtual

Adds an event to this collection, or throws if the concrete collection does not permit adding new events.

Derived classes must implement this method to add the specified event to the homogeneous event collection.

Implemented in LeafEventCollection< EventType >, and DiagramEventCollection< EventType >.

◆ AddToEnd()

void AddToEnd ( const EventCollection< EventType > &  other)

Adds all of other's events to the end of this.

◆ Clear()

virtual void Clear ( )
pure virtual

Removes all events from this collection.

Implemented in LeafEventCollection< EventType >, and DiagramEventCollection< EventType >.

◆ DoAddToEnd()

virtual void DoAddToEnd ( const EventCollection< EventType > &  other)
protectedpure virtual

◆ HasEvents()

virtual bool HasEvents ( ) const
pure virtual

Returns false if and only if this collection contains no events.

Implemented in LeafEventCollection< EventType >, and DiagramEventCollection< EventType >.

◆ operator=() [1/2]

EventCollection& operator= ( EventCollection< EventType > &&  )
delete

◆ operator=() [2/2]

EventCollection& operator= ( const EventCollection< EventType > &  )
delete

◆ SetFrom()

void SetFrom ( const EventCollection< EventType > &  other)

Clears all the events maintained by this then adds all of the events in other to this.


The documentation for this class was generated from the following files: