Abstract base class that represents an event.
The base event contains two main pieces of information: an enum trigger type and an optional attribute that can be used to explain why the event is triggered.
Concrete derived classes contain a function pointer to an optional callback that handles the event. No-op is the default handling behavior. The System framework supports three concrete event types: PublishEvent, DiscreteUpdateEvent, and UnrestrictedUpdateEvent distinguished by their callback functions' write access level to the State.
The most common and convenient use of events and callbacks will happen via the LeafSystem Declare*Event() methods. To that end, the callback signature always passes the const System<T>&
as the first argument, so that LeafSystem does not need to capture this
into the lambda; typically only a pointer-to-member- function is captured. Capturing any more than that would defeat std::function's small buffer optimization and cause heap allocations when scheduling events.
Event handling occurs during a simulation of a system. The logic that describes when particular event types are handled is described in the class documentation for Simulator.
#include <drake/systems/framework/event.h>
Public Types | |
using | TriggerType = systems::TriggerType |
Public Member Functions | |
virtual | ~Event ()=default |
virtual bool | is_discrete_update () const =0 |
Returns true if this is a DiscreteUpdateEvent. More... | |
std::unique_ptr< Event > | Clone () const |
Clones this instance. More... | |
TriggerType | get_trigger_type () const |
Returns the trigger type. More... | |
template<typename EventDataType > | |
bool | has_event_data () const |
Returns true if this event has associated data of the given EventDataType . More... | |
template<typename EventDataType > | |
const EventDataType * | get_event_data () const |
Returns a const pointer to the event data. More... | |
template<typename EventDataType > | |
EventDataType * | get_mutable_event_data () |
Returns a mutable pointer to the event data. More... | |
void | AddToComposite (TriggerType trigger_type, CompositeEventCollection< T > *events) const |
Adds a clone of this event to the event collection events , with the given trigger type. More... | |
void | AddToComposite (CompositeEventCollection< T > *events) const |
Provides an alternate signature for adding an Event that already has the correct trigger type set. More... | |
Protected Member Functions | |
Event ()=default | |
Constructs an empty Event. More... | |
virtual void | DoAddToComposite (TriggerType trigger_type, CompositeEventCollection< T > *events) const =0 |
Derived classes must implement this to add a clone of this Event to the event collection and unconditionally set its trigger type. More... | |
virtual Event * | DoClone () const =0 |
Derived classes must implement this method to clone themselves. More... | |
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable | |
Event (const Event &)=default | |
Event & | operator= (const Event &)=default |
Event (Event &&)=default | |
Event & | operator= (Event &&)=default |
using TriggerType = systems::TriggerType |
|
virtualdefault |
void AddToComposite | ( | TriggerType | trigger_type, |
CompositeEventCollection< T > * | events | ||
) | const |
Adds a clone of this
event to the event collection events
, with the given trigger type.
If this
event has an unknown trigger type, then any trigger type is acceptable. Otherwise the given trigger type must match the trigger type stored in this
event.
trigger_type
must match the current trigger type unless that is unknown. events
must not be null. void AddToComposite | ( | CompositeEventCollection< T > * | events | ) | const |
Provides an alternate signature for adding an Event that already has the correct trigger type set.
Must not have an unknown trigger type.
std::unique_ptr<Event> Clone | ( | ) | const |
Clones this instance.
|
protectedpure virtual |
Derived classes must implement this to add a clone of this Event to the event collection and unconditionally set its trigger type.
|
protectedpure virtual |
const EventDataType* get_event_data | ( | ) | const |
Returns a const pointer to the event data.
The returned value can be nullptr, which means this event does not have any associated data of the given EventDataType
.
EventDataType | the expected data type for an event that has this trigger type (PeriodicEventData or WitnessTriggeredEventData). |
EventDataType* get_mutable_event_data | ( | ) |
Returns a mutable pointer to the event data.
The returned value can be nullptr, which means this event does not have any associated data of the given EventDataType
.
EventDataType | the expected data type for an event that has this trigger type (PeriodicEventData or WitnessTriggeredEventData). |
TriggerType get_trigger_type | ( | ) | const |
Returns the trigger type.
bool has_event_data | ( | ) | const |
Returns true if this event has associated data of the given EventDataType
.
EventDataType | the expected data type for an event that has this trigger type (PeriodicEventData or WitnessTriggeredEventData). |
|
pure virtual |
Returns true
if this is a DiscreteUpdateEvent.
Implemented in UnrestrictedUpdateEvent< T >, DiscreteUpdateEvent< T >, and PublishEvent< T >.