Drake
System3< T > Class Template Reference

A superclass template for systems that use a specified scalar type T for numerical values. More...

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

Inheritance diagram for System3< T >:
Collaboration diagram for System3< T >:

Public Member Functions

Methods common to all Systems

Every System can create a compatible Context, and can provide values for its output ports.

std::unique_ptr< Context3< T > > CreateDefaultContext () const
 Get a default Context<T> compatible with this System<T>. More...
 
const VectorInterface< T > & EvalVectorOutputPort (const Context3< T > &context, int port_num) const
 Convenience method for obtaining the up-to-date value for an output port which is known to be vector valued. More...
 
Methods for all *physical* Systems

Any System that models a physical system that can store energy or carry kinetic energy in moving masses should provide these methods so that conservation of energy can be monitored.

In a conservative system (one with no losses or actuation), the sum of potential and kinetic energy should be constant. That is unchanged whether the system is modeled as continuous or discrete.

For non-conservative systems additional information is required to track energy gained or lost, and that is handled differently for continuous and discrete models.

const T & EvalPotentialEnergy (const Context3< T > &context) const
 Returns the potential energy currently stored in the configuration provided in the given Context3. More...
 
const T & EvalKineticEnergy (const Context3< T > &context) const
 Return the kinetic energy currently present in the motion provided in the given Context3. More...
 
Methods for Systems with discrete state variables
void UpdateDiscreteVariables (Context3< T > &context, int sample_key) const
 TODO: update discrete variables. More...
 
std::pair< double, int > GetNextSampleTime (const Context3< T > &context) const
 Returns the next sample time required by any subsystem of this System. More...
 
- Public Member Functions inherited from AbstractSystem3
virtual ~AbstractSystem3 ()
 
std::string get_name () const
 Returns the name of this system. More...
 
DRAKESYSTEMFRAMEWORK_EXPORT std::unique_ptr< AbstractContext3CreateDefaultContext () 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 AbstractValueEvalOutputPort (const AbstractContext3 &context, int port_num) const
 Obtain an up-to-date value for one of this system's output ports. More...
 
const InputPortFinderget_input_port_finder (int port_num) const
 
const OutputPortFinderget_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...
 
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 InputPort3get_input_port (int port_num) const
 Returns a const reference to the InputPort3 with the given port number. More...
 
InputPort3get_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 OutputPort3get_output_port (int port_num) const
 Returns a const reference to the OutputPort3 with the given port number. More...
 
OutputPort3get_mutable_output_port (int port_num)
 Returns a mutable pointer to the OutputPort3 with the given port number. More...
 
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 AbstractSystem3get_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...
 
AbstractSystem3get_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 AbstractSystem3get_parent_system () const
 Returns a const pointer to the parent system that owns this one, or nullptr if this is a root system. More...
 
AbstractSystem3get_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 AbstractContext3find_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...
 
AbstractContext3find_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 AbstractSystem3get_root_system () const
 Find the root system of the tree of which this subsystem is a member. More...
 
AbstractSystem3get_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

 System3 (const std::string &name)
 Creates a System3 with no ports. More...
 
const VectorInterface< T > & EvalVectorInputPort (const Context3< T > &context, int port_num) const
 Convenience method for obtaining the up-to-date value for an input port which is known to be vector valued. More...
 
virtual const T & DoEvalPotentialEnergy (const Context3< T > &context) const
 If your system is capable of storing energy, implement this method to return the potential energy currently stored in the configuration provided in the given Context3. More...
 
virtual const T & DoEvalKineticEnergy (const Context3< T > &context) const
 If your system models energy of motion, implement this method to return the kinetic energy currently present in the motion provided in the given Context3. More...
 
void DoMapVelocityToConfigurationDerivatives (const Context3< T > &context, const Eigen::Ref< const VectorX< T >> &generalized_velocity, Eigen::Ref< VectorX< T >> *configuration_derivatives) const
 If your system has configuration and velocity variables, and the mapping from velocity v to configuration derivatives q is not identity, then you must implement this method. More...
 
void DoMapAccelerationToConfigurationSecondDerivatives (const Context3< T > &context, const Eigen::Ref< const VectorX< T >> &generalized_acceleration, Eigen::Ref< VectorX< T >> *configuration_second_derivatives) const
 See above for when you have to implement this method. More...
 
virtual const T & DoEvalConservativePower (const Context3< T > &context) const
 Return the rate at which mechanical energy is being converted from potential energy to kinetic energy by this system in the given Context3. More...
 
virtual const T & DoEvalNonConservativePower (const Context3< T > &context) const
 Return the rate at which mechanical energy is being generated (positive) or dissipated (negative) other than by conversion between potential and kinetic energy (in the given Context3). More...
 
- Protected Member Functions inherited from AbstractSystem3
 AbstractSystem3 (const std::string &name)
 
DRAKESYSTEMFRAMEWORK_EXPORT const AbstractValueEvalInputPort (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< AbstractContext3DoCreateEmptyContext () 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...
 

Methods for Systems with continuous state variables

enum  DerivativeBlock { kQdot = 0, kVdot = 1, kZdot = 2, kQdotDot = 3 }
 
Eigen::VectorBlock< const VectorX< T > > EvalTimeDerivatives (const Context3< T > &context, DerivativeBlock block) const
 Returns time derivatives of one or all of the continuous state variable groups. More...
 
const T & EvalConservativePower (const Context3< T > &context) const
 For continuous, physical systems only, returns the rate at which energy is being converted from potential energy to kinetic energy by this system in the given Context3. More...
 
const T & EvalNonConservativePower (const Context3< T > &context) const
 For continuous, physical systems only, returns the rate at which energy is being added to (positive) or dissipated from (negative) this sytem other than* by conversion between potential and kinetic energy (in the given Context3). More...
 
void MapVelocityToConfigurationDerivatives (const Context3< T > &context, const Eigen::Ref< const VectorX< T >> &generalized_velocity, Eigen::Ref< VectorX< T >> *configuration_derivatives) const
 Transforms a given generalized velocity v into qdot, the time derivative of the generalized configuration q. More...
 
void MapAccelerationToConfigurationSecondDerivatives (const Context3< T > &context, const Eigen::Ref< const VectorX< T >> &generalized_acceleration, Eigen::Ref< VectorX< T >> *configuration_second_derivatives) const
 Transforms a given generalized acceleration vdot into qdotdot, the second time derivative of the generalized configuration q. More...
 

Detailed Description

template<typename T>
class drake::systems::System3< T >

A superclass template for systems that use a specified scalar type T for numerical values.

These may be instantiated with different scalar types to use the same code to obtain different kinds of results, such as derivatives or structural analysis of dependencies.

At run time, a System<T> is asked to produce a compatible Context<T> object that can hold all values that can change during a simulation, cache computations that depend on those values, and manage dependencies to prevent access to stale computations.

Template Parameters
TThe vector element type, which must be a valid Eigen scalar.

Member Enumeration Documentation

Enumerator
kQdot 
kVdot 
kZdot 
kQdotDot 

Constructor & Destructor Documentation

System3 ( const std::string &  name)
inlineexplicitprotected

Creates a System3 with no ports.

Member Function Documentation

std::unique_ptr<Context3<T> > CreateDefaultContext ( ) const
inline

Get a default Context<T> compatible with this System<T>.

Here is the call graph for this function:

virtual const T& DoEvalConservativePower ( const Context3< T > &  context) const
inlineprotectedvirtual

Return the rate at which mechanical energy is being converted from potential energy to kinetic energy by this system in the given Context3.

This quantity will be positive when potential energy is decreasing. Note that kinetic energy will also be affected by non-conservative forces so we can't say which direction it is moving, only whether the conservative power is increasing or decreasing the kinetic energy. Power is in watts (J/s). This method is meaningful only for continuous, physical systems; don't implement otherwise. The default implementation returns zero.

virtual const T& DoEvalKineticEnergy ( const Context3< T > &  context) const
inlineprotectedvirtual

If your system models energy of motion, implement this method to return the kinetic energy currently present in the motion provided in the given Context3.

Otherwise the default implementation will return zero. When implementing this method, you may assume that error checking has been performed to validate the Context3.

virtual const T& DoEvalNonConservativePower ( const Context3< T > &  context) const
inlineprotectedvirtual

Return the rate at which mechanical energy is being generated (positive) or dissipated (negative) other than by conversion between potential and kinetic energy (in the given Context3).

Integrating this quantity yields work W, and the total energy E=PE+KE-W should be conserved by any physically-correct model, to within integration accuracy of W. Power is in watts (J/s). (Watts are abbreviated W but not to be confused with work!) This method is meaningful only for continuous, physical systems; don't implement otherwise. The default implementation returns zero.

virtual const T& DoEvalPotentialEnergy ( const Context3< T > &  context) const
inlineprotectedvirtual

If your system is capable of storing energy, implement this method to return the potential energy currently stored in the configuration provided in the given Context3.

Otherwise the default implementation will return zero. When implementing this method, you may assume that error checking has been performed to validate the Context3.

void DoMapAccelerationToConfigurationSecondDerivatives ( const Context3< T > &  context,
const Eigen::Ref< const VectorX< T >> &  generalized_acceleration,
Eigen::Ref< VectorX< T >> *  configuration_second_derivatives 
) const
protected

See above for when you have to implement this method.

void DoMapVelocityToConfigurationDerivatives ( const Context3< T > &  context,
const Eigen::Ref< const VectorX< T >> &  generalized_velocity,
Eigen::Ref< VectorX< T >> *  configuration_derivatives 
) const
protected

If your system has configuration and velocity variables, and the mapping from velocity v to configuration derivatives q is not identity, then you must implement this method.

Otherwise the default method will check that the size of v and q match, and will simply set qdot[i] = v[i]. Otherwise, the transformation must be linear in velocity (qdot = N(q) * v), and it must require no more than O(n) time to compute where n is the size of q.

Implementations may assume that configuration_derivatives is of the same size as the generalized position q present in the given Context, and that generalized_velocity is the same size as the generalized velocities v in that Context3, and should populate configuration_derivatives with elementwise-corresponding derivatives of configuration.

Parameters
contextThe complete evaluation context.
generalized_velocityThe velocity to transform.
configuration_derivativesThe output vector. Must not be nullptr.
const T& EvalConservativePower ( const Context3< T > &  context) const
inline

For continuous, physical systems only, returns the rate at which energy is being converted from potential energy to kinetic energy by this system in the given Context3.

This quantity will be positive when potential energy is decreasing. Note that kinetic energy will also be affected by non-conservative forces so we can't say which direction it is moving, only whether the conservative power is increasing or decreasing the kinetic energy. Power is in watts (J/s). Returns zero for systems where this doesn't make sense.

const T& EvalKineticEnergy ( const Context3< T > &  context) const
inline

Return the kinetic energy currently present in the motion provided in the given Context3.

Non-physical Systems will return 0.

const T& EvalNonConservativePower ( const Context3< T > &  context) const
inline

For continuous, physical systems only, returns the rate at which energy is being added to (positive) or dissipated from (negative) this sytem other than* by conversion between potential and kinetic energy (in the given Context3).

Integrating this quantity yields work W, and the total energy E=PE+KE-W should be conserved by any physically-correct model, to within integration accuracy of W. Power is in watts (J/s). (Watts are abbreviated W but not to be confused with work!) Returns zero for systems where this doesn't make sense.

const T& EvalPotentialEnergy ( const Context3< T > &  context) const
inline

Returns the potential energy currently stored in the configuration provided in the given Context3.

Non-physical Systems will return 0.

Eigen::VectorBlock<const VectorX<T> > EvalTimeDerivatives ( const Context3< T > &  context,
DerivativeBlock  block 
) const

Returns time derivatives of one or all of the continuous state variable groups.

We consider continuous state xc=[q v z] where q are the configuration variables (second order), v are the velocity variables, and z are arbitrary continuous variables. The time derivative is thus xcdot=[qdot vdot zdot]. The second time derivative qdotdot is also available. This method will initiate compuation of the requested derivative; typically the vdot calculation will be very expensive.

const VectorInterface<T>& EvalVectorInputPort ( const Context3< T > &  context,
int  port_num 
) const
inlineprotected

Convenience method for obtaining the up-to-date value for an input port which is known to be vector valued.

Note that this will initiate computation of the value if necessary.

Return values
vector_valueA reference into context containing the correct value for this vector-valued input port.

Here is the caller graph for this function:

const VectorInterface<T>& EvalVectorOutputPort ( const Context3< T > &  context,
int  port_num 
) const
inline

Convenience method for obtaining the up-to-date value for an output port which is known to be vector valued.

Return values
vector_valueA reference into context containing the correct value for this vector-valued output port.
std::pair<double,int> GetNextSampleTime ( const Context3< T > &  context) const

Returns the next sample time required by any subsystem of this System.

This is accompanied by a "sample key" which unambiguously identifies the subsystems, inputs, and outputs that need to be sampled. That key should be returned in a call to UpdateDiscreteVariables()

void MapAccelerationToConfigurationSecondDerivatives ( const Context3< T > &  context,
const Eigen::Ref< const VectorX< T >> &  generalized_acceleration,
Eigen::Ref< VectorX< T >> *  configuration_second_derivatives 
) const
inline

Transforms a given generalized acceleration vdot into qdotdot, the second time derivative of the generalized configuration q.

The current configuration q and velcoity v are taken from the given Context3. Note that generalized acceleration is given explicitly as an argument; any acceleration present in the Context3 is ignored.

The transformation is linear in acceleration and requires no more than O(n) time to compute where n is the size of q. We are computing

  qdotdot = N(q) * vdot + Ndot(q,v) * v

where N is a block diagonal matrix with small blocks, and is the same N as described in MapVelocityToConfigurationDerivatives().

Parameters
[in]contextThe complete evaluation Context3, from which we obtain q and v. Some cache updates may occur.
[in]generalized_accelerationThe input acceleration vdot to transform.
[out]configuration_second_derivativesThe output vector qdotdot. Must not be nullptr.
void MapVelocityToConfigurationDerivatives ( const Context3< T > &  context,
const Eigen::Ref< const VectorX< T >> &  generalized_velocity,
Eigen::Ref< VectorX< T >> *  configuration_derivatives 
) const
inline

Transforms a given generalized velocity v into qdot, the time derivative of the generalized configuration q.

The current configuration is taken from the given Context3. Note that the velocity is given explicitly as an argument; any velocity in the Context is ignored.

The transformation is linear in velocity and requires no more than O(n) time to compute where n is the size of q. We are computing

  qdot = N(q) * v

where N is a block diagonal matrix with small blocks.

Parameters
[in]contextThe complete evaluation Context3, from which we obtain q. Some cache updates may occur.
[in]generalized_velocityThe input velocity v to transform.
[out]configuration_derivativesThe output vector qdot. Must not be nullptr.
void UpdateDiscreteVariables ( Context3< T > &  context,
int  sample_key 
) const

TODO: update discrete variables.


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