- 3.0.2 core module.
TestDiscreteNonlinearSystem.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>
19 {
20 public:
22  static const size_t STATE_DIM = 2;
23  static const size_t CONTROL_DIM = 1;
24 
27  typedef typename Base::time_t time_t;
28 
29  TestDiscreteNonlinearSystem() = delete;
30 
31  // constructor directly using frequency and damping coefficients
32  TestDiscreteNonlinearSystem(SCALAR rate, std::shared_ptr<DiscreteController<2, 1, SCALAR>> controller = nullptr)
33  : Base(controller, SYSTEM_TYPE::GENERAL), rate_(rate)
34  {
35  }
36 
37  //copy constructor
38  TestDiscreteNonlinearSystem(const TestDiscreteNonlinearSystem& arg) : Base(arg), rate_(arg.rate_) {}
40  TestDiscreteNonlinearSystem* clone() const override { return new TestDiscreteNonlinearSystem(*this); }
41  virtual void propagateControlledDynamics(const state_vector_t& state,
42  const time_t n,
43  const control_vector_t& control,
44  state_vector_t& stateNext) override
45  {
46  // this is pretty much random
47  stateNext(0) = state(0) + rate_ * state(0) * control(0);
48  stateNext(1) = state(0) * state(1) * state(1);
49  }
50 
51 private:
52  SCALAR rate_;
53 };
54 } // namespace tpl
55 
57 
58 } // namespace core
59 } // namespace ct
TestDiscreteNonlinearSystem(SCALAR rate, std::shared_ptr< DiscreteController< 2, 1, SCALAR >> controller=nullptr)
Definition: TestDiscreteNonlinearSystem.h:32
static const size_t CONTROL_DIM
Definition: TestDiscreteNonlinearSystem.h:23
virtual void propagateControlledDynamics(const state_vector_t &state, const time_t n, const control_vector_t &control, state_vector_t &stateNext) override
propagates the controlled system dynamics forward by one step
Definition: TestDiscreteNonlinearSystem.h:41
Definition: ControlVector.h:12
virtual ~TestDiscreteNonlinearSystem()
Definition: TestDiscreteNonlinearSystem.h:39
A general, non-linear discrete dynamic system with a control input.
Definition: DiscreteControlledSystem.h:40
Base::control_vector_t control_vector_t
Definition: TestDiscreteNonlinearSystem.h:26
CppAD::AD< CppAD::cg::CG< double > > SCALAR
constexpr size_t n
Definition: MatrixInversionTest.cpp:14
Definition: StateVector.h:12
Interface class for all controllers.
Definition: DiscreteController.h:22
Definition: TestDiscreteNonlinearSystem.h:18
TestDiscreteNonlinearSystem * clone() const override
deep copy
Definition: TestDiscreteNonlinearSystem.h:40
SYSTEM_TYPE
type of system
Definition: System.h:15
Base::state_vector_t state_vector_t
Definition: TestDiscreteNonlinearSystem.h:25
Base::time_t time_t
Definition: TestDiscreteNonlinearSystem.h:27
any non-specific system
Definition: System.h:17
DiscreteControlledSystem< 2, 1, SCALAR > Base
Definition: TestDiscreteNonlinearSystem.h:21
Base::time_t time_t
Definition: DiscreteControlledSystem.h:51
TestDiscreteNonlinearSystem(const TestDiscreteNonlinearSystem &arg)
Definition: TestDiscreteNonlinearSystem.h:38
static const size_t STATE_DIM
Definition: TestDiscreteNonlinearSystem.h:22