- 3.0.2 optimal control module.
DiehlSystem.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 
19 class DiehlSystem : public core::ControlledSystem<1, 1>
21 {
22 public:
23  static const int state_dim = 1;
24  static const int control_dim = 1;
25 
28  const core::Time& t,
29  const core::ControlVector<1>& control,
30  core::StateVector<1>& derivative) override
31  {
32  derivative(0) = (1.0 + state(0)) * state(0) + control(0) + 0.1;
33  }
34 
35  DiehlSystem* clone() const override { return new DiehlSystem(); };
36 };
37 
40 {
41 public:
42  static const int state_dim = 1;
43  static const int control_dim = 1;
44 
46  state_control_matrix_t B_;
47 
48 
51  const double t = 0.0) override
52  {
53  A_ << 1 + 2 * x(0);
54  return A_;
55  }
56 
57  const state_control_matrix_t& getDerivativeControl(const core::StateVector<1>& x,
59  const double t = 0.0) override
60  {
61  B_ << 1;
62  return B_;
63  }
64 
65  DiehlSystemLinear* clone() const override { return new DiehlSystemLinear(); }
66 };
67 
68 
70 std::shared_ptr<CostFunctionQuadratic<1, 1>> createDiehlCostFunction(const core::StateVector<1>& x_final)
71 {
72  Eigen::Matrix<double, 1, 1> Q;
73  Q << 1.0;
74 
75  Eigen::Matrix<double, 1, 1> R;
76  R << 1.0;
77 
78  Eigen::Matrix<double, 1, 1> x_nominal = x_final;
79  Eigen::Matrix<double, 1, 1> u_nominal;
80  u_nominal.setConstant(-0.1); //Eigen::Matrix<double, 1, 1>::Zero();
81 
82  Eigen::Matrix<double, 1, 1> Q_final;
83  Q_final << 10.0;
84 
85  std::shared_ptr<CostFunctionQuadratic<1, 1>> quadraticCostFunction(
86  new CostFunctionQuadraticSimple<1, 1>(Q, R, x_nominal, u_nominal, x_final, Q_final));
87 
88  return quadraticCostFunction;
89 }
90 }
91 }
92 }
static const int control_dim
Definition: DiehlSystem.h:24
DiehlSystem * clone() const override
Definition: DiehlSystem.h:35
DiehlSystemLinear * clone() const override
Definition: DiehlSystem.h:65
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
state_matrix_t A_
Definition: DiehlSystem.h:45
Linear system class for the Diehl system.
Definition: DiehlSystem.h:39
A simple quadratic cost function.
Definition: CostFunctionQuadraticSimple.hpp:23
DiehlSystem()
Definition: DiehlSystem.h:26
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
SECOND_ORDER
const state_control_matrix_t & getDerivativeControl(const core::StateVector< 1 > &x, const core::ControlVector< 1 > &u, const double t=0.0) override
Definition: DiehlSystem.h:57
static const int state_dim
Definition: DiehlSystem.h:23
Dynamics class for the Diehl system.
Definition: DiehlSystem.h:20
void computeControlledDynamics(const core::StateVector< 1 > &state, const core::Time &t, const core::ControlVector< 1 > &control, core::StateVector< 1 > &derivative) override
Definition: DiehlSystem.h:27
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
const state_matrix_t & getDerivativeState(const core::StateVector< 1 > &x, const core::ControlVector< 1 > &u, const double t=0.0) override
Definition: DiehlSystem.h:49
state_control_matrix_t B_
Definition: DiehlSystem.h:46
std::shared_ptr< CostFunctionQuadratic< 1, 1 > > createDiehlCostFunction(const core::StateVector< 1 > &x_final)
create a cost function of appropriate Dimensions for the Diehl system
Definition: DiehlSystem.h:70
double Time