- 3.0.2 core module.
ControlledSystem.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 
9 #include "System.h"
10 
14 
15 
16 namespace ct {
17 namespace core {
18 
20 
45 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
46 class ControlledSystem : public System<STATE_DIM, SCALAR>
47 {
48 public:
49  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
50 
52  typedef typename std::shared_ptr<ControlledSystem<STATE_DIM, CONTROL_DIM, SCALAR>> Ptr;
53  typedef typename Base::time_t time_t;
54 
56 
60  : System<STATE_DIM, SCALAR>(type), controller_(nullptr)
61  {
62  }
63 
65 
71  const SYSTEM_TYPE& type = SYSTEM_TYPE::GENERAL)
72  : System<STATE_DIM, SCALAR>(type), controller_(controller)
73  {
74  controlAction_.setZero();
75  }
76 
79  {
80  if (arg.controller_)
81  controller_ = std::shared_ptr<Controller<STATE_DIM, CONTROL_DIM, SCALAR>>(arg.controller_->clone());
82  }
83 
85  virtual ~ControlledSystem() {}
87  virtual ControlledSystem<STATE_DIM, CONTROL_DIM, SCALAR>* clone() const override = 0;
88 
90 
93  void setController(const std::shared_ptr<Controller<STATE_DIM, CONTROL_DIM, SCALAR>>& controller)
94  {
95  controller_ = controller;
96  }
97 
99 
103  void getController(std::shared_ptr<Controller<STATE_DIM, CONTROL_DIM, SCALAR>>& controller) const
104  {
105  controller = controller_;
106  }
107 
109 
112  std::shared_ptr<Controller<STATE_DIM, CONTROL_DIM, SCALAR>> getController() { return controller_; }
114 
126  const time_t& t,
127  StateVector<STATE_DIM, SCALAR>& derivative) override
128  {
129  if (controller_)
130  controller_->computeControl(state, t, controlAction_);
131  else
132  controlAction_.setZero();
133 
134  computeControlledDynamics(state, t, controlAction_, derivative);
135  }
136 
137 
139  const time_t& t,
140  const ControlVector<CONTROL_DIM, SCALAR>& control,
141  StateVector<STATE_DIM, SCALAR>& derivative) = 0;
142 
144 protected:
145  std::shared_ptr<Controller<STATE_DIM, CONTROL_DIM, SCALAR>> controller_;
146 
148 };
149 }
150 }
Base::time_t time_t
Definition: ControlledSystem.h:53
void setController(const std::shared_ptr< Controller< STATE_DIM, CONTROL_DIM, SCALAR >> &controller)
set a new controller
Definition: ControlledSystem.h:93
void getController(std::shared_ptr< Controller< STATE_DIM, CONTROL_DIM, SCALAR >> &controller) const
get the controller instance
Definition: ControlledSystem.h:103
ControlVector< CONTROL_DIM, SCALAR > controlAction_
Definition: ControlledSystem.h:147
virtual ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > * clone() const override=0
deep copy
clear all close all load ct GNMSLog0 mat reformat t
Definition: ControlVector.h:12
virtual void computeControlledDynamics(const StateVector< STATE_DIM, SCALAR > &state, const time_t &t, const ControlVector< CONTROL_DIM, SCALAR > &control, StateVector< STATE_DIM, SCALAR > &derivative)=0
CppAD::AD< CppAD::cg::CG< double > > SCALAR
virtual void computeDynamics(const StateVector< STATE_DIM, SCALAR > &state, const time_t &t, StateVector< STATE_DIM, SCALAR > &derivative) override
compute the dynamics of the system
Definition: ControlledSystem.h:125
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef System< STATE_DIM, SCALAR > Base
Definition: ControlledSystem.h:51
Definition: StateVector.h:12
ControlledSystem(const ControlledSystem &arg)
copy constructor
Definition: ControlledSystem.h:78
std::shared_ptr< Controller< STATE_DIM, CONTROL_DIM, SCALAR > > controller_
the controller instance
Definition: ControlledSystem.h:145
SYSTEM_TYPE
type of system
Definition: System.h:15
any non-specific system
Definition: System.h:17
ControlVector< CONTROL_DIM, SCALAR > getLastControlAction()
Definition: ControlledSystem.h:143
Interface class for a general system described by an ordinary differential equation (ODE) ...
Definition: System.h:38
virtual ~ControlledSystem()
destructor
Definition: ControlledSystem.h:85
ControlledSystem(std::shared_ptr< ct::core::Controller< STATE_DIM, CONTROL_DIM, SCALAR >> controller, const SYSTEM_TYPE &type=SYSTEM_TYPE::GENERAL)
constructor
Definition: ControlledSystem.h:70
std::shared_ptr< Controller< STATE_DIM, CONTROL_DIM, SCALAR > > getController()
get the controller instace
Definition: ControlledSystem.h:112
std::shared_ptr< ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > > Ptr
Definition: ControlledSystem.h:52
A general, non-linear dynamic system with a control input.
Definition: ControlledSystem.h:46
Interface class for all controllers.
Definition: Controller.h:26
ControlledSystem(const SYSTEM_TYPE &type=SYSTEM_TYPE::GENERAL)
default constructor
Definition: ControlledSystem.h:59