25 #ifndef SRC_SYSTEMS_INCLUDE_CORBO_SYSTEMS_BENCHMARK_LINEAR_BENCHMARK_SYSTEMS_H_ 26 #define SRC_SYSTEMS_INCLUDE_CORBO_SYSTEMS_BENCHMARK_LINEAR_BENCHMARK_SYSTEMS_H_ 59 Ptr getInstance()
const override {
return std::make_shared<SerialIntegratorSystem>(); }
64 bool isLinear()
const override {
return true; }
75 assert(x.rows() == f.rows() &&
"SerialIntegratorSystem::dynamics(): x and f are not of the same size, do not forget to pre-allocate f.");
77 const int num_integrator_states =
_dimension - 1;
79 if (
_dimension > 1) f.head(num_integrator_states) = x.segment(1, num_integrator_states);
95 #ifdef MESSAGE_SUPPORT 97 void toMessage(messages::SystemDynamics& message)
const override 99 SystemDynamicsInterface::toMessage(message);
101 message.mutable_serial_integrators()->set_dimension(
_dimension);
102 message.mutable_serial_integrators()->set_time_constant(
_time_constant);
105 void fromMessage(
const messages::SystemDynamics& message, std::stringstream* issues)
override 107 SystemDynamicsInterface::fromMessage(message, issues);
109 _dimension = message.serial_integrators().dimension();
129 Ptr getInstance()
const override {
return std::make_shared<ParallelIntegratorSystem>(); }
145 assert(x.rows() == f.rows() &&
"ParallelIntegratorSystem::dynamics(): x and f are not of the same size, do not forget to pre-allocate f.");
161 #ifdef MESSAGE_SUPPORT 163 void toMessage(messages::SystemDynamics& message)
const override 165 SystemDynamicsInterface::toMessage(message);
167 message.mutable_parallel_integrators()->set_dimension(
_dimension);
168 message.mutable_parallel_integrators()->set_time_constant(
_time_constant);
171 void fromMessage(
const messages::SystemDynamics& message, std::stringstream* issues)
override 173 SystemDynamicsInterface::fromMessage(message, issues);
175 _dimension = message.parallel_integrators().dimension();
193 Ptr getInstance()
const override {
return std::make_shared<LinearStateSpaceModel>(); }
210 assert(x.size() == f.size() &&
"LinearStateSpaceModel::dynamics(): x and f are not of the same size, do not forget to pre-allocate f.");
224 #ifdef MESSAGE_SUPPORT 226 void toMessage(messages::SystemDynamics& message)
const override 228 SystemDynamicsInterface::toMessage(message);
230 messages::LinearStateSpaceModel* msg = message.mutable_linear_state_space();
233 msg->mutable_a()->Resize(_A.size(), 0);
237 msg->mutable_b()->Resize(_B.size(), 0);
241 void fromMessage(
const messages::SystemDynamics& message, std::stringstream* issues)
override 243 SystemDynamicsInterface::fromMessage(message, issues);
245 const messages::LinearStateSpaceModel& msg = message.linear_state_space();
247 if (msg.a_size() == 0 || msg.b_size() == 0)
249 *issues <<
"LinearStateSpaceModel: Please specify a proper system matrix A and input matrix B.\n";
254 int numel_a = msg.a_size();
257 *issues <<
"LinearStateSpaceModel: system matrix A is not square.\n";
264 int numel_b = msg.b_size();
266 double q = numel_b / p;
267 if (p * q != numel_b)
269 *issues <<
"LinearStateSpaceModel: input matrix B is not a valid matrix (number of columns must be " << p <<
").\n";
277 Eigen::MatrixXd _A = Eigen::MatrixXd::Zero(1, 1);
278 Eigen::MatrixXd _B = Eigen::MatrixXd::Zero(1, 1);
305 Ptr getInstance()
const override {
return std::make_shared<DoubleIntegratorDiscreteTime>(); }
320 assert(x.rows() == 2);
321 assert(x.rows() == f.rows() &&
"IntegratorSystemCont::dynamics(): x and f are not of the same size, do not forget to pre-allocate f.");
323 f[0] = x[0] + _dt * x[1] + 0.5 * _dt * _dt * u[0];
324 f[1] = x[1] + _dt * u[0];
328 const double&
getDt()
const {
return _dt; }
332 #ifdef MESSAGE_SUPPORT 334 void toMessage(messages::SystemDynamics& message)
const override 336 SystemDynamicsInterface::toMessage(message);
337 message.mutable_double_integrator_discrete_time()->set_dt(_dt);
340 void fromMessage(
const messages::SystemDynamics& message, std::stringstream* issue)
override 342 SystemDynamicsInterface::fromMessage(message, issue);
343 _dt = message.double_integrator_discrete_time().dt();
354 #endif // SRC_SYSTEMS_INCLUDE_CORBO_SYSTEMS_BENCHMARK_LINEAR_BENCHMARK_SYSTEMS_H_ System dynamics for a second order integrator (discrete-time)
bool isLinear() const override
Check if the system dynamics are linear.
int getStateDimension() const override
Return state dimension (x)
void dynamics(const Eigen::Ref< const StateVector > &x, const Eigen::Ref< const ControlVector > &u, Eigen::Ref< StateVector > f) const override
Evaluate the system dynamics equation.
Ptr getInstance() const override
Return a newly created shared instance of the implemented class.
int getStateDimension() const override
Return state dimension (x)
LinearStateSpaceModel()
Default constructor (do not forget to set the dimension)
ParallelIntegratorSystem(int dimension)
Construct ingerator system with given order/dimension.
Ptr getInstance() const override
Return a newly created shared instance of the implemented class.
const int & getDimension() const
Get current integrator chain dimension / order of the system.
A matrix or vector expression mapping an existing array of data.
void dynamics(const Eigen::Ref< const StateVector > &x, const Eigen::Ref< const ControlVector > &u, Eigen::Ref< StateVector > f) const override
Evaluate the system dynamics equation.
bool isLinear() const override
Check if the system dynamics are linear.
void setTimeConstant(double time_constant)
Set Time constant T of the integrator.
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
void setParameters(const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::MatrixXd > &B)
Set Time constant T of the integrator.
bool is_square(const Eigen::MatrixBase< Derived > &matrix)
Determine if a given matrix is square.
const double & getTimeConstant() const
Get time constant T of the integrator.
bool isLinear() const override
Check if the system dynamics are linear.
SerialIntegratorSystem()
Default constructor (do not forget to set the dimension)
int getInputDimension() const override
Return the plant input dimension (u)
MatrixType A(a, *n, *n, *lda)
void setDimension(int dim)
Set integrator dimension (p >= 1)
bool isContinuousTime() const override
Check if the system dynamics are defined in continuous-time.
int getInputDimension() const override
Return the plant input dimension (u)
int getInputDimension() const override
Return the plant input dimension (u)
SerialIntegratorSystem(int dimension)
Construct ingerator system with given order/dimension.
int getStateDimension() const override
Return state dimension (x)
DoubleIntegratorDiscreteTime()
Default constructor.
const int & getDimension() const
Get current integrator chain dimension / order of the system.
void dynamics(const Eigen::Ref< const StateVector > &x, const Eigen::Ref< const ControlVector > &u, Eigen::Ref< StateVector > f) const override
Evaluate the system dynamics equation.
EIGEN_DEVICE_FUNC const Scalar & q
void setDimension(int dim)
Set integrator dimension (p >= 1)
Ptr getInstance() const override
Return a newly created shared instance of the implemented class.
void setTimeConstant(double time_constant)
Set Time constant T of the integrator.
A matrix or vector expression mapping an existing expression.
const double & getTimeConstant() const
Get time constant T of the integrator.
bool isContinuousTime() const override
Check if the system dynamics are defined in continuous-time.
void dynamics(const Eigen::Ref< const StateVector > &x, const Eigen::Ref< const ControlVector > &u, Eigen::Ref< StateVector > f) const override
Evaluate the system dynamics equation.
void setDt(double dt)
Set sampling time dt.
Interface class for system dynamic equations.
bool isContinuousTime() const override
Check if the system dynamics are defined in continuous-time.
const double & getDt() const
Get current sampling time dt.
bool isContinuousTime() const override
Check if the system dynamics are defined in continuous-time.
bool isLinear() const override
Check if the system dynamics are linear.
MatrixType B(b, *n, *nrhs, *ldb)
The matrix class, also used for vectors and row-vectors.
int getInputDimension() const override
Return the plant input dimension (u)
System dynamics for a series of integrators (continuous-time)
int getStateDimension() const override
Return state dimension (x)
std::shared_ptr< SystemDynamicsInterface > Ptr
#define FACTORY_REGISTER_SYSTEM_DYNAMICS(type)
Ptr getInstance() const override
Return a newly created shared instance of the implemented class.
ParallelIntegratorSystem()
Default constructor (do not forget to set the dimension)