Drake
MultibodyTreeContext< T > Class Template Reference

MultibodyTreeContext is an object that contains all the information needed to uniquely determine the state of a MultibodyTree. More...

#include <drake/multibody/multibody_tree/multibody_tree_context.h>

Public Member Functions

 MultibodyTreeContext (const MultibodyTreeTopology &topology)
 Instantiates a MultibodyTreeContext for a MultibodyTree with a given topology. More...
 
 MultibodyTreeContext (const MultibodyTreeTopology &topology, bool discrete_state)
 Instantiates a MultibodyTreeContext for a MultibodyTree with a given topology. More...
 
int num_positions () const
 Returns the size of the generalized positions vector. More...
 
int num_velocities () const
 Returns the size of the generalized velocities vector. More...
 
bool is_state_discrete () const
 Returns true if the state is discrete and false if the state is continuous. More...
 
Eigen::VectorBlock< const VectorX< T > > get_state_vector () const
 Returns a const reference to the state vector stored in this context as an Eigen::VectorBlock<const VectorX<T>>. More...
 
Eigen::VectorBlock< VectorX< T > > get_mutable_state_vector ()
 Returns a mutable reference to the state vector stored in this context as an Eigen::VectorBlock<VectorX<T>>. More...
 
Eigen::VectorBlock< const VectorX< T > > get_positions () const
 Returns an Eigen expression of the vector of generalized positions. More...
 
Eigen::VectorBlock< const VectorX< T > > get_velocities () const
 Returns an Eigen expression of the vector of generalized velocities. More...
 
Eigen::VectorBlock< VectorX< T > > get_mutable_positions ()
 Returns a mutable Eigen expression of the vector of generalized positions. More...
 
Eigen::VectorBlock< VectorX< T > > get_mutable_velocities ()
 Returns a mutable Eigen expression of the vector of generalized velocities. More...
 
template<int count>
Eigen::VectorBlock< const VectorX< T >, count > get_state_segment (int start) const
 Returns a const fixed-size Eigen::VectorBlock of count elements referencing a segment in the state vector with its first element at start. More...
 
template<int count>
Eigen::VectorBlock< VectorX< T >, count > get_mutable_state_segment (int start)
 Returns a mutable fixed-size Eigen::VectorBlock of count elements referencing a segment in the state vector with its first element at start. More...
 
Eigen::VectorBlock< const VectorX< T > > get_state_segment (int start, int count) const
 Returns a const fixed-size Eigen::VectorBlock of count elements referencing a segment in the state vector with its first element at start. More...
 
Eigen::VectorBlock< VectorX< T > > get_mutable_state_segment (int start, int count)
 Returns a mutable fixed-size Eigen::VectorBlock of count elements referencing a segment in the state vector with its first element at start. More...
 
Does not allow copy, move, or assignment
 MultibodyTreeContext (const MultibodyTreeContext &)=delete
 
MultibodyTreeContextoperator= (const MultibodyTreeContext &)=delete
 
 MultibodyTreeContext (MultibodyTreeContext &&)=delete
 
MultibodyTreeContextoperator= (MultibodyTreeContext &&)=delete
 
KinematicsCacheAccessors

Accessors to the kinematics caches stored in MultibodyTreeContext.

These will be deprecated once caching lands.

const PositionKinematicsCache< T > & get_position_kinematics_cache () const
 
const VelocityKinematicsCache< T > & get_velocity_kinematics_cache () const
 
PositionKinematicsCache< T > & get_mutable_position_kinematics_cache () const
 
VelocityKinematicsCache< T > & get_mutable_velocity_kinematics_cache () const
 
- Public Member Functions inherited from LeafContext< T >
 LeafContext ()
 
 ~LeafContext () override
 
 LeafContext (LeafContext &&)=delete
 
LeafContextoperator= (const LeafContext &)=delete
 
LeafContextoperator= (LeafContext &&)=delete
 
- Public Member Functions inherited from Context< T >
 Context (Context &&)=delete
 
Contextoperator= (const Context &)=delete
 
Contextoperator= (Context &&)=delete
 
const Tget_time () const
 Returns the current time in seconds. More...
 
const State< T > & get_state () const
 Returns a const reference to the whole State. More...
 
bool is_stateless () const
 Returns true if the Context has no state. More...
 
bool has_only_continuous_state () const
 Returns true if the Context has continuous state, but no discrete or abstract state. More...
 
bool has_only_discrete_state () const
 Returns true if the Context has discrete state, but no continuous or abstract state. More...
 
int get_num_total_states () const
 Returns the total dimension of all of the basic vector states (as if they were muxed). More...
 
const ContinuousState< T > & get_continuous_state () const
 Returns a const reference to the continuous component of the state, which may be of size zero. More...
 
const VectorBase< T > & get_continuous_state_vector () const
 Returns a reference to the continuous state vector, devoid of second-order structure. More...
 
int get_num_discrete_state_groups () const
 Returns the number of vectors (groups) in the discrete state. More...
 
const DiscreteValues< T > & get_discrete_state () const
 Returns a reference to the entire discrete state, which may consist of multiple discrete state vectors (groups). More...
 
const BasicVector< T > & get_discrete_state_vector () const
 Returns a reference to the only discrete state vector. More...
 
const BasicVector< T > & get_discrete_state (int index) const
 Returns a const reference to group (vector) index of the discrete state. More...
 
int get_num_abstract_states () const
 Returns the number of elements in the abstract state. More...
 
const AbstractValuesget_abstract_state () const
 Returns a const reference to the abstract component of the state, which may be of size zero. More...
 
template<typename U >
const U & get_abstract_state (int index) const
 Returns a const reference to the abstract component of the state at index. More...
 
const optional< double > & get_accuracy () const
 Returns the accuracy setting (if any). More...
 
const Parameters< T > & get_parameters () const
 Returns a const reference to this Context's parameters. More...
 
int num_numeric_parameters () const
 Returns the number of vector-valued parameters. More...
 
const BasicVector< T > & get_numeric_parameter (int index) const
 Returns a const reference to the vector-valued parameter at index. More...
 
int num_abstract_parameters () const
 Returns the number of abstract-valued parameters. More...
 
const AbstractValueget_abstract_parameter (int index) const
 Returns a const reference to the abstract-valued parameter at index. More...
 
void set_time (const T &time_sec)
 Sets the current time in seconds. More...
 
State< T > & get_mutable_state ()
 Returns a mutable reference to the whole State, potentially invalidating all state-dependent computations so requiring out of date notifications to be made for all such computations. More...
 
ContinuousState< T > & get_mutable_continuous_state ()
 Returns a mutable reference to the continuous component of the state, which may be of size zero. More...
 
VectorBase< T > & get_mutable_continuous_state_vector ()
 Returns a mutable reference to the continuous state vector, devoid of second-order structure. More...
 
void SetContinuousState (const Eigen::Ref< const VectorX< T >> &xc)
 Sets the continuous state to xc, including q, v, and z partitions. More...
 
void SetTimeAndContinuousState (const T &time_sec, const Eigen::Ref< const VectorX< T >> &xc)
 Sets time to time_sec and continuous state to xc. More...
 
DiscreteValues< T > & get_mutable_discrete_state ()
 Returns a mutable reference to the discrete component of the state, which may be of size zero. More...
 
BasicVector< T > & get_mutable_discrete_state_vector ()
 Returns a mutable reference to the only discrete state vector. More...
 
BasicVector< T > & get_mutable_discrete_state (int index)
 Returns a mutable reference to group (vector) index of the discrete state. More...
 
AbstractValuesget_mutable_abstract_state ()
 Returns a mutable reference to the abstract component of the state, which may be of size zero. More...
 
template<typename U >
U & get_mutable_abstract_state (int index)
 Returns a mutable reference to element index of the abstract state. More...
 
Parameters< T > & get_mutable_parameters ()
 Returns a mutable reference to this Context's parameters. More...
 
BasicVector< T > & get_mutable_numeric_parameter (int index)
 Returns a mutable reference to element index of the vector-valued (numeric) parameters. More...
 
AbstractValueget_mutable_abstract_parameter (int index)
 Returns a mutable reference to element index of the abstract-valued parameters. More...
 
void SetTimeStateAndParametersFrom (const Context< double > &source)
 Sets this context's time, accuracy, state, and parameters from the double values in source, regardless of this context's scalar type. More...
 
FixedInputPortValueFixInputPort (int index, const BasicVector< T > &vec)
 Connects the input port at index to a FixedInputPortValue with the given vector vec. More...
 
FixedInputPortValueFixInputPort (int index, const Eigen::Ref< const VectorX< T >> &data)
 Same as above method but starts with an Eigen vector whose contents are used to initialize a BasicVector in the FixedInputPortValue. More...
 
FixedInputPortValueFixInputPort (int index, std::unique_ptr< BasicVector< T >> vec)
 Same as the above method that takes a const BasicVector<T>&, but here the vector is passed by unique_ptr instead of by const reference. More...
 
void set_accuracy (const optional< double > &accuracy)
 Records the user's requested accuracy. More...
 
std::unique_ptr< Context< T > > Clone () const
 Returns a deep copy of this Context. More...
 
std::unique_ptr< State< T > > CloneState () const
 Returns a deep copy of this Context's State. More...
 
- Public Member Functions inherited from ContextBase
std::unique_ptr< ContextBaseClone () const
 Creates an identical copy of the concrete context object. More...
 
 ~ContextBase () override
 
void DisableCaching () const
 (Debugging) Disables caching recursively for this context and all its subcontexts. More...
 
void EnableCaching () const
 (Debugging) Re-enables caching recursively for this context and all its subcontexts. More...
 
void SetAllCacheEntriesOutOfDate () const
 (Debugging) Marks all cache entries out of date, recursively for this context and all its subcontexts. More...
 
const std::string & GetSystemName () const final
 Returns the local name of the subsystem for which this is the Context. More...
 
std::string GetSystemPathname () const final
 Returns the full pathname of the subsystem for which this is the Context. More...
 
const Cacheget_cache () const
 Returns a const reference to this subcontext's cache. More...
 
Cacheget_mutable_cache () const
 (Advanced) Returns a mutable reference to this subcontext's cache. More...
 
const DependencyTrackerget_tracker (DependencyTicket ticket) const
 Returns a const reference to a DependencyTracker in this subcontext. More...
 
DependencyTrackerget_mutable_tracker (DependencyTicket ticket)
 Returns a mutable reference to a DependencyTracker in this subcontext. More...
 
const DependencyGraphget_dependency_graph () const
 Returns a const reference to the collection of value trackers within this subcontext. More...
 
DependencyGraphget_mutable_dependency_graph ()
 Returns a mutable reference to the dependency graph. More...
 
int get_num_input_ports () const
 Returns the number of input ports in this context. More...
 
int get_num_output_ports () const
 Returns the number of output ports represented in this context. More...
 
DependencyTicket input_port_ticket (InputPortIndex port_num)
 Returns the dependency ticket associated with a particular input port. More...
 
DependencyTicket output_port_ticket (OutputPortIndex port_num)
 Returns the dependency ticket associated with a particular output port. More...
 
FixedInputPortValueFixInputPort (int index, std::unique_ptr< AbstractValue > value)
 Connects the input port at index to a FixedInputPortValue with the given abstract value. More...
 
FixedInputPortValueFixInputPort (int index, const AbstractValue &value)
 Same as above method but the value is passed by const reference instead of by unique_ptr. More...
 
const FixedInputPortValueMaybeGetFixedInputPortValue (int index) const
 For input port index, returns a const FixedInputPortValue if the port is fixed, otherwise nullptr. More...
 
FixedInputPortValueMaybeGetMutableFixedInputPortValue (int index)
 For input port index, returns a mutable FixedInputPortValue if the port is fixed, otherwise nullptr. More...
 
int64_t start_new_change_event ()
 (Internal use only) Returns the next change event serial number that is unique for this entire Context tree, not just this subcontext. More...
 
 ContextBase (ContextBase &&)=delete
 
ContextBaseoperator= (const ContextBase &)=delete
 
ContextBaseoperator= (ContextBase &&)=delete
 

Additional Inherited Members

- Protected Member Functions inherited from LeafContext< T >
 LeafContext (const LeafContext &source)
 Protected copy constructor takes care of the local data members and all base class members, but doesn't update base class pointers so is not a complete copy. More...
 
std::unique_ptr< ContextBaseDoCloneWithoutPointers () const override
 Derived classes should reimplement and replace this; don't recursively invoke it. More...
 
std::unique_ptr< State< T > > DoCloneState () const override
 Returns the appropriate concrete State object to be returned by CloneState(). More...
 
- Protected Member Functions inherited from Context< T >
 Context ()=default
 
 Context (const Context< T > &)=default
 Copy constructor takes care of base class and Context<T> data members. More...
 
virtual void DoPropagateTimeChange (const T &time_sec, int64_t change_event)
 Invokes PropagateTimeChange() on all subcontexts of this Context. More...
 
virtual void DoPropagateAccuracyChange (const optional< double > &accuracy, int64_t change_event)
 Invokes PropagateAccuracyChange() on all subcontexts of this Context. More...
 
const StepInfo< T > & get_step_info () const
 Returns a const reference to current time and step information. More...
 
void init_continuous_state (std::unique_ptr< ContinuousState< T >> xc)
 (Internal use only) Sets the continuous state to xc, deleting whatever was there before. More...
 
void init_discrete_state (std::unique_ptr< DiscreteValues< T >> xd)
 (Internal use only) Sets the discrete state to xd, deleting whatever was there before. More...
 
void init_abstract_state (std::unique_ptr< AbstractValues > xa)
 (Internal use only) Sets the abstract state to xa, deleting whatever was there before. More...
 
void init_parameters (std::unique_ptr< Parameters< T >> params)
 (Internal use only) Sets the parameters to params, deleting whatever was there before. More...
 
- Protected Member Functions inherited from ContextBase
 ContextBase ()
 Default constructor creates an empty ContextBase but initializes all the built-in dependency trackers that are the same in every System (like time, q, all states, all inputs, etc.). More...
 
 ContextBase (const ContextBase &)=default
 Copy constructor takes care of base class data members, but does not fix up base class pointers. More...
 
bool is_root_context () const
 Returns true if this context has no parent. More...
 
bool owns_any_variables_or_parameters () const
 (Internal use only) Returns true if this context provides resources for its own individual state variables or parameters. More...
 
void PropagateBulkChange (int64_t change_event, void(ContextBase::*note_bulk_change)(int64_t change_event))
 (Internal use only) This is a convenience method for invoking the eponymous static method on this context (which occurs frequently). More...
 
virtual void DoPropagateBuildTrackerPointerMap (const ContextBase &clone, DependencyTracker::PointerMap *tracker_map) const
 DiagramContext must implement this to invoke BuildTrackerPointerMap() on each of its subcontexts. More...
 
virtual void DoPropagateFixContextPointers (const ContextBase &source, const DependencyTracker::PointerMap &tracker_map)
 DiagramContext must implement this to invoke FixContextPointers() on each of its subcontexts. More...
 
virtual void DoPropagateCachingChange (void(Cache::*caching_change)()) const
 DiagramContext must implement this to invoke a caching behavior change on each of its subcontexts. More...
 
virtual void DoPropagateBulkChange (int64_t change_event, void(ContextBase::*note_bulk_change)(int64_t change_event))
 DiagramContext must implement this to invoke PropagateBulkChange() on its subcontexts, passing along the indicated method that specifies the particular bulk change (e.g. More...
 
void AddInputPort (InputPortIndex expected_index, DependencyTicket ticket)
 Adds the next input port. More...
 
void AddOutputPort (OutputPortIndex expected_index, DependencyTicket ticket, const internal::OutputPortPrerequisite &prerequisite)
 Adds the next output port. More...
 
void AddDiscreteStateTicket (DependencyTicket ticket)
 Adds a ticket to the list of discrete state tickets. More...
 
void AddAbstractStateTicket (DependencyTicket ticket)
 Adds a ticket to the list of abstract state tickets. More...
 
void AddNumericParameterTicket (DependencyTicket ticket)
 Adds a ticket to the list of numeric parameter tickets. More...
 
void AddAbstractParameterTicket (DependencyTicket ticket)
 Adds a ticket to the list of abstract parameter tickets. More...
 
void NoteTimeChanged (int64_t change_event)
 Notifies the local time tracker that time may have changed. More...
 
void NoteAccuracyChanged (int64_t change_event)
 Notifies the local accuracy tracker that the accuracy setting may have changed. More...
 
void NoteAllStateChanged (int64_t change_event)
 Notifies the local continuous, discrete, and abstract state trackers that each of them may have changed, likely because someone has asked to modify the whole state x. More...
 
void NoteAllContinuousStateChanged (int64_t change_event)
 Notifies the local q, v, and z trackers that each of them may have changed, likely because someone has asked to modify continuous state xc. More...
 
void NoteAllQChanged (int64_t change_event)
 Notifies the local q tracker that the q's may have changed. More...
 
void NoteAllVChanged (int64_t change_event)
 Notifies the local v tracker that the v's may have changed. More...
 
void NoteAllZChanged (int64_t change_event)
 Notifies the local z tracker that the z's may have changed. More...
 
void NoteAllDiscreteStateChanged (int64_t change_event)
 Notifies each local discrete state group tracker that the value of the discrete state group it manages may have changed. More...
 
void NoteAllAbstractStateChanged (int64_t change_event)
 Notifies each local abstract state variable tracker that the value of the abstract state variable it manages may have changed. More...
 
void NoteAllParametersChanged (int64_t change_event)
 Notifies the local numeric and abstract parameter trackers that each of them may have changed, likely because someone asked to modify all the parameters. More...
 
void NoteAllNumericParametersChanged (int64_t change_event)
 Notifies each local numeric parameter tracker that the value of the parameter it manages may have changed. More...
 
void NoteAllAbstractParametersChanged (int64_t change_event)
 Notifies each local abstract parameter tracker that the value of the parameter it manages may have changed. More...
 
- Static Protected Member Functions inherited from Context< T >
static void PropagateTimeChange (Context< T > *context, const T &time_sec, int64_t change_event)
 (Internal use only) Sets a new time and notifies time-dependent quantities that they are now invalid, as part of a given change event. More...
 
static void PropagateAccuracyChange (Context< T > *context, const optional< double > &accuracy, int64_t change_event)
 (Internal use only) Sets a new accuracy and notifies accuracy-dependent quantities that they are now invalid, as part of a given change event. More...
 
static Parameters< T > & access_mutable_parameters (Context< T > *context)
 (Internal use only) Returns a reference to mutable parameters without invalidation notifications. More...
 
static State< T > & access_mutable_state (Context< T > *context)
 (Internal use only) Returns a reference to a mutable state without invalidation notifications. More...
 
static std::unique_ptr< Context< T > > CloneWithoutPointers (const Context< T > &source)
 (Internal use only) Clones a context but without any of its internal pointers. More...
 
- Static Protected Member Functions inherited from ContextBase
static std::unique_ptr< ContextBaseCloneWithoutPointers (const ContextBase &source)
 (Internal use only) Clones a context but without copying any of its internal pointers; the clone's pointers are set to null. More...
 
static void BuildTrackerPointerMap (const ContextBase &source, const ContextBase &clone, DependencyTracker::PointerMap *tracker_map)
 (Internal use only) Given a new context clone containing an identically-structured dependency graph as the one in source, creates a mapping of all tracker memory addresses from source to clone. More...
 
static void FixContextPointers (const ContextBase &source, const DependencyTracker::PointerMap &tracker_map, ContextBase *clone)
 (Internal use only) Assuming clone is a recently-cloned Context that has yet to have its internal pointers updated, sets those pointers now. More...
 
static void PropagateCachingChange (const ContextBase &context, void(Cache::*caching_change)())
 (Internal use only) Applies the given caching-change notification method to context, and propagates the notification to subcontexts if context is a DiagramContext. More...
 
static void PropagateBulkChange (ContextBase *context, int64_t change_event, void(ContextBase::*note_bulk_change)(int64_t change_event))
 (Internal use only) Applies the given bulk-change notification method to the given context, and propagates the notification to subcontexts if this is a DiagramContext. More...
 
static void set_parent (ContextBase *child, ContextBase *parent)
 Declares that parent is the context of the enclosing Diagram. More...
 

Detailed Description

template<typename T>
class drake::multibody::MultibodyTreeContext< T >

MultibodyTreeContext is an object that contains all the information needed to uniquely determine the state of a MultibodyTree.

MultibodyTreeContext provides a collection of convenient access methods to retrieve generalized positions, velocities, cache entries, etc. Users should not need to make calls to these methods directly but rather access portions of a MultibodyTree state through the API provided by the different MultibodyTree elements such as Body, Frame, etc.

Template Parameters
TThe mathematical type of the context, which must be a valid Eigen scalar.

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

  • double
  • AutoDiffXd

They are already available to link against in the containing library.

Constructor & Destructor Documentation

MultibodyTreeContext ( const MultibodyTreeContext< T > &  )
delete
MultibodyTreeContext ( const MultibodyTreeTopology topology)
inlineexplicit

Instantiates a MultibodyTreeContext for a MultibodyTree with a given topology.

The stored state is continuous.

MultibodyTreeContext ( const MultibodyTreeTopology topology,
bool  discrete_state 
)
inline

Instantiates a MultibodyTreeContext for a MultibodyTree with a given topology.

Parameters
[in]discrete_statetrue if the state is to be stored as discrete state. Otherwise the state is stored as continuous state. false if the state is to be stored as continuous state.

Member Function Documentation

PositionKinematicsCache<T>& get_mutable_position_kinematics_cache ( ) const
inline
Eigen::VectorBlock<VectorX<T> > get_mutable_positions ( )
inline

Returns a mutable Eigen expression of the vector of generalized positions.

Eigen::VectorBlock<VectorX<T>, count> get_mutable_state_segment ( int  start)
inline

Returns a mutable fixed-size Eigen::VectorBlock of count elements referencing a segment in the state vector with its first element at start.

Eigen::VectorBlock<VectorX<T> > get_mutable_state_segment ( int  start,
int  count 
)
inline

Returns a mutable fixed-size Eigen::VectorBlock of count elements referencing a segment in the state vector with its first element at start.

Eigen::VectorBlock<VectorX<T> > get_mutable_state_vector ( )
inline

Returns a mutable reference to the state vector stored in this context as an Eigen::VectorBlock<VectorX<T>>.

Eigen::VectorBlock<VectorX<T> > get_mutable_velocities ( )
inline

Returns a mutable Eigen expression of the vector of generalized velocities.

VelocityKinematicsCache<T>& get_mutable_velocity_kinematics_cache ( ) const
inline
const PositionKinematicsCache<T>& get_position_kinematics_cache ( ) const
inline
Eigen::VectorBlock<const VectorX<T> > get_positions ( ) const
inline

Returns an Eigen expression of the vector of generalized positions.

Eigen::VectorBlock<const VectorX<T>, count> get_state_segment ( int  start) const
inline

Returns a const fixed-size Eigen::VectorBlock of count elements referencing a segment in the state vector with its first element at start.

Eigen::VectorBlock<const VectorX<T> > get_state_segment ( int  start,
int  count 
) const
inline

Returns a const fixed-size Eigen::VectorBlock of count elements referencing a segment in the state vector with its first element at start.

Eigen::VectorBlock<const VectorX<T> > get_state_vector ( ) const
inline

Returns a const reference to the state vector stored in this context as an Eigen::VectorBlock<const VectorX<T>>.

Eigen::VectorBlock<const VectorX<T> > get_velocities ( ) const
inline

Returns an Eigen expression of the vector of generalized velocities.

const VelocityKinematicsCache<T>& get_velocity_kinematics_cache ( ) const
inline
bool is_state_discrete ( ) const
inline

Returns true if the state is discrete and false if the state is continuous.

int num_positions ( ) const
inline

Returns the size of the generalized positions vector.

int num_velocities ( ) const
inline

Returns the size of the generalized velocities vector.

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

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