- 3.0.2 core module.
TestNonlinearSystem.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 #include <cmath>
9 #include <memory>
10 #include <iostream>
11 
12 namespace ct {
13 namespace core {
14 
15 namespace tpl {
16 
17 template <typename SCALAR>
18 class TestNonlinearSystem : public ControlledSystem<2, 1, SCALAR>
19 {
20 public:
21  static const size_t STATE_DIM = 2;
22  static const size_t CONTROL_DIM = 1;
23 
26 
27  TestNonlinearSystem() = delete;
28 
29  // constructor directly using frequency and damping coefficients
30  TestNonlinearSystem(SCALAR w_n, std::shared_ptr<Controller<2, 1, SCALAR>> controller = nullptr)
31  : ControlledSystem<2, 1, SCALAR>(controller, SYSTEM_TYPE::GENERAL), w_n_(w_n)
32  {
33  }
34 
35  TestNonlinearSystem(const TestNonlinearSystem& arg) : ControlledSystem<2, 1, SCALAR>(arg), w_n_(arg.w_n_) {}
36  virtual ~TestNonlinearSystem() {}
37  TestNonlinearSystem* clone() const override { return new TestNonlinearSystem(*this); }
39  const SCALAR& t,
40  const control_vector_t& control,
41  state_vector_t& derivative) override
42  {
43  //this is pretty much random
44  derivative(0) = state(1) * state(0) + state(1) * control(0);
45  derivative(1) = w_n_ * control(0) - 2.0 * w_n_ * state(1) - 3.0 * w_n_ * state(1) * control(0);
46  }
47 
48 private:
49  SCALAR w_n_;
50 };
51 }
52 
54 
55 } // namespace core
56 } // namespace ct
virtual void computeControlledDynamics(const StateVector< 2, SCALAR > &state, const SCALAR &t, const control_vector_t &control, state_vector_t &derivative) override
Definition: TestNonlinearSystem.h:38
static const size_t CONTROL_DIM
Definition: TestNonlinearSystem.h:22
TestNonlinearSystem(const TestNonlinearSystem &arg)
Definition: TestNonlinearSystem.h:35
StateVector< 2, SCALAR > state_vector_t
Definition: TestNonlinearSystem.h:25
Definition: ControlVector.h:12
CppAD::AD< CppAD::cg::CG< double > > SCALAR
TestNonlinearSystem * clone() const override
deep copy
Definition: TestNonlinearSystem.h:37
static const size_t STATE_DIM
Definition: TestNonlinearSystem.h:21
ControlVector< 1, SCALAR > control_vector_t
Definition: TestNonlinearSystem.h:24
Definition: TestNonlinearSystem.h:18
SYSTEM_TYPE
type of system
Definition: System.h:15
any non-specific system
Definition: System.h:17
TestNonlinearSystem(SCALAR w_n, std::shared_ptr< Controller< 2, 1, SCALAR >> controller=nullptr)
Definition: TestNonlinearSystem.h:30
virtual ~TestNonlinearSystem()
Definition: TestNonlinearSystem.h:36
A general, non-linear dynamic system with a control input.
Definition: ControlledSystem.h:46
Interface class for all controllers.
Definition: Controller.h:26