- 3.0.2 optimal control module.
SpringLoadedMass.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 
15 {
16 public:
17  static const size_t state_dim = 2; // position, velocity
18  static const size_t control_dim = 1; // force
19 
20  SpringLoadedMass() : core::ControlledSystem<state_dim, control_dim>(core::SYSTEM_TYPE::SECOND_ORDER) {}
22  const core::Time& t,
23  const core::ControlVector<control_dim>& control,
24  core::StateVector<state_dim>& derivative) override
25  {
26  derivative(0) = state(1);
27  derivative(1) = control(0) - kStiffness * state(0) + 0.1; // mass is 1 kg
28  }
29 
30  SpringLoadedMass* clone() const override { return new SpringLoadedMass(); };
31  static constexpr double kStiffness = 10;
32 };
33 
36 {
37 public:
38  static const size_t state_dim = 2; // position, velocity
39  static const size_t control_dim = 1; // force
40 
41  static constexpr double kStiffness = 10;
42 
45 
46 
49  const double t = 0.0) override
50  {
51  A_ << 0, 1, -kStiffness, 0;
52  return A_;
53  }
54 
57  const double t = 0.0) override
58  {
59  B_ << 0, 1;
60  return B_;
61  }
62 
63  SpringLoadedMassLinear* clone() const override { return new SpringLoadedMassLinear(); };
64 };
65 
66 
67 std::shared_ptr<CostFunctionQuadratic<2, 1>> createSpringLoadedMassCostFunction(const core::StateVector<2>& x_final)
68 {
69  Eigen::Matrix<double, 2, 2> Q;
70  Q << 1.0, 0, 0, 1.0;
71 
72  Eigen::Matrix<double, 1, 1> R;
73  R << 1.0;
74 
75  Eigen::Matrix<double, 2, 1> x_nominal = x_final;
76  Eigen::Matrix<double, 1, 1> u_nominal;
77  u_nominal.setZero();
78 
79  Eigen::Matrix<double, 2, 2> Q_final;
80  Q_final << 10.0, 0, 0, 10.0;
81 
82  std::shared_ptr<CostFunctionQuadratic<2, 1>> quadraticCostFunction(
83  new CostFunctionQuadraticSimple<2, 1>(Q, R, x_nominal, u_nominal, x_final, Q_final));
84 
85  return quadraticCostFunction;
86 }
87 }
88 }
89 }
state_matrix_t A_
Definition: SpringLoadedMass.h:43
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: SpringLoadedMass.h:21
std::shared_ptr< CostFunctionQuadratic< 2, 1 > > createSpringLoadedMassCostFunction(const core::StateVector< 2 > &x_final)
Definition: SpringLoadedMass.h:67
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
A simple quadratic cost function.
Definition: CostFunctionQuadraticSimple.hpp:23
static constexpr double kStiffness
Definition: SpringLoadedMass.h:31
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
SECOND_ORDER
static const size_t control_dim
Definition: SpringLoadedMass.h:18
Linear system class for the GNMS unit test.
Definition: SpringLoadedMass.h:35
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: SpringLoadedMass.h:55
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp: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: SpringLoadedMass.h:47
SpringLoadedMass()
Definition: SpringLoadedMass.h:20
SpringLoadedMassLinear * clone() const override
Definition: SpringLoadedMass.h:63
Dynamics class for the GNMS unit test.
Definition: SpringLoadedMass.h:14
static const size_t state_dim
Definition: SpringLoadedMass.h:17
SpringLoadedMass * clone() const override
Definition: SpringLoadedMass.h:30
state_control_matrix_t B_
Definition: SpringLoadedMass.h:44
double Time