- 3.0.2 optimal control module.
MIMOIntegrator.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
8 namespace ct {
9 namespace optcon {
10 namespace example {
11 
12 
14 
15 template <size_t state_dim, size_t control_dim>
16 class MIMOIntegrator : public core::ControlledSystem<state_dim, control_dim>
17 {
18 public:
21  const core::Time& t,
22  const core::ControlVector<control_dim>& control,
23  core::StateVector<state_dim>& derivative) override
24  {
25  for (size_t i = 0; i < state_dim; i++)
26  {
27  derivative(i) = state(i);
28  }
29  for (size_t j = 0; j < control_dim; j++)
30  {
31  derivative(j) += control(j);
32  }
33  }
34 
35  MIMOIntegrator* clone() const override { return new MIMOIntegrator(); };
36 };
37 
39 template <size_t state_dim, size_t control_dim>
40 class MIMOIntegratorLinear : public core::LinearSystem<state_dim, control_dim>
41 {
42 public:
44  typedef typename BASE::state_matrix_t state_matrix_t;
45  typedef typename BASE::state_control_matrix_t state_control_matrix_t;
46 
47  state_matrix_t A_;
48  state_control_matrix_t B_;
49 
51  {
52  A_.setIdentity();
53  B_.setIdentity();
54  }
55 
56 
57  const state_matrix_t& getDerivativeState(const core::StateVector<state_dim>& x,
59  const double t = 0.0) override
60  {
61  return A_;
62  }
63 
64  const state_control_matrix_t& getDerivativeControl(const core::StateVector<state_dim>& x,
66  const double t = 0.0) override
67  {
68  return B_;
69  }
70 
71  MIMOIntegratorLinear* clone() const override { return new MIMOIntegratorLinear(); };
72 };
73 
74 
75 template <size_t state_dim, size_t control_dim>
76 std::shared_ptr<CostFunctionQuadratic<state_dim, control_dim>> createMIMOIntegratorCostFunction(
77  const core::StateVector<state_dim>& x_final)
78 {
79  Eigen::Matrix<double, state_dim, state_dim> Q;
80  Q.setIdentity();
81 
82  Eigen::Matrix<double, control_dim, control_dim> R;
83  R.setIdentity();
84 
85  Eigen::Matrix<double, state_dim, 1> x_nominal = x_final;
86  Eigen::Matrix<double, control_dim, 1> u_nominal;
87  u_nominal.setZero();
88 
89  Eigen::Matrix<double, state_dim, state_dim> Q_final;
90  Q_final.setIdentity();
91 
92  std::shared_ptr<CostFunctionQuadratic<state_dim, control_dim>> quadraticCostFunction(
93  new CostFunctionQuadraticSimple<state_dim, control_dim>(Q, R, x_nominal, u_nominal, x_final, Q_final));
94 
95  return quadraticCostFunction;
96 }
97 }
98 }
99 }
void computeControlledDynamics(const core::StateVector< state_dim > &state, const core::Time &t, const core::ControlVector< control_dim > &control, core::StateVector< state_dim > &derivative) override
Definition: MIMOIntegrator.h:20
const state_matrix_t & getDerivativeState(const core::StateVector< state_dim > &x, const core::ControlVector< control_dim > &u, const double t=0.0) override
Definition: MIMOIntegrator.h:57
std::shared_ptr< CostFunctionQuadratic< state_dim, control_dim > > createMIMOIntegratorCostFunction(const core::StateVector< state_dim > &x_final)
Definition: MIMOIntegrator.h:76
const state_control_matrix_t & getDerivativeControl(const core::StateVector< state_dim > &x, const core::ControlVector< control_dim > &u, const double t=0.0) override
Definition: MIMOIntegrator.h:64
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
BASE::state_control_matrix_t state_control_matrix_t
Definition: MIMOIntegrator.h:45
MIMOIntegrator()
Definition: MIMOIntegrator.h:19
const size_t state_dim
Definition: ConstraintComparison.h:20
A simple quadratic cost function.
Definition: CostFunctionQuadraticSimple.hpp:23
Linear system class for the GNMS unit test.
Definition: MIMOIntegrator.h:40
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
MIMOIntegratorLinear * clone() const override
Definition: MIMOIntegrator.h:71
state_control_matrix_t B_
Definition: MIMOIntegrator.h:48
SECOND_ORDER
BASE::state_matrix_t state_matrix_t
Definition: MIMOIntegrator.h:44
MIMOIntegrator * clone() const override
Definition: MIMOIntegrator.h:35
for i
Definition: mpc_unittest_plotting.m:14
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
Dynamics class for the GNMS unit test.
Definition: MIMOIntegrator.h:16
state_matrix_t A_
Definition: MIMOIntegrator.h:47
MIMOIntegratorLinear()
Definition: MIMOIntegrator.h:50
const size_t control_dim
Definition: ConstraintComparison.h:21
double Time