Drake
|
An abstract superclass for dynamical systems, encapsulating functionality that is independent of the numerical scalar type in use. More...
#include <drake/systems/framework/system3.h>
Public Member Functions | |
virtual | ~AbstractSystem3 () |
std::string | get_name () const |
Returns the name of this system. More... | |
DRAKESYSTEMFRAMEWORK_EXPORT std::unique_ptr< AbstractContext3 > | CreateDefaultContext () const |
Returns a default context, initialized with run time mutable memory for the correct number and type of InputPort3, OutputPort3, and state variable objects, as well as time, parameters, and basic computations. More... | |
DRAKESYSTEMFRAMEWORK_EXPORT const AbstractValue & | EvalOutputPort (const AbstractContext3 &context, int port_num) const |
Obtain an up-to-date value for one of this system's output ports. More... | |
const InputPortFinder & | get_input_port_finder (int port_num) const |
const OutputPortFinder & | get_output_port_finder (int port_num) const |
CacheEntry::Calculator | get_output_port_calculator (int port_num) const |
Given an output port number, return a function that knows how to calculate the value of that port when given a system and context. More... | |
void | CalcOutputPort (const AbstractContext3 &context, int port_num, AbstractValue *result) const |
Unconditionally calculate what would be the output port value into an already-allocated appropriate result object. More... | |
Methods useful for any System | |
These provide the ability to specify input and output ports, which are common to all dynamic systems. | |
int | AddInputPort (std::unique_ptr< InputPort3 > port) |
Add an input port that is to be owned by this system. More... | |
int | AddOutputPort (std::unique_ptr< OutputPort3 > port) |
Add an output port that is to be owned by this System. More... | |
int | get_num_input_ports () const |
Returns the current number of input ports in this system. More... | |
const InputPort3 & | get_input_port (int port_num) const |
Returns a const reference to the InputPort3 with the given port number. More... | |
InputPort3 * | get_mutable_input_port (int port_num) |
Returns a mutable pointer to the InputPort3 with the given port number. More... | |
int | get_num_output_ports () const |
Returns the current number of output ports in this system. More... | |
const OutputPort3 & | get_output_port (int port_num) const |
Returns a const reference to the OutputPort3 with the given port number. More... | |
OutputPort3 * | get_mutable_output_port (int port_num) |
Returns a mutable pointer to the OutputPort3 with the given port number. More... | |
System diagram methods | |
These methods are useful for any system that contains subsystems. | |
template<class ConcreteSystem > | |
ConcreteSystem * | AddSubsystem (std::unique_ptr< ConcreteSystem > subsystem) |
Takes ownership of the given system and returns an unowned, raw pointer to the concrete type for convenient access. More... | |
int | InheritInputPort (AbstractSystem3 *child_subsystem, int input_port_num) |
The given subsystem's InputPort3 becomes the next InputPort3 of this system diagram. More... | |
int | InheritOutputPort (AbstractSystem3 *child_subsystem, int output_port_num) |
The given subsystem's OutputPort3 becomes the next OutputPort3 of this system diagram. More... | |
void | Connect (AbstractSystem3 *source_subsystem, int output_port_num, AbstractSystem3 *sink_subsystem, int input_port_num) |
Connect the given output port of subsystem 1 into the given input port of subsystem 2. More... | |
int | get_num_subsystems () const |
Returns the current number of subsystems contained in this system diagram. More... | |
const AbstractSystem3 & | get_subsystem (int index) const |
Returns a const reference to one of the contained subsystems, using the index reflecting the order in which it was added. More... | |
AbstractSystem3 * | get_mutable_subsystem (int index) |
Returns a mutable pointer to one of the contained subsystems, using the index reflecting the order in which it was added. More... | |
const AbstractSystem3 * | get_parent_system () const |
Returns a const pointer to the parent system that owns this one, or nullptr if this is a root system. More... | |
AbstractSystem3 * | get_mutable_parent_system () |
Returns a mutable pointer to the parent system that owns this one, or nullptr if this is a root system. More... | |
int | get_subsystem_num () const |
If this system is a subsystem of a parent system, return the subsystem number by which that parent knows us. More... | |
std::string | GetSubsystemPathName () const |
Determine the full path name of this subsystem in a form like /rootname/parentname/myname . More... | |
const AbstractContext3 & | find_my_subcontext (const AbstractContext3 &some_subcontext) const |
Get const access to this subsystem's subcontext given const access to any other subsystem's subcontext in the same context diagram. More... | |
AbstractContext3 * | find_my_mutable_subcontext (AbstractContext3 *some_subcontext) const |
Get mutable access to this subsystem's subcontext given mutable access to any other subsystem's subcontext in the same context diagram. More... | |
const AbstractSystem3 & | get_root_system () const |
Find the root system of the tree of which this subsystem is a member. More... | |
AbstractSystem3 * | get_mutable_root_system () |
Get a mutable pointer to the root system of the tree of which this subsystem is a member. More... | |
Protected Member Functions | |
AbstractSystem3 (const std::string &name) | |
DRAKESYSTEMFRAMEWORK_EXPORT const AbstractValue & | EvalInputPort (const AbstractContext3 &context, int port_num) const |
Obtain an up-to-date value for one of this system's input ports. More... | |
virtual std::unique_ptr< AbstractContext3 > | DoCreateEmptyContext () const =0 |
Allocate a concrete Context type that is appropropriate for your concrete System. More... | |
virtual void | DoAcquireContextResources (AbstractContext3 *context) const |
Acquire any private Context resources your concrete System needs, and assign them default values. More... | |
virtual void | DoCalcOutputPort (const AbstractContext3 &context, int port_num, AbstractValue *value) const =0 |
Unconditionally compute the given output port's value. More... | |
Friends | |
class | AbstractContext3 |
An abstract superclass for dynamical systems, encapsulating functionality that is independent of the numerical scalar type in use.
That includes the concepts of input and output, containment of subsystems, and connections among the subsystems' inputs and outputs. A system that contains subsystems is called a "system diagram", one without subsystems is called a "leaf system", and the topmost system diagram is the "root system".
This class is intended to be paired with a compatible AbstractContext3 object whose internal tree structure of subcontexts is identical to the structure of the tree of subsystems.
Input values are presented to a System3 through zero or more InputPort3 objects; output values are delivered through zero or more OutputPort3 objects. Systems are composed by connecting compatible OutputPort3 and InputPort3 objects together into a system diagram. These connections are established during extended construction of a system diagram and must be completed prior to run time execution (and are hence independent of context). InputPort3 objects contain information about their requirements for OutputPort3 mates.
Most systems should not inherit directly from AbstractSystem3. If your system involves any numerical computations it should instead, inherit from System3<T>
.
|
inlinevirtual |
|
inlineexplicitprotected |
|
inline |
Add an input port that is to be owned by this system.
The assigned port number is returned and can be used to retrieve this port later, and to locate its value in a compatible context.
|
inline |
Add an output port that is to be owned by this System.
The assigned port number is returned and can be used to retrieve this port later, and to locate its value in a compatible context.
|
inline |
Takes ownership of the given system and returns an unowned, raw pointer to the concrete type for convenient access.
This subsystem
is assigned the next available index, as given by get_num_subsystems()
prior to making this call.
|
inline |
Unconditionally calculate what would be the output port value into an already-allocated appropriate result object.
|
inline |
Connect the given output port of subsystem 1 into the given input port of subsystem 2.
Both subsystems must be immediate children of this system. The input port must be able to accept the type and sampling rate of the output port.
std::logic_error | The input port does not accept the type or sampling rate of the output port. |
std::unique_ptr< AbstractContext3 > CreateDefaultContext | ( | ) | const |
Returns a default context, initialized with run time mutable memory for the correct number and type of InputPort3, OutputPort3, and state variable objects, as well as time, parameters, and basic computations.
This will contain one subcontext corresponding to each subsystem of this System.
|
inlineprotectedvirtual |
Acquire any private Context resources your concrete System needs, and assign them default values.
The supplied context
is in the process of being constructed and you may assume it already contains resources for your input and output ports. The default implementation acquires no resources.
|
protectedpure virtual |
Unconditionally compute the given output port's value.
When implementing this method, you may assume that error checking has been performed to validate the Context and port number, and that the output value is of the same type as that port's model value.
|
protectedpure virtual |
Allocate a concrete Context type that is appropropriate for your concrete System.
|
protected |
Obtain an up-to-date value for one of this system's input ports.
If necessary this triggers the computation of whatever value source this input port is connected to, typically an output port.
[in,out] | context | A Context that is compatible with this System. |
[in] | port_num | The index number of the input port to be evaluated. |
value | A reference into context containing the current value for this output port. |
const AbstractValue & EvalOutputPort | ( | const AbstractContext3 & | context, |
int | port_num | ||
) | const |
Obtain an up-to-date value for one of this system's output ports.
(Output ports may have distinct sample times so must be individually evaluatable.) If necessary, computation of this value is initiated with the result written into the supplied AbstractContext3's cache.
[in,out] | context | A context that is compatible with this System. |
[in] | port_num | The index number of the output port to be evaluated. |
value | A reference into context containing the current value for this output port. |
|
inline |
Get mutable access to this subsystem's subcontext given mutable access to any other subsystem's subcontext in the same context diagram.
Note that you don't need mutable access to the subsystem to get mutable access to its subcontext.
|
inline |
Get const access to this subsystem's subcontext given const access to any other subsystem's subcontext in the same context diagram.
|
inline |
Returns a const reference to the InputPort3 with the given port number.
|
inline |
|
inline |
Returns a mutable pointer to the InputPort3 with the given port number.
|
inline |
Returns a mutable pointer to the OutputPort3 with the given port number.
|
inline |
Returns a mutable pointer to the parent system that owns this one, or nullptr
if this is a root system.
|
inline |
Get a mutable pointer to the root system of the tree of which this subsystem is a member.
Never returns nullptr
. See get_root_system()
for more information.
|
inline |
Returns a mutable pointer to one of the contained subsystems, using the index reflecting the order in which it was added.
|
inline |
Returns the name of this system.
This is just an arbitrary string with no particular meaning attached.
|
inline |
Returns the current number of input ports in this system.
This is also the port number that will be assigned by the next call to AddInputPort()
.
|
inline |
Returns the current number of output ports in this system.
This is also the port number that will be assigned by the next call to AddOutputPort()
.
|
inline |
Returns the current number of subsystems contained in this system diagram.
This is also the index that will be assigned to the next subsystem that is added here.
|
inline |
Returns a const reference to the OutputPort3 with the given port number.
|
inline |
Given an output port number, return a function that knows how to calculate the value of that port when given a system and context.
The signature is suitable for registering with a cache entry that can invoke this function when the entry is out of date and needs updating.
|
inline |
|
inline |
Returns a const pointer to the parent system that owns this one, or nullptr
if this is a root system.
|
inline |
Find the root system of the tree of which this subsystem is a member.
Searches up the tree so run time is roughly log(N) for an N-subsystem tree starting at a leaf.
|
inline |
Returns a const reference to one of the contained subsystems, using the index reflecting the order in which it was added.
|
inline |
If this system is a subsystem of a parent system, return the subsystem number by which that parent knows us.
Returns -1 if this is a root system.
|
inline |
Determine the full path name of this subsystem in a form like /rootname/parentname/myname
.
This name will be unique if sibling subsystems have unique names within their parent system.
|
inline |
The given subsystem's InputPort3 becomes the next InputPort3 of this system diagram.
The diagram's input port number is returned; it will in general be different from the input port number in the subsystem from which it was inherited.
|
inline |
The given subsystem's OutputPort3 becomes the next OutputPort3 of this system diagram.
The diagram's output port number is returned; it will in general be different from the output port number in the subsystem from which it was inherited.
|
friend |