Drake
OutputPort< T > Class Template Referenceabstract

An OutputPort belongs to a System and represents the properties of one of that System's output ports. More...

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

Inheritance diagram for OutputPort< T >:
[legend]
Collaboration diagram for OutputPort< T >:
[legend]

## Public Member Functions

~OutputPort () override=default

template<typename ValueType >
const ValueType & Eval (const Context< T > &context) const
Returns a reference to the up-to-date value of this output port contained in the given Context. More...

std::unique_ptr< AbstractValueAllocate () const
Allocates a concrete object suitable for holding the value to be exposed by this output port, and returns that as an AbstractValue. More...

void Calc (const Context< T > &context, AbstractValue *value) const
Unconditionally computes the value of this output port with respect to the given context, into an already-allocated AbstractValue object whose concrete type must be exactly the same as the type returned by this port's allocator. More...

const AbstractValueEvalAbstract (const Context< T > &context) const
Returns a reference to the value of this output port contained in the given Context. More...

const System< T > & get_system () const
Returns a reference to the System that owns this output port. More...

Does not allow copy, move, or assignment
OutputPort (const OutputPort &)=delete

OutputPortoperator= (const OutputPort &)=delete

OutputPort (OutputPort &&)=delete

OutputPortoperator= (OutputPort &&)=delete

Public Member Functions inherited from OutputPortBase
virtual ~OutputPortBase ()

OutputPortIndex get_index () const
Returns the index of this output port within the owning System. More...

DependencyTicket ticket () const
Returns the DependencyTicket for this output port within the owning System. More...

PortDataType get_data_type () const
Gets the port data type specified at port construction. More...

int size () const
Returns the fixed size expected for a vector-valued output port. More...

const SystemBaseget_system_base () const
Returns a reference to the System that owns this output port. More...

OutputPortBase (const OutputPortBase &)=delete

OutputPortBaseoperator= (const OutputPortBase &)=delete

OutputPortBase (OutputPortBase &&)=delete

OutputPortBaseoperator= (OutputPortBase &&)=delete

## Protected Member Functions

OutputPort (const System< T > *system, SystemBase *system_base, OutputPortIndex index, DependencyTicket ticket, PortDataType data_type, int size)
Provides derived classes the ability to set the base class members at construction. More...

virtual std::unique_ptr< AbstractValueDoAllocate () const =0
A concrete OutputPort must provide a way to allocate a suitable object for holding the runtime value of this output port. More...

virtual void DoCalc (const Context< T > &context, AbstractValue *value) const =0
A concrete OutputPort must implement this method to calculate the value this output port should have, given the supplied Context. More...

virtual const AbstractValueDoEval (const Context< T > &context) const =0
A concrete OutputPort must provide access to the current value of this output port stored within the given Context. More...

std::string GetPortIdString () const
This is useful for error messages and produces a human-readable identification of an offending output port. More...

Protected Member Functions inherited from OutputPortBase
OutputPortBase (SystemBase *owning_system, OutputPortIndex index, DependencyTicket ticket, PortDataType data_type, int size)
Provides derived classes the ability to set the base class members at construction. More...

SystemBaseget_mutable_system_base ()

virtual internal::OutputPortPrerequisite DoGetPrerequisite () const =0
Concrete output ports must implement this to return the prerequisite dependency ticket for this port, which may be in the current System or one of its immediate child subsystems. More...

## Detailed Description

### template<typename T> class drake::systems::OutputPort< T >

An OutputPort belongs to a System and represents the properties of one of that System's output ports.

OutputPort objects are assigned OutputPortIndex values in the order they are declared; these are unique within a single System.

An output port can be considered a "window" into a System that permits controlled exposure of one of the values contained in that System's Context at run time. Input ports of other subsystems may be connected to an output port to construct system diagrams with carefully managed interdependencies.

The exposed value may be the result of an output computation, or it may simply expose some other value contained in the Context, such as the values of state variables. The Context handles caching of output port values and tracks dependencies to ensure that the values are valid with respect to their prerequisites. Leaf systems provide for the production of output port values, by computation or forwarding from other values within the associated leaf context. A diagram's output ports, on the other hand, are exported from output ports of its contained subsystems.

An output port's value is always stored as an AbstractValue, but we also provide special handling for output ports known to have numeric (vector) values. Vector-valued ports may specify a particular vector length, or may leave that to be determined at runtime.

OutputPort objects support three important operations:

• Allocate() returns an object that can hold the port's value.
• Calc() unconditionally computes the port's value.
• Eval() updates a cached value if necessary.
Template Parameters
 T The vector element type, which must be a valid Eigen scalar.

Instantiated templates for the following kinds of T's are provided:

They are already available to link against in the containing library. No other values for T are currently supported.

## Constructor & Destructor Documentation

 OutputPort ( const OutputPort< T > & )
delete
 OutputPort ( OutputPort< T > && )
delete
 ~OutputPort ( )
overridedefault
 OutputPort ( const System< T > * system, SystemBase * system_base, OutputPortIndex index, DependencyTicket ticket, PortDataType data_type, int size )
inlineprotected

Provides derived classes the ability to set the base class members at construction.

See OutputPortBase::OutputPortBase() for the meaning of these parameters.

Precondition
The system parameter must be the same object as the system_base parameter.

## Member Function Documentation

 std::unique_ptr Allocate ( ) const
inline

Allocates a concrete object suitable for holding the value to be exposed by this output port, and returns that as an AbstractValue.

The returned object will never be null. If Drake assertions are enabled (typically only in Debug builds), validates for a vector-valued port that the returned AbstractValue is actually a BasicVector-derived type and that it has an acceptable size.

Note
If this is a vector-valued port, the underlying type is Value<BasicVector<T>>; downcast to BasicVector<T> before downcasting to the specific BasicVector subclass.

Here is the caller graph for this function:

 void Calc ( const Context< T > & context, AbstractValue * value ) const
inline

Unconditionally computes the value of this output port with respect to the given context, into an already-allocated AbstractValue object whose concrete type must be exactly the same as the type returned by this port's allocator.

If Drake assertions are enabled (typically only in Debug builds), validates that the given value has exactly the same concrete type as is returned by the Allocate() method.

Here is the caller graph for this function:

 virtual std::unique_ptr DoAllocate ( ) const
protectedpure virtual

A concrete OutputPort must provide a way to allocate a suitable object for holding the runtime value of this output port.

The particulars may depend on values and types of objects in the given Context.

Returns
A unique_ptr to the new value-holding object as an AbstractValue.

Here is the caller graph for this function:

 virtual void DoCalc ( const Context< T > & context, AbstractValue * value ) const
protectedpure virtual

A concrete OutputPort must implement this method to calculate the value this output port should have, given the supplied Context.

The value may be determined by computation or by copying from a source value in the Context.

Parameters
 context A Context that has already been validated as compatible with the System whose output port this is. value A pointer that has already be validated as non-null and pointing to an object of the right type to hold a value of this output port.

Here is the caller graph for this function:

 virtual const AbstractValue& DoEval ( const Context< T > & context ) const
protectedpure virtual

A concrete OutputPort must provide access to the current value of this output port stored within the given Context.

If the value is already up to date with respect to its prerequisites in context, no computation should be performed. Otherwise, the implementation should arrange for the value to be computed, typically but not necessarily by invoking DoCalc().

Parameters
 context A Context that has already been validated as compatible with the System whose output port this is.

Here is the caller graph for this function:

 const ValueType& Eval ( const Context< T > & context ) const
inline

Returns a reference to the up-to-date value of this output port contained in the given Context.

This is the preferred way to obtain an output port's value since it will not be recalculated once up to date. If the value is not already up to date with respect to its prerequisites, this port's Calc() method is used first to update the value before the reference is returned. The Calc() method may be arbitrarily expensive, but Eval() is constant time and very fast if the value is already up to date.

Warning
Caching is currently disabled – Calc() will be invoked.
 const AbstractValue& EvalAbstract ( const Context< T > & context ) const
inline

Returns a reference to the value of this output port contained in the given Context.

If that value is not up to date with respect to its prerequisites, the Calc() method above is used first to update the value before the reference is returned.

Warning
Caching is currently disabled – Calc() will be invoked.

Here is the caller graph for this function:

 const System& get_system ( ) const
inline

Returns a reference to the System that owns this output port.

Note that for a diagram output port this will be the diagram, not the leaf system whose output port was forwarded.

Here is the caller graph for this function:

 std::string GetPortIdString ( ) const
inlineprotected

This is useful for error messages and produces a human-readable identification of an offending output port.

Here is the caller graph for this function:

 OutputPort& operator= ( const OutputPort< T > & )
delete
 OutputPort& operator= ( OutputPort< T > && )
delete

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