- 3.0.2 optimal control module.
ZeroOrderHoldSpliner.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 
10 
11 namespace ct {
12 namespace optcon {
13 
21 template <class T, typename SCALAR = double>
22 class ZeroOrderHoldSpliner : public SplinerBase<T, SCALAR>
23 {
24 public:
25  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26 
27  typedef T vector_t;
28  typedef Eigen::Matrix<SCALAR, T::DIM, T::DIM> matrix_t;
29  typedef std::vector<vector_t, Eigen::aligned_allocator<vector_t>> vector_array_t;
30 
31  ZeroOrderHoldSpliner() = delete;
32 
38  ZeroOrderHoldSpliner(std::shared_ptr<tpl::TimeGrid<SCALAR>> grid) : timeGrid_(grid) {}
39  ~ZeroOrderHoldSpliner() override = default;
40  void computeSpline(const vector_array_t& points) override { zOholds_ = points; }
41  // evaluate spline and return vector at interpolation time
42  vector_t evalSpline(const SCALAR time, const size_t shotIdx) override
43  {
44  assert(shotIdx < zOholds_.size());
45  assert(zOholds_[shotIdx] == zOholds_[shotIdx]);
46  return zOholds_[shotIdx];
47  }
48 
49  vector_t splineDerivative_t(const SCALAR time, const size_t shotIdx) const override { return vector_t::Zero(); }
50  vector_t splineDerivative_h_i(const SCALAR time, const size_t shotIdx) const override { return vector_t::Zero(); }
51  matrix_t splineDerivative_q_i(const SCALAR time, const size_t shotIdx) const override
52  {
53  return matrix_t::Identity();
54  }
55 
56  matrix_t splineDerivative_q_iplus1(const SCALAR time, const size_t shotIdx) const override
57  {
58  return matrix_t::Zero();
59  }
60 
61 
62 private:
63  // zero order hold variables
64  vector_array_t zOholds_;
65 
66  std::shared_ptr<tpl::TimeGrid<SCALAR>> timeGrid_;
67 };
68 
69 } // namespace optcon
70 } // namespace ct
std::vector< vector_t, Eigen::aligned_allocator< vector_t > > vector_array_t
Definition: ZeroOrderHoldSpliner.h:29
void computeSpline(const vector_array_t &points) override
Updates the vector on the shots.
Definition: ZeroOrderHoldSpliner.h:40
void grid(bool flag)
matrix_t splineDerivative_q_iplus1(const SCALAR time, const size_t shotIdx) const override
Returns the spline derivative with respect to the control input at shot i+1.
Definition: ZeroOrderHoldSpliner.h:56
Eigen::Matrix< SCALAR, T::DIM, T::DIM > matrix_t
Definition: ZeroOrderHoldSpliner.h:28
The spline implementation for the zero order hold spliner.
Definition: ZeroOrderHoldSpliner.h:22
Abstract base class for the control input splining between the DMS shots.
Definition: SplinerBase.h:20
matrix_t splineDerivative_q_i(const SCALAR time, const size_t shotIdx) const override
Return the spline derivative with respect to the control input at shot i.
Definition: ZeroOrderHoldSpliner.h:51
ZeroOrderHoldSpliner(std::shared_ptr< tpl::TimeGrid< SCALAR >> grid)
Custom constructor.
Definition: ZeroOrderHoldSpliner.h:38
vector_t evalSpline(const SCALAR time, const size_t shotIdx) override
Depending on the spline type, this method evaluates the control input between the shots...
Definition: ZeroOrderHoldSpliner.h:42
CppAD::AD< CppAD::cg::CG< double > > SCALAR
vector_t splineDerivative_h_i(const SCALAR time, const size_t shotIdx) const override
Returns the spline derivatives with respect to the time segment between the shots.
Definition: ZeroOrderHoldSpliner.h:50
Definition: TimeGrid.h:27
vector_t splineDerivative_t(const SCALAR time, const size_t shotIdx) const override
Returns the spline derivatives with respect to time.
Definition: ZeroOrderHoldSpliner.h:49
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef T vector_t
Definition: ZeroOrderHoldSpliner.h:27
~ZeroOrderHoldSpliner() override=default