- 3.0.2 core module.
StateFeedbackController-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 namespace ct {
7 namespace core {
8 
9 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
12  : ContinuousBase(), DiscreteBase(), x_ref_(other.x_ref_), uff_(other.uff_), K_(other.K_)
13 {
14 }
15 
16 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
21  const SCALAR deltaT,
22  const SCALAR t0,
23  const InterpolationType& intType)
24  : x_ref_(x_ref, deltaT, t0, intType), uff_(uff, deltaT, t0, intType), K_(K, deltaT, t0, intType)
25 {
26 }
27 
28 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
30  const SCALAR& t,
31  control_vector_t& controlAction)
32 {
33  controlAction = uff_.eval(t) + K_.eval(t) * (state - x_ref_.eval(t));
34 }
35 
36 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
38  const int n,
39  control_vector_t& controlAction)
40 {
41  controlAction = uff_[n] + K_[n] * (state - x_ref_[n]);
42 }
43 
44 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
48  const tpl::TimeArray<SCALAR>& t)
49 {
50  tpl::TimeArray<SCALAR> tshort = t;
51  tshort.pop_back(); // todo: the copying here is not optimal
52 
53  if (K.size() != tshort.size())
54  throw std::runtime_error("StateFeedbackController.h : K.size() != tshort.size()");
55  if (uff.size() != tshort.size())
56  throw std::runtime_error("StateFeedbackController.h : uff.size() != tshort.size()");
57  if (x_ref.size() != t.size())
58  throw std::runtime_error("StateFeedbackController.h : x_ref.size() != t.size()");
59 
60  x_ref_.setData(x_ref), x_ref_.setTime(t), uff_.setData(uff);
61  uff_.setTime(tshort);
62  K_.setData(K);
63  K_.setTime(tshort);
64 }
65 
66 
67 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
70 {
72 }
73 
74 
75 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
78 {
79  return x_ref_.getDataArray();
80 }
81 
82 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
85 {
86  return uff_.getDataArray();
87 }
88 
89 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
92 {
93  return K_.getDataArray();
94 }
95 
96 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
98 {
99  return x_ref_.getTimeArray();
100 }
101 
102 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
105 {
106  return x_ref_;
107 }
108 
109 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
112 {
113  return x_ref_;
114 }
115 
116 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
119 {
120  return uff_;
121 }
122 
123 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
126 {
127  return uff_;
128 }
129 
130 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
133 {
134  return K_;
135 }
136 
137 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
140 {
141  return K_;
142 }
143 
144 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
148 {
149  u_traj.clear();
150 
151  for (size_t i = 0; i < x_traj.size() - 1; i++)
152  {
153  u_traj.push_back(uff_[i] + K_[i] * (x_traj[i] - x_ref_[i]), x_traj.getTimeFromIndex(i), true);
154  }
155 }
156 
157 } // namespace core
158 } // namespace ct
StateTrajectory< STATE_DIM, SCALAR > x_ref_
Definition: StateFeedbackController.h:153
void clear()
Clear the trajectory.
Definition: DiscreteTrajectoryBase.h:211
An discrete array (vector) of a particular data type.
Definition: DiscreteArray.h:22
const tpl::TimeArray< SCALAR > & time() const
get time array
Definition: StateFeedbackController-impl.h:97
StateTrajectory< STATE_DIM, SCALAR > & getReferenceStateTrajectory()
get a reference to the feedforward trajectory
Definition: StateFeedbackController-impl.h:104
StateFeedbackController()
default constructor
Definition: StateFeedbackController.h:56
const DiscreteArray< FeedbackMatrix< STATE_DIM, CONTROL_DIM, SCALAR > > & K() const
get feedback array (without timings)
Definition: StateFeedbackController-impl.h:91
size_t size() const
returns the size of the trajectory
Definition: DiscreteTrajectoryBase.h:146
const DiscreteArray< state_vector_t > & x_ref() const
get reference state vector array (without timings)
Definition: StateFeedbackController-impl.h:77
FeedbackTrajectory< STATE_DIM, CONTROL_DIM, SCALAR > & getFeedbackTrajectory()
get a reference to the feedback trajectory
Definition: StateFeedbackController-impl.h:132
Definition: ControlVector.h:12
CppAD::AD< CppAD::cg::CG< double > > SCALAR
virtual void computeControl(const state_vector_t &state, const SCALAR &t, control_vector_t &controlAction) override
computes the control action in the continuous case
Definition: StateFeedbackController-impl.h:29
InterpolationType
Definition: Interpolation.h:14
A linear state feedback controller.
Definition: StateFeedbackController.h:39
A discrete, timed trajectory with interpolation.
Definition: DiscreteTrajectoryBase.h:31
constexpr size_t n
Definition: MatrixInversionTest.cpp:14
const DiscreteArray< control_vector_t > & uff() const
get feedforward array (without timings)
Definition: StateFeedbackController-impl.h:84
Interface class for all controllers.
Definition: DiscreteController.h:22
for i
const SCALAR & getTimeFromIndex(const size_t &ind) const
get the time stamp at a certain index
Definition: DiscreteTrajectoryBase.h:243
An array in time.
Definition: TimeArray.h:22
ControlTrajectory< CONTROL_DIM, SCALAR > uff_
state reference trajectory
Definition: StateFeedbackController.h:154
void update(const DiscreteArray< state_vector_t > &x_ref, const DiscreteArray< control_vector_t > &uff, const DiscreteArray< FeedbackMatrix< STATE_DIM, CONTROL_DIM, SCALAR >> &K, const tpl::TimeArray< SCALAR > &t)
updates the controller
Definition: StateFeedbackController-impl.h:45
void extractControlTrajectory(const StateTrajectory< STATE_DIM, SCALAR > &x_traj, ControlTrajectory< CONTROL_DIM, SCALAR > &u_traj)
extracts a physically meaningful control trajectory from the given state-feedback law and a reference...
Definition: StateFeedbackController-impl.h:145
StateFeedbackController< STATE_DIM, CONTROL_DIM, SCALAR > * clone() const override
deep cloning
Definition: StateFeedbackController-impl.h:69
void push_back(const T &data, const SCALAR &time, const bool timeIsAbsolute)
Add a data and time point at the end.
Definition: DiscreteTrajectoryBase.h:181
Definition: FeedbackMatrix.h:12
FeedbackTrajectory< STATE_DIM, CONTROL_DIM, SCALAR > K_
feedforward control trajectory
Definition: StateFeedbackController.h:155
DiscreteBase::state_vector_t state_vector_t
Definition: StateFeedbackController.h:48
ControlTrajectory< CONTROL_DIM, SCALAR > & getFeedforwardTrajectory()
get a reference to the feedforward trajectory
Definition: StateFeedbackController-impl.h:118