Drake
SpringMassSystem< T > Class Template Reference

A model of a one-dimensional spring-mass system. More...

#include <systems/plants/spring_mass_system/spring_mass_system.h>

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

Public Member Functions

 SpringMassSystem (double spring_constant_N_per_m, double mass_kg, bool system_is_forced=false)
 Constructs a spring-mass system with a fixed spring constant and given mass. More...
 
template<typename U >
 SpringMassSystem (const SpringMassSystem< U > &)
 Scalar-converting copy constructor. See System Scalar Conversion. More...
 
const InputPortDescriptor< T > & get_force_port () const
 Returns the input port to the externally applied force. More...
 
const OutputPort< T > & get_output_port () const
 Returns the port to output state. More...
 
double get_spring_constant () const
 Returns the spring constant k that was provided at construction, in N/m. More...
 
double get_mass () const
 Returns the mass m that was provided at construction, in kg. More...
 
bool get_system_is_forced () const
 Returns true iff the system is forced. More...
 
get_position (const Context< T > &context) const
 Gets the current position of the mass in the given Context. More...
 
get_velocity (const Context< T > &context) const
 Gets the current velocity of the mass in the given Context. More...
 
get_input_force (const Context< T > &context) const
 
get_conservative_work (const Context< T > &context) const
 Gets the current value of the conservative power integral in the given Context. More...
 
void set_position (Context< T > *context, const T &position) const
 Sets the position of the mass in the given Context. More...
 
void set_velocity (Context< T > *context, const T &velocity) const
 Sets the velocity of the mass in the given Context. More...
 
void set_conservative_work (Context< T > *context, const T &energy) const
 Sets the initial value of the conservative power integral in the given Context. More...
 
EvalSpringForce (const Context< T > &context) const
 Returns the force being applied by the spring to the mass in the given Context. More...
 
DoCalcPotentialEnergy (const Context< T > &context) const override
 Returns the potential energy currently stored in the spring in the given Context. More...
 
DoCalcKineticEnergy (const Context< T > &context) const override
 Returns the current kinetic energy of the moving mass in the given Context. More...
 
DoCalcConservativePower (const Context< T > &context) const override
 Returns the rate at which mechanical energy is being converted from potential energy in the spring to kinetic energy of the mass by this spring-mass system in the given Context. More...
 
DoCalcNonConservativePower (const Context< T > &context) const override
 Returns power that doesn't involve the conservative spring element. More...
 
void DoCalcTimeDerivatives (const Context< T > &context, ContinuousState< T > *derivatives) const override
 Override this if you have any continuous state variables xc in your concrete System to calculate their time derivatives. More...
 
void GetClosedFormSolution (const T &x0, const T &v0, const T &tf, T *xf, T *vf) const
 Returns the closed-form position and velocity solution for this system from the given initial conditions. More...
 
Does not allow copy, move, or assignment
 SpringMassSystem (const SpringMassSystem &)=delete
 
SpringMassSystemoperator= (const SpringMassSystem &)=delete
 
 SpringMassSystem (SpringMassSystem &&)=delete
 
SpringMassSystemoperator= (SpringMassSystem &&)=delete
 
- Public Member Functions inherited from LeafSystem< T >
 ~LeafSystem () override
 
std::unique_ptr< CompositeEventCollection< T > > AllocateCompositeEventCollection () const final
 Allocates a CompositeEventCollection object for this system. More...
 
std::unique_ptr< LeafContext< T > > AllocateContext () const
 Shadows System<T>::AllocateContext to provide a more concrete return type LeafContext<T>. More...
 
std::unique_ptr< ContextBaseDoMakeContext () const final
 Derived class implementations should allocate a suitable default-constructed Context, with default-constructed subcontexts for diagrams. More...
 
void DoValidateAllocatedContext (const ContextBase &context_base) const final
 Any derived class that imposes restrictions on the structure or content of an acceptable Context should enforce those restrictions by overriding this method. More...
 
void SetDefaultState (const Context< T > &context, State< T > *state) const override
 Default implementation: sets all continuous state to the model vector given in DeclareContinuousState (or zero if no model vector was given) and discrete states to zero. More...
 
void SetDefaultParameters (const Context< T > &context, Parameters< T > *parameters) const override
 Default implementation: sets all numeric parameters to the model vector given to DeclareNumericParameter, or else if no model was provided sets the numeric parameter to one. More...
 
std::unique_ptr< SystemOutput< T > > AllocateOutput (const Context< T > &) const final
 Returns a container that can hold the values of all of this System's output ports. More...
 
std::unique_ptr< ContinuousState< T > > AllocateTimeDerivatives () const override
 Returns the AllocateContinuousState value, which must not be nullptr. More...
 
std::unique_ptr< DiscreteValues< T > > AllocateDiscreteVariables () const override
 Returns the AllocateDiscreteState value, which must not be nullptr. More...
 
std::multimap< int, intGetDirectFeedthroughs () const final
 Reports all direct feedthroughs from input ports to output ports. More...
 
 LeafSystem (const LeafSystem &)=delete
 
LeafSystemoperator= (const LeafSystem &)=delete
 
 LeafSystem (LeafSystem &&)=delete
 
LeafSystemoperator= (LeafSystem &&)=delete
 
- Public Member Functions inherited from System< T >
 ~System () override=default
 
void GetWitnessFunctions (const Context< T > &context, std::vector< const WitnessFunction< T > * > *w) const
 Gets the witness functions active for the given state. More...
 
CalcWitnessValue (const Context< T > &context, const WitnessFunction< T > &witness_func) const
 Evaluates a witness function at the given context. More...
 
std::string GetSystemIdString () const
 Returns a string suitable for identifying this particular System in error messages, when it is a subsystem of a larger Diagram. More...
 
 System (const System &)=delete
 
Systemoperator= (const System &)=delete
 
 System (System &&)=delete
 
Systemoperator= (System &&)=delete
 
std::unique_ptr< Context< T > > AllocateContext () const
 Returns a Context<T> suitable for use with this System<T>. More...
 
std::unique_ptr< BasicVector< T > > AllocateInputVector (const InputPortDescriptor< T > &descriptor) const
 Given a port descriptor, allocates the vector storage. More...
 
std::unique_ptr< AbstractValueAllocateInputAbstract (const InputPortDescriptor< T > &descriptor) const
 Given a port descriptor, allocates the abstract storage. More...
 
std::unique_ptr< Context< T > > CreateDefaultContext () const
 This convenience method allocates a context using AllocateContext() and sets its default values using SetDefaultContext(). More...
 
void SetDefaultContext (Context< T > *context) const
 
virtual void SetRandomState (const Context< T > &context, State< T > *state, RandomGenerator *generator) const
 Assigns random values to all elements of the state. More...
 
virtual void SetRandomParameters (const Context< T > &context, Parameters< T > *parameters, RandomGenerator *generator) const
 Assigns random values to all parameters. More...
 
void SetRandomContext (Context< T > *context, RandomGenerator *generator) const
 
void AllocateFreestandingInputs (Context< T > *context) const
 For each input port, allocates a freestanding input of the concrete type that this System requires, and binds it to the port, disconnecting any prior input. More...
 
bool HasAnyDirectFeedthrough () const
 Returns true if any of the inputs to the system might be directly fed through to any of its outputs and false otherwise. More...
 
bool HasDirectFeedthrough (int output_port) const
 Returns true if there might be direct-feedthrough from any input port to the given output_port, and false otherwise. More...
 
bool HasDirectFeedthrough (int input_port, int output_port) const
 Returns true if there might be direct-feedthrough from the given input_port to the given output_port, and false otherwise. More...
 
void Publish (const Context< T > &context, const EventCollection< PublishEvent< T >> &events) const
 This method is the public entry point for dispatching all publish event handlers. More...
 
void Publish (const Context< T > &context) const
 Forces a publish on the system, given a context. More...
 
const T & EvalConservativePower (const Context< T > &context) const
 Returns a reference to the cached value of the conservative power. More...
 
const T & EvalNonConservativePower (const Context< T > &context) const
 Returns a reference to the cached value of the non-conservative power. More...
 
template<template< typename > class Vec = BasicVector>
const Vec< T > * EvalVectorInput (const Context< T > &context, int port_index) const
 Causes the vector-valued input port with the given port_index to become up-to-date, delegating to our parent Diagram if necessary. More...
 
Eigen::VectorBlock< const VectorX< T > > EvalEigenVectorInput (const Context< T > &context, int port_index) const
 Causes the vector-valued input port with the given port_index to become up-to-date, delegating to our parent Diagram if necessary. More...
 
const AbstractValueEvalAbstractInput (const Context< T > &context, int port_index) const
 Causes the abstract-valued input port with the given port_index to become up-to-date, delegating to our parent Diagram if necessary. More...
 
template<typename V >
const V * EvalInputValue (const Context< T > &context, int port_index) const
 Causes the abstract-valued input port with the given port_index to become up-to-date, delegating to our parent Diagram if necessary. More...
 
int get_num_constraint_equations (const Context< T > &context) const
 Gets the number of constraint equations for this system using the given context (useful in case the number of constraints is dependent upon the current state (as might be the case with a system modeled using piecewise differential algebraic equations). More...
 
Eigen::VectorXd EvalConstraintEquations (const Context< T > &context) const
 Evaluates the constraint equations for the system at the generalized coordinates and generalized velocity specified by the context. More...
 
Eigen::VectorXd EvalConstraintEquationsDot (const Context< T > &context) const
 Computes the time derivative of each constraint equation, evaluated at the generalized coordinates and generalized velocity specified by the context. More...
 
Eigen::VectorXd CalcVelocityChangeFromConstraintImpulses (const Context< T > &context, const Eigen::MatrixXd &J, const Eigen::VectorXd &lambda) const
 Computes the change in velocity from applying the given constraint forces to the system at the given context. More...
 
double CalcConstraintErrorNorm (const Context< T > &context, const Eigen::VectorXd &error) const
 Computes the norm on constraint error (used as a metric for comparing errors between the outputs of algebraic equations applied to two different state variable instances). More...
 
void CalcTimeDerivatives (const Context< T > &context, ContinuousState< T > *derivatives) const
 Calculates the time derivatives xcdot of the continuous state xc. More...
 
void CalcDiscreteVariableUpdates (const Context< T > &context, const EventCollection< DiscreteUpdateEvent< T >> &events, DiscreteValues< T > *discrete_state) const
 This method is the public entry point for dispatching all discrete variable update event handlers. More...
 
void CalcDiscreteVariableUpdates (const Context< T > &context, DiscreteValues< T > *discrete_state) const
 This method forces a discrete update on the system given a context, and the updated discrete state is stored in discrete_state. More...
 
void CalcUnrestrictedUpdate (const Context< T > &context, const EventCollection< UnrestrictedUpdateEvent< T >> &events, State< T > *state) const
 This method is the public entry point for dispatching all unrestricted update event handlers. More...
 
void CalcUnrestrictedUpdate (const Context< T > &context, State< T > *state) const
 This method forces an unrestricted update on the system given a context, and the updated state is stored in discrete_state. More...
 
CalcNextUpdateTime (const Context< T > &context, CompositeEventCollection< T > *events) const
 This method is called by a Simulator during its calculation of the size of the next continuous step to attempt. More...
 
void GetPerStepEvents (const Context< T > &context, CompositeEventCollection< T > *events) const
 This method is called by Simulator::Initialize() to gather all update and publish events that are to be handled in StepTo() at the point before Simulator integrates continuous state. More...
 
void GetInitializationEvents (const Context< T > &context, CompositeEventCollection< T > *events) const
 This method is called by Simulator::Initialize() to gather all update and publish events that need to be handled at initialization before the simulator starts integration. More...
 
optional< PeriodicEventDataGetUniquePeriodicDiscreteUpdateAttribute () const
 Gets whether there exists a unique periodic attribute that triggers one or more discrete update events (and, if so, returns that unique periodic attribute). More...
 
std::map< PeriodicEventData, std::vector< const Event< T > * >, PeriodicEventDataComparatorGetPeriodicEvents () const
 Gets all periodic triggered events for a system. More...
 
void CalcOutput (const Context< T > &context, SystemOutput< T > *outputs) const
 Utility method that computes for every output port i the value y(i) that should result from the current contents of the given Context. More...
 
CalcPotentialEnergy (const Context< T > &context) const
 Calculates and returns the potential energy current stored in the configuration provided in context. More...
 
CalcKineticEnergy (const Context< T > &context) const
 Calculates and returns the kinetic energy currently present in the motion provided in the given Context. More...
 
CalcConservativePower (const Context< T > &context) const
 Calculates and returns the rate at which mechanical energy is being converted from potential energy to kinetic energy by this system in the given Context. More...
 
CalcNonConservativePower (const Context< T > &context) const
 Calculates and returns 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 Context). More...
 
void MapVelocityToQDot (const Context< T > &context, const VectorBase< T > &generalized_velocity, VectorBase< T > *qdot) const
 Transforms a given generalized velocity v to the time derivative qdot of the generalized configuration q taken from the supplied Context. More...
 
void MapVelocityToQDot (const Context< T > &context, const Eigen::Ref< const VectorX< T >> &generalized_velocity, VectorBase< T > *qdot) const
 Transforms the given generalized velocity to the time derivative of generalized configuration. More...
 
void MapQDotToVelocity (const Context< T > &context, const VectorBase< T > &qdot, VectorBase< T > *generalized_velocity) const
 Transforms the time derivative qdot of the generalized configuration q to generalized velocities v. More...
 
void MapQDotToVelocity (const Context< T > &context, const Eigen::Ref< const VectorX< T >> &qdot, VectorBase< T > *generalized_velocity) const
 Transforms the given time derivative qdot of generalized configuration q to generalized velocity v. More...
 
void set_name (const std::string &name)
 Sets the name of the system. More...
 
std::string get_name () const
 Returns the name last supplied to set_name(), or empty if set_name() was never called. More...
 
std::string GetMemoryObjectName () const
 Returns a name for this System based on a stringification of its type name and memory address. More...
 
void GetPath (std::stringstream *output) const
 Writes the full path of this System in the tree of Systems to output. More...
 
std::string GetPath () const
 
int get_num_input_ports () const
 Returns the number of input ports of the system. More...
 
int get_num_output_ports () const
 Returns the number of output ports of the system. More...
 
const InputPortDescriptor< T > & get_input_port (int port_index) const
 Returns the descriptor of the input port at index port_index. More...
 
const OutputPort< T > & get_output_port (int port_index) const
 Returns the output port at index port_index. More...
 
int get_num_constraints () const
 Returns the number of constraints specified for the system. More...
 
const SystemConstraint< T > & get_constraint (SystemConstraintIndex constraint_index) const
 Returns the constraint at index constraint_index. More...
 
bool CheckSystemConstraintsSatisfied (const Context< T > &context, double tol) const
 Returns true if context satisfies all of the registered SystemConstraints with tolerance tol. More...
 
int get_num_total_inputs () const
 Returns the total dimension of all of the input ports (as if they were muxed). More...
 
int get_num_total_outputs () const
 Returns the total dimension of all of the output ports (as if they were muxed). More...
 
void CheckValidOutput (const SystemOutput< T > *output) const
 Checks that output is consistent with the number and size of output ports declared by the system. More...
 
template<typename T1 = T>
void CheckValidContextT (const Context< T1 > &context) const
 Checks that context is consistent for this System template. More...
 
VectorX< T > CopyContinuousStateVector (const Context< T > &context) const
 Returns a copy of the continuous state vector xc into an Eigen vector. More...
 
void set_parent (const detail::InputPortEvaluatorInterface< T > *parent)
 Declares that parent is the immediately enclosing Diagram. More...
 
std::string GetGraphvizString () const
 Returns a Graphviz string describing this System. More...
 
int64_t GetGraphvizId () const
 Returns an opaque integer that uniquely identifies this system in the Graphviz output. More...
 
void FixInputPortsFrom (const System< double > &other_system, const Context< double > &other_context, Context< T > *target_context) const
 Fixes all of the input ports in target_context to their current values in other_context, as evaluated by other_system. More...
 
const SystemScalarConverterget_system_scalar_converter () const
 (Advanced) Returns the SystemScalarConverter for this object. More...
 
std::unique_ptr< System< AutoDiffXd > > ToAutoDiffXd () const
 Creates a deep copy of this System, transmogrified to use the autodiff scalar type, with a dynamic-sized vector of partial derivatives. More...
 
std::unique_ptr< System< AutoDiffXd > > ToAutoDiffXdMaybe () const
 Creates a deep copy of this system exactly like ToAutoDiffXd(), but returns nullptr if this System does not support autodiff, instead of throwing an exception. More...
 
std::unique_ptr< System< symbolic::Expression > > ToSymbolic () const
 Creates a deep copy of this System, transmogrified to use the symbolic scalar type. More...
 
std::unique_ptr< System< symbolic::Expression > > ToSymbolicMaybe () const
 Creates a deep copy of this system exactly like ToSymbolic(), but returns nullptr if this System does not support symbolic, instead of throwing an exception. More...
 
- Public Member Functions inherited from SystemBase
 ~SystemBase () override
 
void set_name (const std::string &name)
 Sets the name of the system. More...
 
const std::string & GetSystemName () const final
 Returns the name last supplied to set_name(), or a default name if set_name() was never called. More...
 
std::string GetSystemPathname () const final
 Generates and returns the full path name of this subsystem, starting from the root System, with '/' delimiters between parent and child subsystems. More...
 
std::string GetSystemType () const final
 Returns the most-derived type of this concrete System object as a human-readable string suitable for use in error messages. More...
 
void ThrowIfContextNotCompatible (const ContextBase &context) const final
 Throws an exception with an appropriate message if the given context is not compatible with this System. More...
 
std::unique_ptr< ContextBaseAllocateContext () const
 Returns a Context suitable for use with this System. More...
 
int num_cache_entries () const
 Returns the number nc of cache entries currently allocated in this System. More...
 
const CacheEntryget_cache_entry (CacheIndex index) const
 Return a reference to a CacheEntry given its index. More...
 
void CheckValidContext (const ContextBase &context) const
 Checks whether the given context is valid for this System and throws an exception with a helpful message if not. More...
 
 SystemBase (const SystemBase &)=delete
 
SystemBaseoperator= (const SystemBase &)=delete
 
 SystemBase (SystemBase &&)=delete
 
SystemBaseoperator= (SystemBase &&)=delete
 
const CacheEntryDeclareCacheEntry (std::string description, CacheEntry::AllocCallback alloc_function, CacheEntry::CalcCallback calc_function, std::vector< DependencyTicket > prerequisites_of_calc={all_sources_ticket()})
 Declares a new CacheEntry in this System using the least-restrictive definitions for the associated functions. More...
 
template<class MySystem , class MyContext , typename ValueType >
const CacheEntryDeclareCacheEntry (std::string description, ValueType(MySystem::*make)() const, void(MySystem::*calc)(const MyContext &, ValueType *) const, std::vector< DependencyTicket > prerequisites_of_calc={all_sources_ticket()})
 Declares a cache entry by specifying member functions to use both for the allocator and calculator. More...
 
template<class MySystem , class MyContext , typename ValueType >
const CacheEntryDeclareCacheEntry (std::string description, const ValueType &model_value, void(MySystem::*calc)(const MyContext &, ValueType *) const, std::vector< DependencyTicket > prerequisites_of_calc={all_sources_ticket()})
 Declares a cache entry by specifying a model value of concrete type ValueType and a calculator function that is a class member function (method) with signature: More...
 
template<class MySystem , class MyContext , typename ValueType >
const CacheEntryDeclareCacheEntry (std::string description, void(MySystem::*calc)(const MyContext &, ValueType *) const, std::vector< DependencyTicket > prerequisites_of_calc={all_sources_ticket()})
 Declares a cache entry by specifying only a calculator function that is a class member function (method) with signature: More...
 
DependencyTicket cache_entry_ticket (CacheIndex index)
 Returns a ticket indicating dependence on a particular cache entry. More...
 

Protected Member Functions

 SpringMassSystem (SystemScalarConverter converter, double spring_constant_N_per_m, double mass_kg, bool system_is_forced)
 Constructor that specifies System Scalar Conversion support. More...
 
- Protected Member Functions inherited from LeafSystem< T >
 LeafSystem ()
 Default constructor that declares no inputs, outputs, state, parameters, events, nor scalar-type conversion support (AutoDiff, etc.). More...
 
 LeafSystem (SystemScalarConverter converter)
 Constructor that declares no inputs, outputs, state, parameters, or events, but allows subclasses to declare scalar-type conversion support (AutoDiff, etc.). More...
 
virtual std::unique_ptr< LeafContext< T > > DoMakeLeafContext () const
 Provides a new instance of the leaf context for this system. More...
 
virtual void DoValidateAllocatedLeafContext (const LeafContext< T > &context) const
 Derived classes that impose restrictions on what resources are permitted should check those restrictions by implementing this. More...
 
DoCalcWitnessValue (const Context< T > &context, const WitnessFunction< T > &witness_func) const final
 Derived classes will implement this method to evaluate a witness function at the given context. More...
 
void AddTriggeredWitnessFunctionToCompositeEventCollection (Event< T > *event, CompositeEventCollection< T > *events) const final
 Add event to events due to a witness function triggering. More...
 
void DoCalcNextUpdateTime (const Context< T > &context, CompositeEventCollection< T > *events, T *time) const override
 Computes the next update time based on the configured periodic events, for scalar types that are arithmetic, or aborts for scalar types that are not arithmetic. More...
 
BasicVector< T > * DoAllocateInputVector (const InputPortDescriptor< T > &descriptor) const override
 Allocates a vector that is suitable as an input value for descriptor. More...
 
AbstractValueDoAllocateInputAbstract (const InputPortDescriptor< T > &descriptor) const override
 Allocates an AbstractValue suitable as an input value for descriptor. More...
 
void GetGraphvizFragment (std::stringstream *dot) const override
 Emits a graphviz fragment for this System. More...
 
void GetGraphvizInputPortToken (const InputPortDescriptor< T > &port, std::stringstream *dot) const final
 Appends a fragment to the dot stream identifying the graphviz node representing port. More...
 
void GetGraphvizOutputPortToken (const OutputPort< T > &port, std::stringstream *dot) const final
 Appends a fragment to the dot stream identifying the graphviz node representing port. More...
 
virtual std::unique_ptr< ContinuousState< T > > AllocateContinuousState () const
 Returns a ContinuousState used to implement both CreateDefaultContext and AllocateTimeDerivatives. More...
 
virtual std::unique_ptr< DiscreteValues< T > > AllocateDiscreteState () const
 Reserves the discrete state as required by CreateDefaultContext. More...
 
virtual std::unique_ptr< AbstractValuesAllocateAbstractState () const
 Reserves the abstract state as required by CreateDefaultContext. More...
 
virtual std::unique_ptr< Parameters< T > > AllocateParameters () const
 Reserves the parameters as required by CreateDefaultContext. More...
 
virtual optional< boolDoHasDirectFeedthrough (int input_port, int output_port) const
 Returns true if there is direct-feedthrough from the given input_port to the given output_port, false if there is not direct-feedthrough, or nullopt if unknown (in which case SystemSymbolicInspector will attempt to measure the feedthrough using symbolic form). More...
 
int DeclareNumericParameter (const BasicVector< T > &model_vector)
 Declares a numeric parameter using the given model_vector. More...
 
template<template< typename > class U = BasicVector>
const U< T > & GetNumericParameter (const Context< T > &context, int index) const
 Extracts the numeric parameters of type U from the context at index. More...
 
template<template< typename > class U = BasicVector>
U< T > & GetMutableNumericParameter (Context< T > *context, int index) const
 Extracts the numeric parameters of type U from the context at index. More...
 
int DeclareAbstractParameter (const AbstractValue &model_value)
 Declares an abstract parameter using the given model_value. More...
 
template<typename EventType >
void DeclarePeriodicEvent (double period_sec, double offset_sec)
 Declares that this System has a simple, fixed-period event specified with no custom callback function, and its attribute field contains an Event<T>::PeriodicAttribute constructed from the specified period_sec and offset_sec. More...
 
template<typename EventType >
void DeclarePeriodicEvent (double period_sec, double offset_sec, const EventType &event)
 Declares that this System has a simple, fixed-period event specified by event. More...
 
void DeclarePeriodicDiscreteUpdate (double period_sec, double offset_sec=0)
 Declares a periodic discrete update event with period = period_sec and offset = offset_sec. More...
 
void DeclarePeriodicUnrestrictedUpdate (double period_sec, double offset_sec=0)
 Declares a periodic unrestricted update event with period = period_sec and offset = offset_sec. More...
 
void DeclarePeriodicPublish (double period_sec, double offset_sec=0)
 Declares a periodic publish event with period = period_sec and offset = offset_sec. More...
 
template<typename EventType >
void DeclarePerStepEvent (const EventType &event)
 Declares a per-step event using event, which is deep copied (the copy is maintained by this). More...
 
template<typename EventType >
void DeclareInitializationEvent (const EventType &event)
 Declares an initialization event by deep copying event and storing it internally. More...
 
void DeclareContinuousState (int num_state_variables)
 Declares that this System should reserve continuous state with num_state_variables state variables, which have no second-order structure. More...
 
void DeclareContinuousState (int num_q, int num_v, int num_z)
 Declares that this System should reserve continuous state with num_q generalized positions, num_v generalized velocities, and num_z miscellaneous state variables. More...
 
void DeclareContinuousState (const BasicVector< T > &model_vector)
 Declares that this System should reserve continuous state with model_vector.size() miscellaneous state variables, stored in a vector Cloned from model_vector. More...
 
void DeclareContinuousState (const BasicVector< T > &model_vector, int num_q, int num_v, int num_z)
 Declares that this System should reserve continuous state with num_q generalized positions, num_v generalized velocities, and num_z miscellaneous state variables, stored in a vector Cloned from model_vector. More...
 
void DeclareContinuousState (std::unique_ptr< BasicVector< T >> model_vector, int num_q, int num_v, int num_z)
 Declares that this System should reserve continuous state with num_q generalized positions, num_v generalized velocities, and num_z miscellaneous state variables, stored in the a vector Cloned from model_vector. More...
 
void DeclareDiscreteState (int num_state_variables)
 Declares that this System should reserve discrete state with num_state_variables state variables. More...
 
int DeclareAbstractState (std::unique_ptr< AbstractValue > abstract_state)
 Declares an abstract state. More...
 
template<class MySystem >
SystemConstraintIndex DeclareEqualityConstraint (void(MySystem::*calc)(const Context< T > &, VectorX< T > *) const, int count, const std::string &description)
 Declares a system constraint of the form f(context) = 0 by specifying a member function to use to calculate the (VectorX) constraint value with a signature: More...
 
SystemConstraintIndex DeclareEqualityConstraint (typename SystemConstraint< T >::CalcCallback calc, int count, const std::string &description)
 Declares a system constraint of the form f(context) = 0 by specifying a std::function to use to calculate the (Vector) constraint value with a signature: More...
 
template<class MySystem >
SystemConstraintIndex DeclareInequalityConstraint (void(MySystem::*calc)(const Context< T > &, VectorX< T > *) const, int count, const std::string &description)
 Declares a system constraint of the form f(context) ≥ 0 by specifying a member function to use to calculate the (VectorX) constraint value with a signature: More...
 
SystemConstraintIndex DeclareInequalityConstraint (typename SystemConstraint< T >::CalcCallback calc, int count, const std::string &description)
 Declares a system constraint of the form f(context) ≥ 0 by specifying a std::function to use to calculate the (Vector) constraint value with a signature: More...
 
virtual void DoPublish (const Context< T > &context, const std::vector< const PublishEvent< T > * > &events) const
 Derived-class event handler for all simultaneous publish events in events. More...
 
virtual void DoCalcDiscreteVariableUpdates (const Context< T > &context, const std::vector< const DiscreteUpdateEvent< T > * > &events, DiscreteValues< T > *discrete_state) const
 Derived-class event handler for all simultaneous discrete update events. More...
 
virtual void DoCalcUnrestrictedUpdate (const Context< T > &context, const std::vector< const UnrestrictedUpdateEvent< T > * > &events, State< T > *state) const
 Derived-class event handler for all simultaneous unrestricted update events. More...
 
const InputPortDescriptor< T > & DeclareVectorInputPort (const BasicVector< T > &model_vector, optional< RandomDistribution > random_type=nullopt)
 Declares a vector-valued input port using the given model_vector. More...
 
const InputPortDescriptor< T > & DeclareAbstractInputPort (const AbstractValue &model_value)
 Declares an abstract-valued input port using the given model_value. More...
 
template<class MySystem >
std::unique_ptr< WitnessFunction< T > > DeclareWitnessFunction (const std::string &description, const WitnessFunctionDirection &direction_type, T(MySystem::*calc)(const Context< T > &) const) const
 Constructs the witness function with the given description (used primarily for debugging and logging), direction type, and calculator function; and with no event object. More...
 
template<class MySystem >
std::unique_ptr< WitnessFunction< T > > DeclareWitnessFunction (const std::string &description, const WitnessFunctionDirection &direction_type, T(MySystem::*calc)(const Context< T > &) const, void(MySystem::*publish_callback)(const Context< T > &, const PublishEvent< T > &) const) const
 Constructs the witness function with the given description (used primarily for debugging and logging), direction type, calculation function, and publish event callback function for when this triggers. More...
 
template<class MySystem >
std::unique_ptr< WitnessFunction< T > > DeclareWitnessFunction (const std::string &description, const WitnessFunctionDirection &direction_type, T(MySystem::*calc)(const Context< T > &) const, void(MySystem::*du_callback)(const Context< T > &, const DiscreteUpdateEvent< T > &, DiscreteValues< T > *) const) const
 Constructs the witness function with the given description (used primarily for debugging and logging), direction type, calculation function, and discrete update event callback function for when this triggers. More...
 
template<class MySystem >
std::unique_ptr< WitnessFunction< T > > DeclareWitnessFunction (const std::string &description, const WitnessFunctionDirection &direction_type, T(MySystem::*calc)(const Context< T > &) const, void(MySystem::*uu_callback)(const Context< T > &, const UnrestrictedUpdateEvent< T > &, State< T > *) const) const
 Constructs the witness function with the given description (used primarily for debugging and logging), direction type, calculation function, and unrestricted update event callback function for when this triggers. More...
 
template<class MySystem >
std::unique_ptr< WitnessFunction< T > > DeclareWitnessFunction (const std::string &description, const WitnessFunctionDirection &direction_type, T(MySystem::*calc)(const Context< T > &) const, const Event< T > &e) const
 Constructs the witness function with the given description (used primarily for debugging and logging), direction type, and calculation function, and with a unique pointer to the event that is to be dispatched when this witness function triggers. More...
 
template<class MySystem , typename BasicVectorSubtype >
const OutputPort< T > & DeclareVectorOutputPort (const BasicVectorSubtype &model_vector, void(MySystem::*calc)(const Context< T > &, BasicVectorSubtype *) const)
 Declares a vector-valued output port by specifying (1) a model vector of type BasicVectorSubtype derived from BasicVector and initialized to the correct size and desired initial value, and (2) a calculator function that is a class member function (method) with signature: More...
 
template<class MySystem , typename BasicVectorSubtype >
const OutputPort< T > & DeclareVectorOutputPort (void(MySystem::*calc)(const Context< T > &, BasicVectorSubtype *) const)
 Declares a vector-valued output port by specifying only a calculator function that is a class member function (method) with signature: More...
 
const OutputPort< T > & DeclareVectorOutputPort (const BasicVector< T > &model_vector, typename LeafOutputPort< T >::CalcVectorCallback vector_calc_function)
 (Advanced) Declares a vector-valued output port using the given model_vector and a function for calculating the port's value at runtime. More...
 
template<class MySystem , typename OutputType >
const OutputPort< T > & DeclareAbstractOutputPort (const OutputType &model_value, void(MySystem::*calc)(const Context< T > &, OutputType *) const)
 Declares an abstract-valued output port by specifying a model value of concrete type OutputType and a calculator function that is a class member function (method) with signature: More...
 
template<class MySystem , typename OutputType >
const OutputPort< T > & DeclareAbstractOutputPort (void(MySystem::*calc)(const Context< T > &, OutputType *) const)
 Declares an abstract-valued output port by specifying only a calculator function that is a class member function (method) with signature: More...
 
template<class MySystem , typename OutputType >
const OutputPort< T > & DeclareAbstractOutputPort (OutputType(MySystem::*make)() const, void(MySystem::*calc)(const Context< T > &, OutputType *) const)
 Declares an abstract-valued output port by specifying member functions to use both for the allocator and calculator. More...
 
const OutputPort< T > & DeclareAbstractOutputPort (typename LeafOutputPort< T >::AllocCallback alloc_function, typename LeafOutputPort< T >::CalcCallback calc_function)
 (Advanced) Declares an abstract-valued output port using the given allocator and calculator functions provided in their most generic forms. More...
 
- Protected Member Functions inherited from System< T >
virtual void DoGetWitnessFunctions (const Context< T > &, std::vector< const WitnessFunction< T > * > *) const
 Derived classes can override this method to provide witness functions active for the given state. More...
 
SystemConstraintIndex AddConstraint (std::unique_ptr< SystemConstraint< T >> constraint)
 Adds an already-created constraint to the list of constraints for this System. More...
 
const EventCollection< PublishEvent< T > > & get_forced_publish_events () const
 
const EventCollection< DiscreteUpdateEvent< T > > & get_forced_discrete_update_events () const
 
const EventCollection< UnrestrictedUpdateEvent< T > > & get_forced_unrestricted_update_events () const
 
void set_forced_publish_events (std::unique_ptr< EventCollection< PublishEvent< T >>> forced)
 
void set_forced_discrete_update_events (std::unique_ptr< EventCollection< DiscreteUpdateEvent< T >>> forced)
 
void set_forced_unrestricted_update_events (std::unique_ptr< EventCollection< UnrestrictedUpdateEvent< T >>> forced)
 
 System (SystemScalarConverter converter)
 Constructs an empty System base class object, possibly supporting scalar-type conversion support (AutoDiff, etc.) using converter. More...
 
const InputPortDescriptor< T > & DeclareInputPort (PortDataType type, int size, optional< RandomDistribution > random_type=nullopt)
 Adds a port with the specified type and size to the input topology. More...
 
const InputPortDescriptor< T > & DeclareAbstractInputPort ()
 Adds an abstract-valued port to the input topology. More...
 
void CreateOutputPort (std::unique_ptr< OutputPort< T >> port)
 Adds an already-created output port to this System. More...
 
virtual void DoMapQDotToVelocity (const Context< T > &context, const Eigen::Ref< const VectorX< T >> &qdot, VectorBase< T > *generalized_velocity) const
 Provides the substantive implementation of MapQDotToVelocity(). More...
 
virtual void DoMapVelocityToQDot (const Context< T > &context, const Eigen::Ref< const VectorX< T >> &generalized_velocity, VectorBase< T > *qdot) const
 Provides the substantive implementation of MapVelocityToQDot(). More...
 
virtual int do_get_num_constraint_equations (const Context< T > &context) const
 Gets the number of constraint equations for this system from the given context. More...
 
virtual Eigen::VectorXd DoEvalConstraintEquations (const Context< T > &context) const
 Evaluates the constraint equations for the system at the generalized coordinates and generalized velocity specified by the context. More...
 
virtual Eigen::VectorXd DoEvalConstraintEquationsDot (const Context< T > &context) const
 Computes the time derivative of each constraint equation, evaluated at the generalized coordinates and generalized velocity specified by the context. More...
 
virtual Eigen::VectorXd DoCalcVelocityChangeFromConstraintImpulses (const Context< T > &context, const Eigen::MatrixXd &J, const Eigen::VectorXd &lambda) const
 Computes the change in velocity from applying the given constraint forces to the system at the given context. More...
 
virtual double DoCalcConstraintErrorNorm (const Context< T > &context, const Eigen::VectorXd &error) const
 Computes the norm of the constraint error. More...
 
Eigen::VectorBlock< VectorX< T > > GetMutableOutputVector (SystemOutput< T > *output, int port_index) const
 Returns a mutable Eigen expression for a vector valued output port with index port_index in this system. More...
 
void EvalInputPort (const Context< T > &context, int port_index) const
 Causes an InputPortValue in the context to become up-to-date, delegating to the parent Diagram if necessary. More...
 
- Protected Member Functions inherited from SystemBase
 SystemBase ()=default
 

Additional Inherited Members

- Static Public Member Functions inherited from System< T >
template<template< typename > class S = ::drake::systems::System>
static std::unique_ptr< S< AutoDiffXd > > ToAutoDiffXd (const S< T > &from)
 Creates a deep copy of from, transmogrified to use the autodiff scalar type, with a dynamic-sized vector of partial derivatives. More...
 
template<template< typename > class S = ::drake::systems::System>
static std::unique_ptr< S< symbolic::Expression > > ToSymbolic (const S< T > &from)
 Creates a deep copy of from, transmogrified to use the symbolic scalar type. More...
 
- Static Public Member Functions inherited from SystemBase
static DependencyTicket all_sources_ticket ()
 Returns a ticket indicating dependence on every possible independent source value, including time, state, input ports, parameters, and the accuracy setting (but not cache entries). More...
 
static DependencyTicket nothing_ticket ()
 Returns a ticket indicating that a computation does not depend on any source value; that is, it is a constant. More...
 
static DependencyTicket time_ticket ()
 Returns a ticket indicating dependence on time. More...
 
static DependencyTicket accuracy_ticket ()
 Returns a ticket indicating dependence on the accuracy setting in the Context. More...
 
static DependencyTicket q_ticket ()
 Returns a ticket indicating that a computation depends on configuration state variables q. More...
 
static DependencyTicket v_ticket ()
 Returns a ticket indicating dependence on velocity state variables v. More...
 
static DependencyTicket z_ticket ()
 Returns a ticket indicating dependence on all of the miscellaneous continuous state variables z. More...
 
static DependencyTicket xc_ticket ()
 Returns a ticket indicating dependence on all of the continuous state variables q, v, or z. More...
 
static DependencyTicket xd_ticket ()
 Returns a ticket indicating dependence on all of the numerical discrete state variables, in any discrete variable group. More...
 
static DependencyTicket xa_ticket ()
 Returns a ticket indicating dependence on all of the abstract state variables in the current Context. More...
 
static DependencyTicket all_state_ticket ()
 Returns a ticket indicating dependence on all state variables x in this subsystem, including continuous variables xc, discrete (numeric) variables xd, and abstract state variables xa. More...
 
static DependencyTicket xcdot_ticket ()
 Returns a ticket for the cache entry that holds time derivatives of the continuous variables. More...
 
static DependencyTicket xdhat_ticket ()
 Returns a ticket for the cache entry that holds the discrete state update for the numerical discrete variables in the state. More...
 
static DependencyTicket configuration_ticket ()
 Returns a ticket indicating dependence on all the configuration variables for this System. More...
 
static DependencyTicket velocity_ticket ()
 Returns a ticket indicating dependence on all of the velocity variables for this System. More...
 
static DependencyTicket kinematics_ticket ()
 Returns a ticket indicating dependence on all of the configuration and velocity state variables of this System. More...
 
static DependencyTicket all_parameters_ticket ()
 Returns a ticket indicating dependence on all parameters p in this subsystem, including numeric parameters pn, and abstract parameters pa. More...
 
static DependencyTicket all_input_ports_ticket ()
 Returns a ticket indicating dependence on all input ports u of this subsystem. More...
 
- Static Protected Member Functions inherited from SystemBase
static std::unique_ptr< ContextBaseMakeContext (const SystemBase &system)
 Allows Diagram to use private MakeContext() to invoke the same method on its children. More...
 
static void ValidateAllocatedContext (const SystemBase &system, const ContextBase &context)
 Allows Diagram to use its private ValidateAllocatedContext() to invoke the same method on its children. More...
 

Detailed Description

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

A model of a one-dimensional spring-mass system.

/// |-----\/\/ k /\/\----( m )  +x
/// 

Units are MKS (meters-kilograms-seconds).

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

  • double
  • AutoDiffXd

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

Constructor & Destructor Documentation

SpringMassSystem ( const SpringMassSystem< T > &  )
delete
SpringMassSystem ( SpringMassSystem< T > &&  )
delete
SpringMassSystem ( double  spring_constant_N_per_m,
double  mass_kg,
bool  system_is_forced = false 
)

Constructs a spring-mass system with a fixed spring constant and given mass.

Subclasses must use the protected constructor, not this one.

Parameters
[in]spring_constant_N_per_mThe spring constant in N/m.
[in]mass_KgThe actual value in Kg of the mass attached to the spring.
[in]system_is_forcedIf true, the system has an input port for an external force. If false, the system has no inputs.
SpringMassSystem ( const SpringMassSystem< U > &  other)
explicit

Scalar-converting copy constructor. See System Scalar Conversion.

SpringMassSystem ( SystemScalarConverter  converter,
double  spring_constant_N_per_m,
double  mass_kg,
bool  system_is_forced 
)
protected

Constructor that specifies System Scalar Conversion support.

Here is the call graph for this function:

Member Function Documentation

T DoCalcConservativePower ( const Context< T > &  context) const
overridevirtual

Returns the rate at which mechanical energy is being converted from potential energy in the spring to kinetic energy of the mass by this spring-mass system in the given Context.

For this system, we have conservative power

///   power_c = f v
///           = power_ke
///           = -power_pe
/// 

This quantity is positive when the spring is accelerating the mass and negative when the spring is decelerating the mass.

Reimplemented from System< T >.

Here is the call graph for this function:

T DoCalcKineticEnergy ( const Context< T > &  context) const
overridevirtual

Returns the current kinetic energy of the moving mass in the given Context.

This is ke = m v^2 / 2 for this system. The rate of change of kinetic energy (that is, power that adding to kinetic energy) is

///   power_ke = d/dt ke
///            = m v a
///            = m v (f/m)
///            = f v
///            = -power_pe
/// 

(assuming the only force is due to the spring). Energy is in joules.

See also
EvalSpringForce(), EvalPotentialEnergy()

Reimplemented from System< T >.

Here is the call graph for this function:

T DoCalcNonConservativePower ( const Context< T > &  context) const
overridevirtual

Returns power that doesn't involve the conservative spring element.

(There is none in this system.)

Reimplemented from System< T >.

Here is the call graph for this function:

T DoCalcPotentialEnergy ( const Context< T > &  context) const
overridevirtual

Returns the potential energy currently stored in the spring in the given Context.

For this linear spring, pe = k (x-x0)^2 / 2, so that spring force f = -k (x-x0) is the negative gradient of pe. The rate of change of potential energy (that is, power that adding to potential energy) is

///   power_pe = d/dt pe
///            = k (x-x0) v
///            = -f v.
/// 

Energy is in joules J (N-m).

Reimplemented from System< T >.

Here is the call graph for this function:

void DoCalcTimeDerivatives ( const Context< T > &  context,
ContinuousState< T > *  derivatives 
) const
overridevirtual

Override this if you have any continuous state variables xc in your concrete System to calculate their time derivatives.

The derivatives vector will correspond elementwise with the state vector Context.state.continuous_state.get_state(). Thus, if the state in the Context has second-order structure xc=[q,v,z], that same structure applies to the derivatives.

This method is called only from the public non-virtual CalcTimeDerivatives() which will already have error-checked the parameters so you don't have to. In particular, implementations may assume that the given Context is valid for this System; that the derivatives pointer is non-null, and that the referenced object has the same constituent structure as was produced by AllocateTimeDerivatives().

The default implementation does nothing if the derivatives vector is size zero and aborts otherwise.

Reimplemented from System< T >.

Here is the call graph for this function:

T EvalSpringForce ( const Context< T > &  context) const

Returns the force being applied by the spring to the mass in the given Context.

This force f is given by f = -k (x-x0); the spring applies the opposite force -f to the world attachment point at the other end. The force is in newtons N (kg-m/s^2).

Here is the call graph for this function:

Here is the caller graph for this function:

T get_conservative_work ( const Context< T > &  context) const
inline

Gets the current value of the conservative power integral in the given Context.

const InputPortDescriptor< T > & get_force_port ( ) const

Returns the input port to the externally applied force.

Here is the call graph for this function:

T get_input_force ( const Context< T > &  context) const
inline
Returns
the external driving force to the system.

Here is the call graph for this function:

Here is the caller graph for this function:

double get_mass ( ) const
inline

Returns the mass m that was provided at construction, in kg.

Here is the caller graph for this function:

const OutputPort< T > & get_output_port ( ) const

Returns the port to output state.

Here is the call graph for this function:

T get_position ( const Context< T > &  context) const
inline

Gets the current position of the mass in the given Context.

Here is the caller graph for this function:

double get_spring_constant ( ) const
inline

Returns the spring constant k that was provided at construction, in N/m.

Here is the caller graph for this function:

bool get_system_is_forced ( ) const
inline

Returns true iff the system is forced.

T get_velocity ( const Context< T > &  context) const
inline

Gets the current velocity of the mass in the given Context.

Here is the caller graph for this function:

void GetClosedFormSolution ( const T &  x0,
const T &  v0,
const T &  tf,
T *  xf,
T *  vf 
) const
inline

Returns the closed-form position and velocity solution for this system from the given initial conditions.

Parameters
x0the position of the spring at time t = 0.
v0the velocity of the spring at time t = 0.
tfthe time at which to return the position and velocity.
[out]xfthe position of the spring at time tf, on return.
[out]vfthe velocity of the spring at time tf, on return.
Exceptions
std::logic_errorif xf or vf is nullptr or if the system is forced.

Here is the call graph for this function:

Here is the caller graph for this function:

SpringMassSystem& operator= ( SpringMassSystem< T > &&  )
delete
SpringMassSystem& operator= ( const SpringMassSystem< T > &  )
delete
void set_conservative_work ( Context< T > *  context,
const T &  energy 
) const
inline

Sets the initial value of the conservative power integral in the given Context.

void set_position ( Context< T > *  context,
const T &  position 
) const
inline

Sets the position of the mass in the given Context.

void set_velocity ( Context< T > *  context,
const T &  velocity 
) const
inline

Sets the velocity of the mass in the given Context.


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