Drake
Drake C++ Documentation
ContinuousState< T > Class Template Reference

Detailed Description

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

ContinuousState is a view of, and optionally a container for, all the continuous state variables xc of a Drake System.

Continuous state variables are those whose values are defined by differential equations, so we expect there to be a well-defined time derivative xcdotd/dt xc.

The contents of xc are conceptually partitioned into three groups:

  • q is generalized position
  • v is generalized velocity
  • z is other continuous state

For a Drake LeafSystem these partitions are stored contiguously in memory in this sequence: xc=[q v z]. But because a Drake System may be a Diagram composed from subsystems, each with its own continuous state variables ("substates"), the composite continuous state will not generally be stored in contiguous memory. In that case the most we can say is that xc={q,v,z}, that is, it consists of all the q's, v's, and z's, in some order.

Nevertheless, this ContinuousState class provides a vector view of the data that groups together all the q partitions, v partitions, and z partitions. For example, if there are three subsystems (possibly Diagrams) whose continuous state variables are respectively xc₁={q₁,v₁,z₁}, xc₂={q₂,v₂,z₂}, and xc₃={q₃,v₃,z₃} the composite xc includes all the partitions in an undefined order. However, composite q, v, and z appear ordered as q=[q₁ q₂ q₃], v=[v₁ v₂ v₃], z=[z₁ z₂ z₃]. Note that the element ordering of the composite xc is not a concatenation of the composite subgroups. Do not index elements of the full state xc unless you know it is the continuous state of a LeafSystem (a LeafSystem looking at its own Context can depend on that).

Any of the groups may be empty. However, groups q and v must be either both present or both empty, because the time derivative qdot of the second-order state variables q must be computable using a linear mapping qdot=N(q)*v.

The time derivative xcdot has the identical substructure to xc, with the partitions interpreted as qdot, vdot, and zdot. We use identical ContinuousState objects for both.

Memory ownership

When a ContinuousState represents the state of a LeafSystem, it always owns the memory that is used for the state variables and is responsible for destruction. For a Diagram, ContinuousState can instead be a view of the underlying LeafSystem substates, so that modifying the Diagram's continuous state affects the LeafSystems appropriately. In that case, the memory is owned by the underlying LeafSystems. However, when a ContinuousState object of any structure is cloned, the resulting object always owns all its underlying memory, which is initialized with a copy of the original state variable values but is otherwise independent. The cloned object retains the structure and ordering of the elements and does not guarantee contiguous storage.

See also
DiagramContinuousState for more information.
Template Parameters
TThe scalar type, which must be one of the default scalars.

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

Public Member Functions

 ContinuousState (std::unique_ptr< VectorBase< T >> state)
 Constructs a ContinuousState for a system that does not have second-order structure. More...
 
 ContinuousState (std::unique_ptr< VectorBase< T >> state, int num_q, int num_v, int num_z)
 Constructs a ContinuousState that exposes second-order structure. More...
 
 ContinuousState ()
 Constructs a zero-length ContinuousState. More...
 
virtual ~ContinuousState ()
 
std::unique_ptr< ContinuousState< T > > Clone () const
 Creates a deep copy of this object with the same substructure but with all data owned by the copy. More...
 
int size () const
 Returns the size of the entire continuous state vector, which is necessarily num_q + num_v + num_z. More...
 
int num_q () const
 Returns the number of generalized positions q in this state vector. More...
 
int num_v () const
 Returns the number of generalized velocities v in this state vector. More...
 
int num_z () const
 Returns the number of miscellaneous continuous state variables z in this state vector. More...
 
T & operator[] (std::size_t idx)
 
const T & operator[] (std::size_t idx) const
 
const VectorBase< T > & get_vector () const
 Returns a reference to the entire continuous state vector. More...
 
VectorBase< T > & get_mutable_vector ()
 Returns a mutable reference to the entire continuous state vector. More...
 
const VectorBase< T > & get_generalized_position () const
 Returns a const reference to the subset of the state vector that is generalized position q. More...
 
VectorBase< T > & get_mutable_generalized_position ()
 Returns a mutable reference to the subset of the state vector that is generalized position q. More...
 
const VectorBase< T > & get_generalized_velocity () const
 Returns a const reference to the subset of the continuous state vector that is generalized velocity v. More...
 
VectorBase< T > & get_mutable_generalized_velocity ()
 Returns a mutable reference to the subset of the continuous state vector that is generalized velocity v. More...
 
const VectorBase< T > & get_misc_continuous_state () const
 Returns a const reference to the subset of the continuous state vector that is other continuous state z. More...
 
VectorBase< T > & get_mutable_misc_continuous_state ()
 Returns a mutable reference to the subset of the continuous state vector that is other continuous state z. More...
 
template<typename U >
void SetFrom (const ContinuousState< U > &other)
 Copies the values from other into this, converting the scalar type as necessary. More...
 
void SetFromVector (const Eigen::Ref< const VectorX< T >> &value)
 Sets the entire continuous state vector from an Eigen expression. More...
 
VectorX< T > CopyToVector () const
 Returns a copy of the entire continuous state vector into an Eigen vector. More...
 
Does not allow copy, move, or assignment
 ContinuousState (const ContinuousState &)=delete
 
ContinuousStateoperator= (const ContinuousState &)=delete
 
 ContinuousState (ContinuousState &&)=delete
 
ContinuousStateoperator= (ContinuousState &&)=delete
 
System compatibility
internal::SystemId get_system_id () const
 (Internal) Gets the id of the subsystem that created this state. More...
 
void set_system_id (internal::SystemId id)
 (Internal) Records the id of the subsystem that created this state. More...
 

Protected Member Functions

 ContinuousState (std::unique_ptr< VectorBase< T >> state, std::unique_ptr< VectorBase< T >> q, std::unique_ptr< VectorBase< T >> v, std::unique_ptr< VectorBase< T >> z)
 Constructs a continuous state that exposes second-order structure, with no particular constraints on the layout. More...
 
virtual std::unique_ptr< ContinuousStateDoClone () const
 DiagramContinuousState must override this to maintain the necessary internal substructure, and to perform a deep copy so that the result owns all its own data. More...
 

Constructor & Destructor Documentation

◆ ContinuousState() [1/6]

ContinuousState ( const ContinuousState< T > &  )
delete

◆ ContinuousState() [2/6]

ContinuousState ( ContinuousState< T > &&  )
delete

◆ ContinuousState() [3/6]

ContinuousState ( std::unique_ptr< VectorBase< T >>  state)
explicit

Constructs a ContinuousState for a system that does not have second-order structure.

The q and v partitions are empty; all of the state xc is miscellaneous continuous state z.

◆ ContinuousState() [4/6]

ContinuousState ( std::unique_ptr< VectorBase< T >>  state,
int  num_q,
int  num_v,
int  num_z 
)

Constructs a ContinuousState that exposes second-order structure.

Parameters
stateThe source xc of continuous state information.
num_qThe number of position variables q.
num_vThe number of velocity variables v.
num_zThe number of other continuous variables z.

We require that num_q ≥ num_v and that the sum of the partition sizes adds up to the size of state.

◆ ContinuousState() [5/6]

Constructs a zero-length ContinuousState.

◆ ~ContinuousState()

virtual ~ContinuousState ( )
virtual

◆ ContinuousState() [6/6]

ContinuousState ( std::unique_ptr< VectorBase< T >>  state,
std::unique_ptr< VectorBase< T >>  q,
std::unique_ptr< VectorBase< T >>  v,
std::unique_ptr< VectorBase< T >>  z 
)
protected

Constructs a continuous state that exposes second-order structure, with no particular constraints on the layout.

Precondition
The q, v, z are all views into the same storage as state.
Parameters
stateThe entire continuous state.
qThe subset of state that is generalized position.
vThe subset of state that is generalized velocity.
zThe subset of state that is neither position nor velocity.

Member Function Documentation

◆ Clone()

std::unique_ptr<ContinuousState<T> > Clone ( ) const

Creates a deep copy of this object with the same substructure but with all data owned by the copy.

That is, if the original was a Diagram continuous state that merely referenced substates, the clone will not include any references to the original substates and is thus decoupled from the Context containing the original. The concrete type of the BasicVector underlying each leaf ContinuousState is preserved. See the class comments above for more information.

◆ CopyToVector()

VectorX<T> CopyToVector ( ) const

Returns a copy of the entire continuous state vector into an Eigen vector.

◆ DoClone()

virtual std::unique_ptr<ContinuousState> DoClone ( ) const
protectedvirtual

DiagramContinuousState must override this to maintain the necessary internal substructure, and to perform a deep copy so that the result owns all its own data.

The default implementation here requires that the full state is a BasicVector (that is, this is a leaf continuous state). The BasicVector is cloned to preserve its concrete type and contents, then the q, v, z Subvectors are created referencing it. The implementation should not set_system_id on the result, the caller will set an id on the state after this method returns.

◆ get_generalized_position()

const VectorBase<T>& get_generalized_position ( ) const

Returns a const reference to the subset of the state vector that is generalized position q.

May be zero length.

◆ get_generalized_velocity()

const VectorBase<T>& get_generalized_velocity ( ) const

Returns a const reference to the subset of the continuous state vector that is generalized velocity v.

May be zero length.

◆ get_misc_continuous_state()

const VectorBase<T>& get_misc_continuous_state ( ) const

Returns a const reference to the subset of the continuous state vector that is other continuous state z.

May be zero length.

◆ get_mutable_generalized_position()

VectorBase<T>& get_mutable_generalized_position ( )

Returns a mutable reference to the subset of the state vector that is generalized position q.

May be zero length.

◆ get_mutable_generalized_velocity()

VectorBase<T>& get_mutable_generalized_velocity ( )

Returns a mutable reference to the subset of the continuous state vector that is generalized velocity v.

May be zero length.

◆ get_mutable_misc_continuous_state()

VectorBase<T>& get_mutable_misc_continuous_state ( )

Returns a mutable reference to the subset of the continuous state vector that is other continuous state z.

May be zero length.

◆ get_mutable_vector()

VectorBase<T>& get_mutable_vector ( )

Returns a mutable reference to the entire continuous state vector.

◆ get_system_id()

internal::SystemId get_system_id ( ) const

(Internal) Gets the id of the subsystem that created this state.

◆ get_vector()

const VectorBase<T>& get_vector ( ) const

Returns a reference to the entire continuous state vector.

◆ num_q()

int num_q ( ) const

Returns the number of generalized positions q in this state vector.

◆ num_v()

int num_v ( ) const

Returns the number of generalized velocities v in this state vector.

◆ num_z()

int num_z ( ) const

Returns the number of miscellaneous continuous state variables z in this state vector.

◆ operator=() [1/2]

ContinuousState& operator= ( ContinuousState< T > &&  )
delete

◆ operator=() [2/2]

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

◆ operator[]() [1/2]

T& operator[] ( std::size_t  idx)

◆ operator[]() [2/2]

const T& operator[] ( std::size_t  idx) const

◆ set_system_id()

void set_system_id ( internal::SystemId  id)

(Internal) Records the id of the subsystem that created this state.

◆ SetFrom()

void SetFrom ( const ContinuousState< U > &  other)

Copies the values from other into this, converting the scalar type as necessary.

◆ SetFromVector()

void SetFromVector ( const Eigen::Ref< const VectorX< T >> &  value)

Sets the entire continuous state vector from an Eigen expression.

◆ size()

int size ( ) const

Returns the size of the entire continuous state vector, which is necessarily num_q + num_v + num_z.


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