- 3.0.2 optimal control module.
DisturbedSystemController-impl.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 
11 template <size_t STATE_DIM, size_t DIST_DIM, size_t CONTROL_DIM, typename SCALAR>
13  std::shared_ptr<ct::core::Controller<STATE_DIM, CONTROL_DIM, SCALAR>> controller)
14  : controller_(controller)
15 {
16 }
17 
18 template <size_t STATE_DIM, size_t DIST_DIM, size_t CONTROL_DIM, typename SCALAR>
20  const DisturbedSystemController& other)
21  : controller_(other.controller_->clone())
22 {
23 }
24 
25 template <size_t STATE_DIM, size_t DIST_DIM, size_t CONTROL_DIM, typename SCALAR>
28 {
29  return new DisturbedSystemController(*this);
30 }
31 
32 template <size_t STATE_DIM, size_t DIST_DIM, size_t CONTROL_DIM, typename SCALAR>
35  const SCALAR& t,
37 {
38  if (!controller_)
39  throw std::runtime_error("DisturbedSystemController: nominal controller not set!");
40 
41  controller_->computeControl(state.template head<STATE_DIM>(), t, controlAction);
42 
43  std::cout << "DisturbedSystemController computed control: " << controlAction.transpose() << std::endl;
44 }
45 
46 template <size_t STATE_DIM, size_t DIST_DIM, size_t CONTROL_DIM, typename SCALAR>
50  const SCALAR time)
51 {
52  if (!controller_)
53  throw std::runtime_error("Controller not set!");
54  return controller_->getDerivativeU0(state.head(STATE_DIM), time);
55 }
56 
57 template <size_t STATE_DIM, size_t DIST_DIM, size_t CONTROL_DIM, typename SCALAR>
61  const SCALAR time)
62 {
63  if (!controller_)
64  throw std::runtime_error("Controller not set!");
65  return controller_->getDerivativeUf(state.head(STATE_DIM), time);
66 }
67 
68 template <size_t STATE_DIM, size_t DIST_DIM, size_t CONTROL_DIM, typename SCALAR>
70  std::shared_ptr<ct::core::Controller<STATE_DIM, CONTROL_DIM, SCALAR>> controller)
71 {
72  controller_ = controller;
73 }
74 
75 } // namespace optcon
76 } // namespace ct
void computeControl(const ct::core::StateVector< AUGMENTED_DIM, SCALAR > &state, const SCALAR &t, ct::core::ControlVector< CONTROL_DIM, SCALAR > &controlAction) override
Implementation of the base computeControl method.
Definition: DisturbedSystemController-impl.h:33
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
ct::core::ControlMatrix< CONTROL_DIM, SCALAR > getDerivativeU0(const ct::core::StateVector< AUGMENTED_DIM, SCALAR > &state, const SCALAR time) override
Implementation of the base getDerivativeU0 method.
Definition: DisturbedSystemController-impl.h:48
CppAD::AD< CppAD::cg::CG< double > > SCALAR
void setController(std::shared_ptr< ct::core::Controller< STATE_DIM, CONTROL_DIM, SCALAR >> controller)
Sets the nominal controller.
Definition: DisturbedSystemController-impl.h:69
ct::core::ControlMatrix< CONTROL_DIM, SCALAR > getDerivativeUf(const ct::core::StateVector< AUGMENTED_DIM, SCALAR > &state, const SCALAR time) override
Implementation of the base getDerivativeUf method.
Definition: DisturbedSystemController-impl.h:59
DisturbedSystemController * clone() const override
Clone method.
Definition: DisturbedSystemController-impl.h:27
DisturbedSystemController(std::shared_ptr< ct::core::Controller< STATE_DIM, CONTROL_DIM, SCALAR >> controller=nullptr)
Constructor. Takes in the nominal controller.
Definition: DisturbedSystemController-impl.h:12
Disturbed controller allows us to augment the controller so that all the CT interfaces and dimensions...
Definition: DisturbedSystemController.h:24