state_feedback_1output.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2016 by Horatiu George Todoran <todorangrg@gmail.com> *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above copyright *
10  * notice, this list of conditions and the following disclaimer. *
11  * 2. Redistributions in binary form must reproduce the above copyright *
12  * notice, this list of conditions and the following disclaimer in *
13  * the documentation and/or other materials provided with the *
14  * distribution. *
15  * 3. Neither the name of the copyright holder nor the names of its *
16  * contributors may be used to endorse or promote products derived *
17  * from this software without specific prior written permission. *
18  * *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY *
29  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
30  * POSSIBILITY OF SUCH DAMAGE. *
31  ***************************************************************************/
32 
33 #ifndef STATE_FEEDBACK_1OUTPUT_HPP
34 #define STATE_FEEDBACK_1OUTPUT_HPP
35 
36 #include <float.h>
37 #include <memory>
38 
41 
42 namespace tuw
43 {
70 template <typename InputStateType, typename ParamsType>
71 class StateFeedback1Output : public StateFeedback<InputStateType, InputStateType, double, ParamsType>, public Integrator
72 {
73  // special class member functions
74 public:
75  StateFeedback1Output(std::shared_ptr<ParamsType> _params)
76  : StateFeedback<InputStateType, InputStateType, double, ParamsType>(_params), reloadParamInternal_(false)
77  {
78  this->output_ = std::shared_ptr<double>(new double);
79  }
80 
81 public:
82  virtual ~StateFeedback1Output() = default;
83 
84 public:
86 
87 public:
89 
90 public:
92 
93 public:
95 
96 public:
97  std::shared_ptr<double>& compute(std::shared_ptr<InputStateType>& _xObs, std::shared_ptr<InputStateType>& _xDes,
98  const double& _t) override
99  {
100  desSize_ = _xDes->valueSize();
102  {
104  }
105 
106  for (size_t i = 0; i < outputOrder_; ++i)
107  {
108  xDiffVec_(i) = _xObs->value(i) - _xDes->value(i);
109  }
110  for (size_t i = outputOrder_; i < xDiffSize_; ++i)
111  {
112  xDiffVec_(i) = -_xDes->value(i);
113  }
114 
115  *this->output_ = -kX_.dot(xDiffVec_) - kInt_ * intOutput();
116  if (fabs(*this->output_) < intSaturateVal_)
117  {
118  integrate(xDiffVec_(0) * (_t - t_));
119  }
120  t_ = _t;
121  return this->output_;
122  }
124 private:
126  {
127  reloadParamInternal_ = false;
128  xDiffSize_ = std::min(outputOrder_ + 1, desSize_);
129  xDiffVec_.resize(xDiffSize_);
130  kX_.conservativeResize(xDiffSize_);
131  if (outputOrder_ != xDiffSize_)
132  {
133  kX_(kX_.rows() - 1) = 1;
134  }
135  if (kInt_ == 0)
136  {
138  t_ = 0;
139  }
140  }
141 
142 protected:
143  size_t outputOrder_;
144 protected:
146 protected:
147  double kInt_;
148 protected:
149  Eigen::VectorXd kX_;
150 protected:
152 
153 private:
154  size_t desSize_;
155 
156 private:
157  size_t xDiffSize_;
158 
159 private:
161 
162 private:
163  double t_;
164 
165 private:
166  Eigen::VectorXd xDiffVec_;
167 };
168 }
169 
170 #endif // STATE_FEEDBACK_1OUTPUT_HPP
Eigen::VectorXd kX_
State error gains
double intSaturateVal_
Box constraint. When output outside of it, error integration is not performed.
void reset(const double &_x0)
resets the integrated value and compensation variable.
Definition: integrator.hpp:69
bool reloadParamInternal_
Triggers base class reconfiguration. To be set to true on any parameter change.
size_t outputOrder_
Order of the output variable in the defined state.
StateFeedback1Output & operator=(const StateFeedback1Output &)=default
std::shared_ptr< double > output_
Last computet output state.
double kInt_
gain of the integrated error
virtual ~StateFeedback1Output()=default
const double & intOutput() const
Returns the integrator value.
Definition: integrator.hpp:78
StateFeedback1Output(std::shared_ptr< ParamsType > _params)
Interface for a filter that outputs a desired state given an observed state and a desired state...
Partial implementation of the StateFeedback interface for 1-dimensional output linear state-feedback ...
void reloadParamInternal()
Performs class specific reconfiguration on parameters change.
void integrate(const double &_dx)
Addds a new value to the integrated value.
Definition: integrator.hpp:86
std::shared_ptr< double > & compute(std::shared_ptr< InputStateType > &_xObs, std::shared_ptr< InputStateType > &_xDes, const double &_t) override
Computes the output state at the specified time instant given the observed state and the desired stat...
Minimal class performing numerically stable integration (using the Kahan summation algorithm)...
Definition: integrator.hpp:44


tuw_control
Author(s): George Todoran
autogenerated on Mon Jun 10 2019 15:27:21