- 3.0.2 optimal control module.
ControllerDms.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 <Eigen/Dense>
9 
11 
12 
13 namespace ct {
14 namespace optcon {
15 
16 
29 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
30 class ControllerDms : public ct::core::Controller<STATE_DIM, CONTROL_DIM, SCALAR>
31 {
32 public:
33  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
34 
36  typedef typename DIMENSIONS::state_vector_t state_vector_t;
37  typedef typename DIMENSIONS::control_vector_t control_vector_t;
38 
39 
40  ControllerDms() = delete;
41 
42  ControllerDms(std::shared_ptr<SplinerBase<control_vector_t, SCALAR>> controlSpliner, size_t shotIdx)
43  : controlSpliner_(controlSpliner), shotIdx_(shotIdx)
44  {
45  }
46 
47 
48  ControllerDms(const ControllerDms& arg) : controlSpliner_(arg.controlSpliner_), shotIdx_(arg.shotIdx_) {}
49  ~ControllerDms() override = default;
51  {
53  }
54 
55 
56  void computeControl(const state_vector_t& state, const SCALAR& t, control_vector_t& controlAction) override
57  {
58  controlAction = controlSpliner_->evalSpline(t, shotIdx_);
59  assert(controlAction == controlAction);
60  }
61 
62  core::ControlMatrix<CONTROL_DIM, SCALAR> getDerivativeU0(const state_vector_t& state, const SCALAR time) override
63  {
64  return controlSpliner_->splineDerivative_q_i(time, shotIdx_);
65  }
66 
67  core::ControlMatrix<CONTROL_DIM, SCALAR> getDerivativeUf(const state_vector_t& state, const SCALAR time) override
68  {
69  return controlSpliner_->splineDerivative_q_iplus1(time, shotIdx_);
70  }
71 
72 
73 private:
74  std::shared_ptr<SplinerBase<control_vector_t, SCALAR>> controlSpliner_;
75 
76  /* index of the shot to which this controller belongs */
77  const size_t shotIdx_;
78 };
79 
80 } // namespace optcon
81 } // namespace ct
void computeControl(const state_vector_t &state, const SCALAR &t, control_vector_t &controlAction) override
Definition: ControllerDms.h:56
DIMENSIONS::state_vector_t state_vector_t
Definition: ControllerDms.h:36
~ControllerDms() override=default
DMS controller class.
Definition: ControllerDms.h:30
Abstract base class for the control input splining between the DMS shots.
Definition: SplinerBase.h:20
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
core::ControlMatrix< CONTROL_DIM, SCALAR > getDerivativeUf(const state_vector_t &state, const SCALAR time) override
Definition: ControllerDms.h:67
core::ControlMatrix< CONTROL_DIM, SCALAR > getDerivativeU0(const state_vector_t &state, const SCALAR time) override
Definition: ControllerDms.h:62
CppAD::AD< CppAD::cg::CG< double > > SCALAR
Defines basic types used in the DMS algorithm.
Definition: DmsDimensions.h:18
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef DmsDimensions< STATE_DIM, CONTROL_DIM, SCALAR > DIMENSIONS
Definition: ControllerDms.h:35
ControllerDms(const ControllerDms &arg)
Definition: ControllerDms.h:48
DIMENSIONS::control_vector_t control_vector_t
Definition: ControllerDms.h:37
ControllerDms< STATE_DIM, CONTROL_DIM, SCALAR > * clone() const override
Definition: ControllerDms.h:50
ControllerDms(std::shared_ptr< SplinerBase< control_vector_t, SCALAR >> controlSpliner, size_t shotIdx)
Definition: ControllerDms.h:42