DMP_BBO library
Protected Member Functions | Friends | List of all members
DynamicalSystem Class Referenceabstract

Interface for implementing dynamical systems. More...

#include <DynamicalSystem.hpp>

Inheritance diagram for DynamicalSystem:
Inheritance graph
[legend]

Public Member Functions

Constructors/Destructor
 DynamicalSystem (int order, double tau, Eigen::VectorXd initial_state, Eigen::VectorXd attractor_state, std::string name)
 Initialization constructor. More...
 
virtual ~DynamicalSystem (void)
 Destructor.
 
virtual DynamicalSystemclone (void) const =0
 Return a pointer to a deep copy of the DynamicalSystem object. More...
 
Main DynamicalSystem functions
virtual void differentialEquation (const Eigen::Ref< const Eigen::VectorXd > &x, Eigen::Ref< Eigen::VectorXd > xd) const =0
 The differential equation which defines the system. More...
 
virtual void analyticalSolution (const Eigen::VectorXd &ts, Eigen::MatrixXd &xs, Eigen::MatrixXd &xds) const =0
 Return analytical solution of the system at certain times. More...
 
virtual void integrateStart (Eigen::Ref< Eigen::VectorXd > x, Eigen::Ref< Eigen::VectorXd > xd) const
 Start integrating the system. More...
 
void integrateStart (const Eigen::VectorXd &x_init, Eigen::Ref< Eigen::VectorXd > x, Eigen::Ref< Eigen::VectorXd > xd)
 Start integrating the system with a new initial state. More...
 
virtual void integrateStep (double dt, const Eigen::Ref< const Eigen::VectorXd > x, Eigen::Ref< Eigen::VectorXd > x_updated, Eigen::Ref< Eigen::VectorXd > xd_updated) const
 Integrate the system one time step. More...
 

Protected Member Functions

 DynamicalSystem (void)
 Default constructor. More...
 

Friends

class boost::serialization::access
 Give boost serialization access to private members. More...
 

Input/Output

std::ostream & operator<< (std::ostream &output, const DynamicalSystem &dyn_sys)
 Write a DynamicalSystem to an output stream. More...
 
virtual std::string toString (void) const =0
 Returns a string representation of the object. More...
 

Accessor functions

enum  IntegrationMethod { EULER, RUNGE_KUTTA }
 The possible integration methods that can be used. More...
 
void set_integration_method (IntegrationMethod integration_method)
 Choose the integration method. More...
 
int dim (void) const
 Get the dimensionality of the dynamical system, i.e. More...
 
int dim_orig (void) const
 Get the dimensionality of the dynamical system, i.e. More...
 
double tau (void) const
 Accessor function for the time constant. More...
 
virtual void set_tau (double tau)
 Mutator function for the time constant. More...
 
Eigen::VectorXd initial_state (void) const
 Accessor function for the initial state of the dynamical system. More...
 
void initial_state (Eigen::VectorXd &initial_state) const
 Accessor function for the initial state of the dynamical system. More...
 
virtual void set_initial_state (const Eigen::VectorXd &initial_state)
 Mutator function for the initial state of the dynamical system. More...
 
Eigen::VectorXd attractor_state (void) const
 Accessor function for the attractor state of the dynamical system. More...
 
void attractor_state (Eigen::VectorXd &attractor_state) const
 Accessor function for the attractor state of the dynamical system. More...
 
virtual void set_attractor_state (const Eigen::Ref< const Eigen::VectorXd > &attractor_state)
 Mutator function for the attractor state of the dynamical system. More...
 
std::string name (void) const
 Accessor function for the name of the dynamical system. More...
 
virtual void set_name (std::string name)
 Mutator function for the name of the dynamical system. More...
 
void set_dim (int dim)
 Set the dimensionality of the dynamical system, i.e. More...
 

Detailed Description

Interface for implementing dynamical systems.

Other dynamical systems should inherit from this class.

Two pure virtual functions that each DynamicalSystem subclass should implement are

This class provides accesor/mutator methods for some variables typically found in dynamical systems:

This class also provides functionality for integrating a dynamical system by repeatidly calling it's differentialEquation, and doing simple Euler or 4th-order Runge-Kutta integration. The related functions are:

Definition at line 62 of file DynamicalSystem.hpp.

Member Enumeration Documentation

The possible integration methods that can be used.

Definition at line 190 of file DynamicalSystem.hpp.

190 { EULER, RUNGE_KUTTA };

Constructor & Destructor Documentation

DynamicalSystem ( int  order,
double  tau,
Eigen::VectorXd  initial_state,
Eigen::VectorXd  attractor_state,
std::string  name 
)

Initialization constructor.

Parameters
orderOrder of the system
tauTime constant, see tau()
initial_stateInitial state, see initial_state()
attractor_stateAttractor state, see attractor_state()
nameA name you give, see name()

Definition at line 35 of file DynamicalSystem.cpp.

36  :
37  // For 1st order systems, the dimensionality of the state vector 'x' is 'dim'
38  // For 2nd order systems, the system is expanded to x = [y z], where 'y' and
39  // 'z' are both of dimensionality 'dim'. Therefore dim(x) is 2*dim
40  dim_(initial_state.size()*order),
41  // The dimensionality of the system before a potential rewrite
42  dim_orig_(initial_state.size()),
43  tau_(tau),initial_state_(initial_state),attractor_state_(attractor_state),
44  name_(name),integration_method_(RUNGE_KUTTA)
45 {
46  assert(order==1 || order==2);
47  assert(initial_state.size()==attractor_state.size());
48 }
double tau(void) const
Accessor function for the time constant.
Eigen::VectorXd initial_state(void) const
Accessor function for the initial state of the dynamical system.
std::string name(void) const
Accessor function for the name of the dynamical system.
Eigen::VectorXd attractor_state(void) const
Accessor function for the attractor state of the dynamical system.
DynamicalSystem ( void  )
inlineprotected

Default constructor.

Remarks
This default constuctor is required for boost::serialization to work. See Boost serialization issues

Definition at line 375 of file DynamicalSystem.hpp.

375 {};

Here is the call graph for this function:

Member Function Documentation

virtual DynamicalSystem* clone ( void  ) const
pure virtual

Return a pointer to a deep copy of the DynamicalSystem object.

Returns
Pointer to a deep copy

Implemented in Dmp, DmpWithGainSchedules, SpringDamperSystem, ExponentialSystem, TimeSystem, and SigmoidSystem.

virtual void differentialEquation ( const Eigen::Ref< const Eigen::VectorXd > &  x,
Eigen::Ref< Eigen::VectorXd >  xd 
) const
pure virtual

The differential equation which defines the system.

It relates state values to rates of change of those state values

Parameters
[in]xcurrent state (column vector of size dim() X 1)
[out]xdrate of change in state (column vector of size dim() X 1)
Remarks
x and xd should be of size dim() X 1. This forces you to pre-allocate memory, which speeds things up (and also makes Eigen's Ref functionality easier to deal with).

Implemented in Dmp, SpringDamperSystem, ExponentialSystem, TimeSystem, and SigmoidSystem.

virtual void analyticalSolution ( const Eigen::VectorXd &  ts,
Eigen::MatrixXd &  xs,
Eigen::MatrixXd &  xds 
) const
pure virtual

Return analytical solution of the system at certain times.

Parameters
[in]tsA vector of times for which to compute the analytical solutions
[out]xsSequence of state vectors. T x D or D x T matrix, where T is the number of times (the length of 'ts'), and D the size of the state (i.e. dim())
[out]xdsSequence of state vectors (rates of change). T x D or D x T matrix, where T is the number of times (the length of 'ts'), and D the size of the state (i.e. dim())
Remarks
The output xs and xds will be of size D x T only if the matrix x you pass as an argument of size D x T. In all other cases (i.e. including passing an empty matrix) the size of x will be T x D. This feature has been added so that you may pass matrices of either size.

Implemented in Dmp, SpringDamperSystem, ExponentialSystem, TimeSystem, and SigmoidSystem.

void integrateStart ( Eigen::Ref< Eigen::VectorXd >  x,
Eigen::Ref< Eigen::VectorXd >  xd 
) const
virtual

Start integrating the system.

Parameters
[out]x- The first vector of state variables
[out]xd- The first vector of rates of change of the state variables
Remarks
x and xd should be of size dim() X 1. This forces you to pre-allocate memory, which speeds things up (and also makes Eigen's Ref functionality easier to deal with).

Reimplemented in Dmp.

Definition at line 60 of file DynamicalSystem.cpp.

60  {
61  // Check size. Leads to faster numerical integration and makes Eigen::Ref easier to deal with
62  assert(x.size()==dim());
63  assert(xd.size()==dim());
64 
65  // Return value for state variables
66  // Pad the end with zeros: Why? In the spring-damper system, the state consists of x = [y z].
67  // The initial state only applies to y. Therefore, we set x = [y 0];
68  x.fill(0);
69  x.segment(0,initial_state_.size()) = initial_state_;
70 
71  // Return value (rates of change)
73 }
int dim(void) const
Get the dimensionality of the dynamical system, i.e.
virtual void differentialEquation(const Eigen::Ref< const Eigen::VectorXd > &x, Eigen::Ref< Eigen::VectorXd > xd) const =0
The differential equation which defines the system.

Here is the call graph for this function:

void integrateStart ( const Eigen::VectorXd &  x_init,
Eigen::Ref< Eigen::VectorXd >  x,
Eigen::Ref< Eigen::VectorXd >  xd 
)

Start integrating the system with a new initial state.

Parameters
[in]x_init- The initial state vector
[out]x- The first vector of state variable
[out]xd- The first vector of rates of change of the state variables

Definition at line 54 of file DynamicalSystem.cpp.

55 {
56  set_initial_state(x_init);
57  integrateStart(x,xd);
58 }
virtual void set_initial_state(const Eigen::VectorXd &initial_state)
Mutator function for the initial state of the dynamical system.
virtual void integrateStart(Eigen::Ref< Eigen::VectorXd > x, Eigen::Ref< Eigen::VectorXd > xd) const
Start integrating the system.

Here is the call graph for this function:

void integrateStep ( double  dt,
const Eigen::Ref< const Eigen::VectorXd >  x,
Eigen::Ref< Eigen::VectorXd >  x_updated,
Eigen::Ref< Eigen::VectorXd >  xd_updated 
) const
virtual

Integrate the system one time step.

Parameters
[in]dtDuration of the time step
[in]xCurrent state
[out]x_updatedUpdated state, dt time later.
[out]xd_updatedUpdated rates of change of state, dt time later.
Remarks
x should be of size dim() X 1. This forces you to pre-allocate memory, which speeds things up (and also makes Eigen's Ref functionality easier to deal with).

Definition at line 75 of file DynamicalSystem.cpp.

76 {
77  assert(dt>0.0);
78  // Check size. Leads to faster numerical integration and makes Eigen::Ref easier to deal with
79  assert(x.size()==dim());
80  if (integration_method_ == RUNGE_KUTTA)
81  integrateStepRungeKutta(dt, x, x_updated, xd_updated);
82  else
83  integrateStepEuler(dt, x, x_updated, xd_updated);
84 }
int dim(void) const
Get the dimensionality of the dynamical system, i.e.

Here is the call graph for this function:

virtual std::string toString ( void  ) const
pure virtual

Returns a string representation of the object.

Returns
A string representation of the object.

Implemented in Dmp, ExponentialSystem, SpringDamperSystem, SigmoidSystem, and TimeSystem.

void set_integration_method ( IntegrationMethod  integration_method)
inline

Choose the integration method.

Parameters
[in]integration_methodThe integration method, see DynamicalSystem::IntegrationMethod.

Definition at line 195 of file DynamicalSystem.hpp.

195  {
196  integration_method_ = integration_method;
197  }
int dim ( void  ) const
inline

Get the dimensionality of the dynamical system, i.e.

the length of its state vector.

Returns
Dimensionality of the dynamical system

Definition at line 203 of file DynamicalSystem.hpp.

203  {
204  return dim_;
205  }
int dim_orig ( void  ) const
inline

Get the dimensionality of the dynamical system, i.e.

the length of its output.

2nd order systems are represented as 1st order systems with an expanded state. The SpringDamperSystem for instance is represented as x = [y z], xd = [yd zd]. DynamicalSystem::dim() returns dim(x) = dim([y z]) = 2*dim(y) DynamicalSystem::dim_orig() returns dim(y) = dim()/2

For Dynamical Movement Primitives, dim_orig() may be for instance 3, if the output of the DMP represents x,y,z coordinates. However, dim() will have a much larger dimensionality, because it also contains the variables of all the subsystems (phase system, gating system, etc.)

Returns
Original dimensionality of the dynamical system

Definition at line 221 of file DynamicalSystem.hpp.

221  {
222  return dim_orig_;
223  }
double tau ( void  ) const
inline

Accessor function for the time constant.

Returns
Time constant

Definition at line 229 of file DynamicalSystem.hpp.

229 { return tau_; }
virtual void set_tau ( double  tau)
inlinevirtual

Mutator function for the time constant.

Parameters
[in]tauTime constant

Reimplemented in Dmp, and SigmoidSystem.

Definition at line 235 of file DynamicalSystem.hpp.

235  {
236  assert(tau>0.0);
237  tau_ = tau;
238  }
double tau(void) const
Accessor function for the time constant.

Here is the call graph for this function:

Eigen::VectorXd initial_state ( void  ) const
inline

Accessor function for the initial state of the dynamical system.

Returns
Initial state of the dynamical system.

Definition at line 244 of file DynamicalSystem.hpp.

244 { return initial_state_; }
void initial_state ( Eigen::VectorXd &  initial_state) const
inline

Accessor function for the initial state of the dynamical system.

Parameters
[out]initial_stateInitial state of the dynamical system.

Definition at line 250 of file DynamicalSystem.hpp.

251  {
252  initial_state=initial_state_;
253  }
Eigen::VectorXd initial_state(void) const
Accessor function for the initial state of the dynamical system.
virtual void set_initial_state ( const Eigen::VectorXd &  initial_state)
inlinevirtual

Mutator function for the initial state of the dynamical system.

Parameters
[in]initial_stateInitial state of the dynamical system.

Reimplemented in Dmp, and SigmoidSystem.

Definition at line 258 of file DynamicalSystem.hpp.

258  {
259  assert(initial_state.size()==dim_orig_);
260  initial_state_ = initial_state;
261  }
Eigen::VectorXd initial_state(void) const
Accessor function for the initial state of the dynamical system.

Here is the call graph for this function:

Eigen::VectorXd attractor_state ( void  ) const
inline

Accessor function for the attractor state of the dynamical system.

Returns
Attractor state of the dynamical system.

Definition at line 267 of file DynamicalSystem.hpp.

267 { return attractor_state_; }
void attractor_state ( Eigen::VectorXd &  attractor_state) const
inline

Accessor function for the attractor state of the dynamical system.

Parameters
[out]attractor_stateAttractor state of the dynamical system.

Definition at line 273 of file DynamicalSystem.hpp.

274  {
275  attractor_state=attractor_state_;
276  }
Eigen::VectorXd attractor_state(void) const
Accessor function for the attractor state of the dynamical system.
virtual void set_attractor_state ( const Eigen::Ref< const Eigen::VectorXd > &  attractor_state)
inlinevirtual

Mutator function for the attractor state of the dynamical system.

Parameters
[in]attractor_stateAttractor state of the dynamical system.

Definition at line 281 of file DynamicalSystem.hpp.

281  {
282  assert(attractor_state.size()==dim_orig_);
283  attractor_state_ = attractor_state;
284  }
Eigen::VectorXd attractor_state(void) const
Accessor function for the attractor state of the dynamical system.

Here is the call graph for this function:

std::string name ( void  ) const
inline

Accessor function for the name of the dynamical system.

Returns
Name of the dynamical system.

Definition at line 290 of file DynamicalSystem.hpp.

290 { return name_; }
virtual void set_name ( std::string  name)
inlinevirtual

Mutator function for the name of the dynamical system.

Parameters
[in]nameName of the dynamical system.

Definition at line 295 of file DynamicalSystem.hpp.

295  {
296  name_ = name;
297  }
std::string name(void) const
Accessor function for the name of the dynamical system.

Here is the call graph for this function:

void set_dim ( int  dim)
inlineprotected

Set the dimensionality of the dynamical system, i.e.

the length of its state vector.

Parameters
[in]dimDimensionality of the dynamical system

Definition at line 304 of file DynamicalSystem.hpp.

304  {
305  dim_ = dim;
306  }
int dim(void) const
Get the dimensionality of the dynamical system, i.e.

Here is the call graph for this function:

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Give boost serialization access to private members.

Definition at line 375 of file DynamicalSystem.hpp.

std::ostream& operator<< ( std::ostream &  output,
const DynamicalSystem dyn_sys 
)
friend

Write a DynamicalSystem to an output stream.

Parameters
[in]outputOutput stream to which to write to
[in]dyn_sysDynamical system to write
Returns
Output stream
Remarks
Calls pure virtual function toString(), which must be implemented by all subclasses: http://stackoverflow.com/questions/4571611/virtual-operator

Definition at line 169 of file DynamicalSystem.hpp.

169  {
170  output << dyn_sys.toString();
171  return output;
172  }

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