25 #include <boost/serialization/export.hpp> 26 #include <boost/archive/text_iarchive.hpp> 27 #include <boost/archive/text_oarchive.hpp> 28 #include <boost/archive/xml_iarchive.hpp> 29 #include <boost/archive/xml_oarchive.hpp> 37 #include <eigen3/Eigen/Core> 43 using namespace Eigen;
47 SpringDamperSystem::SpringDamperSystem(
double tau, Eigen::VectorXd y_init, Eigen::VectorXd y_attr,
double damping_coefficient,
double spring_constant,
double mass, std::string name)
49 damping_coefficient_(damping_coefficient),spring_constant_(spring_constant),mass_(mass)
52 spring_constant_ = damping_coefficient_*damping_coefficient_/4;
69 damping_coefficient_,spring_constant_,mass_,
name());
73 const Eigen::Ref<const Eigen::VectorXd>& x,
74 Eigen::Ref<Eigen::VectorXd> xd)
const 76 ENTERING_REAL_TIME_CRITICAL_CODE
95 zd_ = (-spring_constant_*(y_-y_attr_) - damping_coefficient_*z_)/(mass_*
tau());
97 xd.segment(0,
dim()/2) = yd_;
98 xd.segment(
dim()/2,
dim()/2) = zd_;
100 EXITING_REAL_TIME_CRITICAL_CODE
111 bool caller_expects_transposed = (xs.rows()==
dim() && xs.cols()==T);
123 double omega_0 = sqrt(spring_constant_/mass_)/
tau();
124 double zeta = damping_coefficient_/(2*sqrt(mass_*spring_constant_));
126 cout <<
"WARNING: Spring-damper system is not critically damped, zeta=" << zeta << endl;
138 for (
int i_dim=0; i_dim<dim2; i_dim++)
140 double y0 = y_init[i_dim] - y_attr[i_dim];
142 if (y_init.size()>=
dim())
145 yd0 = y_init[dim2 + i_dim];
154 double B = yd0 + omega_0*y0;
158 VectorXd exp_term = -omega_0*ts;
159 exp_term = exp_term.array().exp();
161 int Y = 0*dim2 + i_dim;
162 int Z = 1*dim2 + i_dim;
164 VectorXd ABts = A + B*ts.array();
169 xs.col(Y) = y_attr(i_dim) + (( ABts.array()))*exp_term.array();
172 xds.col(Y) = ((B - omega_0* ABts.array()))*exp_term.array();
175 VectorXd ydds = (-omega_0*(2*B - omega_0* ABts.array()))*exp_term.array();
178 xs.col(Z) = xds.col(Y)*
tau();
179 xds.col(Z) = ydds*
tau();
182 if (caller_expects_transposed)
184 xs.transposeInPlace();
185 xds.transposeInPlace();
double tau(void) const
Accessor function for the time constant.
int dim_orig(void) const
Get the dimensionality of the dynamical system, i.e.
SpringDamperSystem class header file.
DynamicalSystem * clone(void) const
Return a pointer to a deep copy of the DynamicalSystem object.
void analyticalSolution(const Eigen::VectorXd &ts, Eigen::MatrixXd &xs, Eigen::MatrixXd &xds) const
Return analytical solution of the system at certain times.
Eigen::VectorXd initial_state(void) const
Accessor function for the initial state of the dynamical system.
int dim(void) const
Get the dimensionality of the dynamical system, i.e.
BOOST_CLASS_EXPORT_IMPLEMENT(DmpBbo::SpringDamperSystem)
For boost::serialization.
std::string toString(void) const
Returns a string representation of the object.
#define RETURN_STRING_FROM_BOOST_SERIALIZATION_XML(name)
Macro to convert the boost XML serialization of an object into a string.
std::string name(void) const
Accessor function for the name of the dynamical system.
void differentialEquation(const Eigen::Ref< const Eigen::VectorXd > &x, Eigen::Ref< Eigen::VectorXd > xd) const
The differential equation which defines the system.
Interface for implementing dynamical systems.
Eigen::VectorXd attractor_state(void) const
Accessor function for the attractor state of the dynamical system.
Header file to generate strings from boost serialized files.
Dynamical System modelling the evolution of a spring-damper system: .
double const CRITICALLY_DAMPED
Value indicating that the spring constant should be set such that the spring damper system is critica...
~SpringDamperSystem(void)
Destructor.
Header file for serialization of Eigen matrices.