agv_diff_drive_v_w.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2017 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 AGV_DIFF_DRIVE_V_W_HPP
34 #define AGV_DIFF_DRIVE_V_W_HPP
35 
38 #include <tuw_control/utils.h>
39 
40 namespace tuw
41 {
42 namespace DiffDrive
43 {
44 // Defining the system state
45 
55 template <class TNumType, class TLeafType>
56 class StateNmVW : public StateMapArray<TNumType, TLeafType, 2>
57 {
58 public:
60 
61 public:
62  auto& x()
63  {
64  return this->template sub<0>();
65  }
66 
67 public:
68  const auto& x() const
69  {
70  return this->template sub<0>();
71  }
72 
73 public:
74  auto& y()
75  {
76  return this->template sub<1>();
77  }
78 
79 public:
80  const auto& y() const
81  {
82  return this->template sub<1>();
83  }
84 
85 public:
86  auto& state()
87  {
88  return *this;
89  }
90 
91 public:
92  const auto& state() const
93  {
94  return *this;
95  }
96 };
97 
107 template <class TNumType, class TLeafType>
109 {
110 public:
112 
113 public:
114  auto& JPow()
115  {
116  return this->template sub<0>();
117  }
118 
119 public:
120  const auto& JPow() const
121  {
122  return this->template sub<0>();
123  }
124 
125 public:
126  auto& JInt()
127  {
128  return this->template sub<1>();
129  }
130 
131 public:
132  const auto& JInt() const
133  {
134  return this->template sub<1>();
135  }
136 
137 public:
138  auto& x()
139  {
140  return this->template sub<2>();
141  }
142 
143 public:
144  const auto& x() const
145  {
146  return this->template sub<2>();
147  }
148 
149 public:
150  auto& y()
151  {
152  return this->template sub<3>();
153  }
154 
155 public:
156  const auto& y() const
157  {
158  return this->template sub<3>();
159  }
160 
161 public:
162  auto& state()
163  {
164  return *this;
165  }
166 
167 public:
168  const auto& state() const
169  {
170  return *this;
171  }
172 };
173 
183 template <class TNumType, class TLeafType>
185 {
186 public:
188 
189 public:
190  auto& theta()
191  {
192  return this->template sub<0>();
193  }
194 
195 public:
196  const auto& theta() const
197  {
198  return this->template sub<0>();
199  }
200 
201 public:
202  auto& v()
203  {
204  return this->template sub<1>();
205  }
206 
207 public:
208  const auto& v() const
209  {
210  return this->template sub<1>();
211  }
212 
213 public:
214  auto& w()
215  {
216  return this->template sub<2>();
217  }
218 
219 public:
220  const auto& w() const
221  {
222  return this->template sub<2>();
223  }
224 
225 public:
226  auto& av()
227  {
228  return this->template sub<3>();
229  }
230 
231 public:
232  const auto& av() const
233  {
234  return this->template sub<3>();
235  }
236 
237 public:
238  auto& aw()
239  {
240  return this->template sub<4>();
241  }
242 
243 public:
244  const auto& aw() const
245  {
246  return this->template sub<4>();
247  }
248 
249 public:
250  auto& t()
251  {
252  return this->template sub<5>();
253  }
254 
255 public:
256  const auto& t() const
257  {
258  return this->template sub<5>();
259  }
260 
261 public:
262  auto& s()
263  {
264  return this->template sub<6>();
265  }
266 
267 public:
268  const auto& s() const
269  {
270  return this->template sub<6>();
271  }
272 };
273 
274 static constexpr const size_t optParamBlockSize = 3;
275 
284 template <class TNumType, typename TLeafType>
286 {
287 public:
289 
290 public:
291  auto& optParamV()
292  {
293  return this->template sub<0>();
294  } // parameters influencing linear velocity
295 public:
296  const auto& optParamV() const
297  {
298  return this->template sub<0>();
299  }
300 
301 public:
302  auto& optParamW()
303  {
304  return this->template sub<1>();
305  } // parameters influencing angular velocity
306 public:
307  const auto& optParamW() const
308  {
309  return this->template sub<1>();
310  }
311 
312 public:
313  auto& optParamT()
314  {
315  return this->template sub<2>();
316  } // parameters influencing temporal location of previous parameters
317 public:
318  const auto& optParamT() const
319  {
320  return this->template sub<2>();
321  }
322 };
323 
326 
328 template <class TNumType>
331 template <class TNumType>
334 template <class TNumType>
337 template <class TNumType>
339 
349 template <class TNumType, class TCfDataType>
350 struct ParamType
351 {
354  TCfDataType cfData;
355  enum class ParamFuncVars
356  {
357  V,
358  W
359  };
360 };
361 
362 template <class TNumType, class MapDataType, class TStateType, template <class> class TDiscretizationType,
363  class... TFuncsType>
365  : public StateSimBase<StateSimVWBase<TNumType, MapDataType, TStateType, TDiscretizationType, TFuncsType...>,
366  ParamType<TNumType, MapDataType>, TStateType, TDiscretizationType, TFuncsType...>
367 {
369 
370 public:
371  void adjustXSizeImpl(auto& _XNm, auto& _XCf)
372  {
373  this->paramStruct->paramFuncs.precompute();
374  }
375 
376 public:
377  void setXNm0Impl(auto& _XNm0)
378  {
379  for (int i = 0; i < _XNm0.data().size(); ++i)
380  {
381  _XNm0.data()(i) = 0;
382  }
383  _XNm0.x() = this->paramStruct->state0.stateNm().x();
384  _XNm0.y() = this->paramStruct->state0.stateNm().y();
385  }
386  // same as before, but all closed-form variables have to be computed
387 public:
388  void setXCfImpl(auto& _XCf, const TNumType& _arc, const PfEaG& _eAG)
389  {
390  setXCfNmStep(_XCf, _arc, _eAG);
391  auto& paramFuncs = this->paramStruct->paramFuncs;
392  _XCf.w() = paramFuncs.computeFuncVal(asInt(PFV::W));
393  _XCf.av() = paramFuncs.computeFuncDiff1(asInt(PFV::V));
394  _XCf.aw() = paramFuncs.computeFuncDiff1(asInt(PFV::W));
395  _XCf.t() = _arc;
396  _XCf.s() = paramFuncs.computeS();
397  }
398  // implement evaluation of the numerical state variables derivatives at a given arc and a given evaluation order
399  // guarantee
400 public:
401  void setXCfDotImpl(auto& _XCfDot, const auto& _XCf, const TNumType& _arc, const PfEaG& _eAG) const
402  {
403  _XCfDot.theta() = _XCf.w();
404  _XCfDot.v() = _XCf.av();
405  _XCfDot.w() = _XCf.aw();
406  _XCfDot.av() = 0;
407  _XCfDot.aw() = 0;
408  _XCfDot.t() = 1.;
409  _XCfDot.s() = fabs(_XCf.v());
410  }
411  // implement evaluation of the numerical state variables derivatives at a given arc and a given evaluation order
412  // guarantee
413 public:
414  void setXNmDotImpl(auto& _XNmDot, auto& _stateCf, const auto& _stateNm, const TNumType& _arc, const PfEaG& _eAG)
415  {
416  setXCfNmStep(_stateCf, _arc, _eAG);
417  if ((arcNmDotCache_ == _arc) && (_eAG == PfEaG::NEAR_LAST))
418  {
419  }
420  else
421  {
422  cosTheta_ = cos(_stateCf.theta());
423  sinTheta_ = sin(_stateCf.theta());
424  arcNmDotCache_ = _arc;
425  }
426  _XNmDot.x() = _stateCf.v() * cosTheta_;
427  _XNmDot.y() = _stateCf.v() * sinTheta_;
428  }
429 
430 private:
431  void setXCfNmStep(auto& _XCf, const TNumType& _arc, const PfEaG& _eAG)
432  {
433  if ((arcCfNmStepCache_ == _arc) && (_eAG == PfEaG::NEAR_LAST))
434  {
435  return;
436  }
437  arcCfNmStepCache_ = _arc;
438  auto& paramFuncs = this->paramStruct->paramFuncs;
439  const auto& state0 = this->paramStruct->state0;
440  paramFuncs.setEvalArc(_arc, _eAG);
441 
442  const TNumType thetaIndef = paramFuncs.computeFuncInt1(asInt(PFV::W));
443  _XCf.theta() = thetaIndef + state0.stateCf().theta();
444  _XCf.v() = paramFuncs.computeFuncVal(asInt(PFV::V));
445  }
446 
448 
449 public:
450  void setGradXNm0Impl(auto& _gradXNm0, const auto& _XNm0)
451  {
452  for (int i = 0; i < _gradXNm0.data().size(); ++i)
453  {
454  _gradXNm0.data()(i) = 0;
455  }
456  }
457 
458 public:
459  void adjustGradXSizeImpl(auto& _gradXNm, auto& _gradXCf)
460  {
461  auto& paramFuncs = this->paramStruct->paramFuncs;
462  int ctrlPtOptNr = paramFuncs.funcCtrlPtSize(0) - 1;
463  if (_gradXNm.sub(0).sub(0).data().size() != ctrlPtOptNr)
464  {
465  for (size_t i = 0; i < _gradXNm.subSize(); ++i)
466  {
467  for (size_t j = 0; j < _gradXNm.sub(i).subSize(); ++j)
468  {
469  _gradXNm.sub(i).sub(j).subResize(ctrlPtOptNr);
470  }
471  }
472  for (size_t i = 0; i < _gradXCf.subSize(); ++i)
473  {
474  for (size_t j = 0; j < _gradXCf.sub(i).subSize(); ++j)
475  {
476  _gradXCf.sub(i).sub(j).subResize(ctrlPtOptNr);
477  }
478  }
479  }
480  }
481 
482 public:
483  void setGradXCfImpl(auto& _gradXCf, const auto& _XCf, const TNumType& _arc, const PfEaG& _eAG)
484  {
485  setGradXCfNmStep(_gradXCf, _XCf, _arc, _eAG);
486  }
487 
488 public:
489  void setGradXNmDotImpl(auto& _gradXNmDot, auto& _XGradXCf, const auto& _XGradXNm, const TNumType& _arc,
490  const PfEaG& _eAG)
491  {
492  if ((arcGradNmStepCache_ == _arc) && (_eAG == PfEaG::NEAR_LAST))
493  {
494  return;
495  }
496  arcGradNmStepCache_ = _arc;
497 
498  auto& gradXCf = _XGradXCf.stateGrad();
499  const auto& XCf = _XGradXCf.state();
500  setGradXCfNmStep(gradXCf, XCf, _arc, _eAG);
501 
502  // combining dfdx * GradX + dfdu * dudp
503  static Eigen::Matrix<TNumType, 2, 1> dfduX;
504  static Eigen::Matrix<TNumType, 2, 1> dfduY;
505 
506  dfduX(0) = cosTheta_;
507  dfduX(1) = sinTheta_;
508  dfduY(0) = -XCf.v() * sinTheta_;
509  dfduY(1) = +XCf.v() * cosTheta_;
510 
511  auto& dXdParamV = _gradXNmDot.x().optParamV().data();
512  auto& dYdParamV = _gradXNmDot.y().optParamV().data();
513  auto& dXdParamW = _gradXNmDot.x().optParamW().data();
514  auto& dYdParamW = _gradXNmDot.y().optParamW().data();
515  auto& dXdParamT = _gradXNmDot.x().optParamT().data();
516  auto& dYdParamT = _gradXNmDot.y().optParamT().data();
517  const auto& stateGradCfParamVIV = gradXCf.v().optParamV();
518  const auto& stateGradCfParamWITheta = gradXCf.theta().optParamW();
519  const auto& stateGradCfParamTIV = gradXCf.v().optParamT();
520  const auto& stateGradCfParamTITheta = gradXCf.theta().optParamT();
521 
522  for (int i = 0; i < dXdParamV.size(); ++i)
523  {
524  const auto& stateGradCfParamVIVI = stateGradCfParamVIV.sub(i);
525  const auto& stateGradCfParamWIThetaI = stateGradCfParamWITheta.sub(i);
526  const auto& stateGradCfParamTIVI = stateGradCfParamTIV.sub(i);
527  const auto& stateGradCfParamTIThetaI = stateGradCfParamTITheta.sub(i);
528  dXdParamV(i) = stateGradCfParamVIVI * dfduX(0);
529  dYdParamV(i) = stateGradCfParamVIVI * dfduX(1);
530  dXdParamW(i) = stateGradCfParamWIThetaI * dfduY(0);
531  dYdParamW(i) = stateGradCfParamWIThetaI * dfduY(1);
532  dXdParamT(i) = stateGradCfParamTIVI * dfduX(0) + stateGradCfParamTIThetaI * dfduY(0);
533  dYdParamT(i) = stateGradCfParamTIVI * dfduX(1) + stateGradCfParamTIThetaI * dfduY(1);
534  }
535  }
536 
537  // implement evaluation of the numerical state variables derivatives at a given arc and a given evaluation order
538  // guarantee
539 private:
540  void setGradXCfNmStep(auto& _gradXCf, const auto& _XCf, const TNumType& _arc, const PfEaG& _eAG)
541  {
542  if ((arcGradCache_ == _arc) && (_eAG == PfEaG::NEAR_LAST))
543  {
544  return;
545  }
546  arcGradCache_ = _arc;
547  auto& paramFuncs = this->paramStruct->paramFuncs;
548 
549  _gradXCf.data().setZero();
550  auto& dVdParamV = _gradXCf.v().optParamV();
551  auto& dSdParamV = _gradXCf.s().optParamV();
552  for (size_t i = 0; i < dVdParamV.subSize(); ++i)
553  {
554  auto& dVdParamVI = dVdParamV.sub(i);
555  auto& dSdParamVI = dSdParamV.sub(i);
556 
557  if (i + 1 < dVdParamV.subSize())
558  {
559  const TNumType& evalArcAbove = paramFuncs.ctrlPtVal(0, i + 2, CtrlPtDim::ARC);
560  const TNumType& evalArcBelow = paramFuncs.ctrlPtVal(0, i + 1, CtrlPtDim::ARC);
561  if (_arc > evalArcBelow)
562  {
563  const TNumType arcIntEnd = fmin(_arc, evalArcAbove);
564  const TNumType deltaEvalArc = evalArcAbove - evalArcBelow;
565  dSdParamVI = +(arcIntEnd - evalArcBelow) * (evalArcBelow - 2. * _arc + arcIntEnd) / (2. * deltaEvalArc);
566  dVdParamVI = -(arcIntEnd - evalArcBelow) / deltaEvalArc;
567  }
568  }
569  const TNumType& evalArcAbove = paramFuncs.ctrlPtVal(0, i + 1, CtrlPtDim::ARC);
570  const TNumType& evalArcBelow = paramFuncs.ctrlPtVal(0, i, CtrlPtDim::ARC);
571  if (_arc > evalArcBelow)
572  {
573  const TNumType arcIntEnd = fmin(_arc, evalArcAbove);
574  const TNumType deltaEvalArc = evalArcAbove - evalArcBelow;
575  dSdParamVI += -(arcIntEnd - evalArcBelow) * (evalArcBelow - 2. * _arc + arcIntEnd) / (2. * deltaEvalArc);
576  dVdParamVI += +(arcIntEnd - evalArcBelow) / deltaEvalArc;
577  }
578  }
579 
580  auto& dThdParamW = _gradXCf.theta().optParamW();
581  auto& dWdParamW = _gradXCf.w().optParamW();
582  for (size_t i = 0; i < dThdParamW.subSize(); ++i)
583  {
584  auto& dThdParamWI = dThdParamW.sub(i);
585  auto& dWdParamWI = dWdParamW.sub(i);
586  if (i + 1 < dThdParamW.subSize())
587  {
588  const TNumType& evalArcAbove = paramFuncs.ctrlPtVal(1, i + 2, CtrlPtDim::ARC);
589  const TNumType& evalArcBelow = paramFuncs.ctrlPtVal(1, i + 1, CtrlPtDim::ARC);
590  if (_arc > evalArcBelow)
591  {
592  const TNumType arcIntEnd = fmin(_arc, evalArcAbove);
593  const TNumType deltaEvalArc = evalArcAbove - evalArcBelow;
594  dThdParamWI = +(arcIntEnd - evalArcBelow) * (evalArcBelow - 2. * _arc + arcIntEnd) / (2. * deltaEvalArc);
595  dWdParamWI = -(arcIntEnd - evalArcBelow) / deltaEvalArc;
596  }
597  }
598  const TNumType& evalArcAbove = paramFuncs.ctrlPtVal(1, i + 1, CtrlPtDim::ARC);
599  const TNumType& evalArcBelow = paramFuncs.ctrlPtVal(1, i, CtrlPtDim::ARC);
600  if (_arc > evalArcBelow)
601  {
602  const TNumType arcIntEnd = fmin(_arc, evalArcAbove);
603  const TNumType deltaEvalArc = evalArcAbove - evalArcBelow;
604  dThdParamWI += -(arcIntEnd - evalArcBelow) * (evalArcBelow - 2. * _arc + arcIntEnd) / (2. * deltaEvalArc);
605  dWdParamWI += +(arcIntEnd - evalArcBelow) / deltaEvalArc;
606  }
607  }
608 
609  auto& dThdParamT = _gradXCf.theta().optParamT();
610  auto& dVdParamT = _gradXCf.v().optParamT();
611  auto& dWdParamT = _gradXCf.w().optParamT();
612  auto& dSdParamT = _gradXCf.s().optParamT();
613 
614  auto& dAVdParamV = _gradXCf.av().optParamV();
615  auto& dAVdParamT = _gradXCf.av().optParamT();
616  auto& dAWdParamW = _gradXCf.aw().optParamW();
617  auto& dAWdParamT = _gradXCf.aw().optParamT();
618  for (size_t i = 0; i < dVdParamT.subSize(); ++i)
619  {
620  auto& dThdParamTI = dThdParamT.sub(i);
621  auto& dVdParamTI = dVdParamT.sub(i);
622  auto& dWdParamTI = dWdParamT.sub(i);
623  auto& dSdParamTI = dSdParamT.sub(i);
624 
625  auto& dAVdParamVI = dAVdParamV.sub(i);
626  auto& dAWdParamWI = dAWdParamW.sub(i);
627  auto& dAVdParamTI = dAVdParamT.sub(i);
628  auto& dAWdParamTI = dAWdParamT.sub(i);
629  if (i + 1 < paramFuncs.funcCtrlPtSize(0))
630  {
631  const TNumType& evalArcAbove = paramFuncs.ctrlPtVal(1, i + 1, CtrlPtDim::ARC);
632  const TNumType& evalArcBelow = paramFuncs.ctrlPtVal(1, i, CtrlPtDim::ARC);
633  if ((_arc <= evalArcAbove) && (_arc > evalArcBelow))
634  {
635  const TNumType& vP = paramFuncs.ctrlPtVal(0, i + 1, CtrlPtDim::VAL);
636  const TNumType& vM = paramFuncs.ctrlPtVal(0, i + 0, CtrlPtDim::VAL);
637  const TNumType& wP = paramFuncs.ctrlPtVal(1, i + 1, CtrlPtDim::VAL);
638  const TNumType& wM = paramFuncs.ctrlPtVal(1, i + 0, CtrlPtDim::VAL);
639  const TNumType arcIntEnd = fmin(_arc, evalArcAbove);
640  const TNumType deltaEvalArc = evalArcAbove - evalArcBelow;
641  const TNumType deltaEvalArcSqr = deltaEvalArc * deltaEvalArc;
642  const TNumType deltaArcIntBound = arcIntEnd - evalArcBelow;
643  dThdParamTI = +deltaArcIntBound * (wP - wM) * (evalArcBelow - 2. * _arc + arcIntEnd) / (2. * deltaEvalArcSqr);
644  dVdParamTI = -deltaArcIntBound * (vP - vM) / deltaEvalArcSqr;
645  dWdParamTI = -deltaArcIntBound * (wP - wM) / deltaEvalArcSqr;
646  dAVdParamTI = -(vP - vM) / deltaEvalArcSqr;
647  dAWdParamTI = -(wP - wM) / deltaEvalArcSqr;
648  dAVdParamVI = +1. / deltaEvalArc;
649  dAWdParamWI = +1. / deltaEvalArc;
650  dSdParamTI = +deltaArcIntBound * (vP - vM) * (evalArcBelow - 2. * _arc + arcIntEnd) / (2. * deltaEvalArcSqr);
651  }
652  else if ((_arc > evalArcBelow) && (i + 1 < dVdParamT.subSize()))
653  {
654  const TNumType& evalArcAbove2 = paramFuncs.ctrlPtVal(1, i + 2, CtrlPtDim::ARC);
655  const TNumType deltaEvalArc = evalArcAbove2 - evalArcAbove;
656  const TNumType deltaEvalArcSqr = deltaEvalArc * deltaEvalArc;
657  if (_arc <= evalArcAbove2)
658  {
659  dAVdParamVI = -1. / deltaEvalArc;
660  dAWdParamWI = -1. / deltaEvalArc;
661  const TNumType& vP = paramFuncs.ctrlPtVal(0, i + 2, CtrlPtDim::VAL);
662  const TNumType& vM = paramFuncs.ctrlPtVal(0, i + 1, CtrlPtDim::VAL);
663  const TNumType& wP = paramFuncs.ctrlPtVal(1, i + 2, CtrlPtDim::VAL);
664  const TNumType& wM = paramFuncs.ctrlPtVal(1, i + 1, CtrlPtDim::VAL);
665  dAVdParamTI = +(vP - vM) / deltaEvalArcSqr;
666  dAWdParamTI = +(wP - wM) / deltaEvalArcSqr;
667  }
668  if (_arc < evalArcAbove2)
669  {
670  const TNumType& vP = paramFuncs.ctrlPtVal(0, i + 2, CtrlPtDim::VAL);
671  const TNumType& vM = paramFuncs.ctrlPtVal(0, i + 1, CtrlPtDim::VAL);
672  const TNumType& vMM = paramFuncs.ctrlPtVal(0, i + 0, CtrlPtDim::VAL);
673  const TNumType& wP = paramFuncs.ctrlPtVal(1, i + 2, CtrlPtDim::VAL);
674  const TNumType& wM = paramFuncs.ctrlPtVal(1, i + 1, CtrlPtDim::VAL);
675  const TNumType& wMM = paramFuncs.ctrlPtVal(1, i + 0, CtrlPtDim::VAL);
676  const TNumType arcIntEnd = fmin(_arc, evalArcAbove2);
677 
678  const TNumType deltaArcIntBound = evalArcAbove2 - arcIntEnd;
679  dThdParamTI = -(+(wM - wMM) * evalArcAbove2 * evalArcAbove2 +
680  (wP - wMM) * (evalArcAbove * evalArcAbove - 2. * evalArcAbove * evalArcAbove2) +
681  (wP - wM) * (arcIntEnd * arcIntEnd + 2. * _arc * (evalArcAbove2 - arcIntEnd))) /
682  (2. * deltaEvalArcSqr);
683  dVdParamTI = -deltaArcIntBound * (vP - vM) / deltaEvalArcSqr;
684  dWdParamTI = -deltaArcIntBound * (wP - wM) / deltaEvalArcSqr;
685  dSdParamTI = -(+(vM - vMM) * evalArcAbove2 * evalArcAbove2 +
686  (vP - vMM) * (evalArcAbove * evalArcAbove - 2. * evalArcAbove * evalArcAbove2) +
687  (vP - vM) * (arcIntEnd * arcIntEnd + 2. * _arc * (evalArcAbove2 - arcIntEnd))) /
688  (2. * deltaEvalArcSqr);
689  }
690  else
691  {
692  const TNumType& vP = paramFuncs.ctrlPtVal(0, i + 2, CtrlPtDim::VAL);
693  const TNumType& vM = paramFuncs.ctrlPtVal(0, i + 0, CtrlPtDim::VAL);
694  const TNumType& wP = paramFuncs.ctrlPtVal(1, i + 2, CtrlPtDim::VAL);
695  const TNumType& wM = paramFuncs.ctrlPtVal(1, i + 0, CtrlPtDim::VAL);
696  dThdParamTI = -(wP - wM) / 2.;
697  dSdParamTI = -(vP - vM) / 2.;
698  }
699  }
700  else if (_arc > evalArcBelow)
701  {
702  const TNumType& vP = paramFuncs.ctrlPtVal(0, i + 1, CtrlPtDim::VAL);
703  const TNumType& vM = paramFuncs.ctrlPtVal(0, i + 0, CtrlPtDim::VAL);
704  const TNumType& wP = paramFuncs.ctrlPtVal(1, i + 1, CtrlPtDim::VAL);
705  const TNumType& wM = paramFuncs.ctrlPtVal(1, i + 0, CtrlPtDim::VAL);
706  dThdParamTI = -(wP - wM) / 2.;
707  dSdParamTI = -(vP - vM) / 2.;
708  }
709  }
710  }
711  }
712 
713  // internal helper variables
714 protected:
715  TNumType cosTheta_;
716 
717 protected:
718  TNumType sinTheta_;
719 
720 protected:
722 
723 protected:
724  TNumType arcNmDotCache_;
725 
726 protected:
727  TNumType arcGradCache_;
728 
729 protected:
731 };
732 //---------------------------------------------------------------------Optimization parameters
733 
734 template <class TNumType, class TParamStructType>
736 {
737  static void setOptVar(TParamStructType& _paramStruct, const Eigen::Matrix<TNumType, -1, 1>& _optVarExt)
738  {
739  auto& paramFuncs = _paramStruct.paramFuncs;
740  size_t idxOptVec = 0;
741  for (size_t i = 0; i < paramFuncs.funcsSize(); ++i)
742  {
743  for (size_t j = 1; j < paramFuncs.funcCtrlPtSize(i); ++j)
744  {
745  paramFuncs.ctrlPtVal(i, j, CtrlPtDim::VAL) = _optVarExt(idxOptVec++);
746  }
747  }
748  for (size_t j = 1; j < paramFuncs.funcsArcSize(0); ++j)
749  {
750  paramFuncs.funcsArc(0, j) = _optVarExt(idxOptVec++);
751  }
752  }
753  static void getOptVar(Eigen::Matrix<TNumType, -1, 1>& _optVarExt, const TParamStructType& _paramStruct)
754  {
755  auto& paramFuncs = _paramStruct.paramFuncs;
756  int newSize = paramFuncs.funcsSize() * (paramFuncs.funcCtrlPtSize(0) - 1) + (paramFuncs.funcsArcSize(0) - 1);
757  if (newSize != _optVarExt.size())
758  {
759  _optVarExt.resize(newSize);
760  }
761  size_t idxOptVec = 0;
762  for (size_t i = 0; i < paramFuncs.funcsSize(); ++i)
763  {
764  for (size_t j = 1; j < paramFuncs.funcCtrlPtSize(i); ++j)
765  {
766  _optVarExt(idxOptVec++) = paramFuncs.ctrlPtVal(i, j, CtrlPtDim::VAL);
767  }
768  }
769  for (size_t j = 1; j < paramFuncs.funcsArcSize(0); ++j)
770  {
771  _optVarExt(idxOptVec++) = paramFuncs.funcsArc(0, j);
772  }
773  }
774 };
775 
776 template <class TNumType, class TMapDataType, template <class> class TDiscretizationType>
777 class StateSimVW : public StateSimVWBase<TNumType, TMapDataType, StateVW<TNumType>, TDiscretizationType>
778 {
779 };
780 
781 template <class TNumType, class TMapDataType, template <class> class TDiscretizationType, class... TCostFuncType>
783  : public StateSimVWBase<TNumType, TMapDataType, StateWithLVW<TNumType>, TDiscretizationType, TCostFuncType...>
784 {
785 };
786 
787 template <class TNumType, class TMapDataType, template <class> class TDiscretizationType>
788 class StateWithGradSimVW : public StateSimVWBase<TNumType, TMapDataType, StateWithGradVW<TNumType>, TDiscretizationType>
789 {
790 };
791 
792 template <class TNumType, class TMapDataType, template <class> class TDiscretizationType, class... TCostFuncType>
793 class StateWithLWithGradSimVW : public StateSimVWBase<TNumType, TMapDataType, StateWithLWithGradVW<TNumType>,
794  TDiscretizationType, TCostFuncType...>
795 {
796 };
797 }
798 }
799 
800 #endif // AGV_DIFF_DRIVE_V_W_HPP
void setGradXCfImpl(auto &_gradXCf, const auto &_XCf, const TNumType &_arc, const PfEaG &_eAG)
Defining the system optimization parameters structure.
static constexpr const size_t optParamBlockSize
void setGradXCfNmStep(auto &_gradXCf, const auto &_XCf, const TNumType &_arc, const PfEaG &_eAG)
control point value
void setXCfImpl(auto &_XCf, const TNumType &_arc, const PfEaG &_eAG)
control point arc parameter
void setGradXNmDotImpl(auto &_gradXNmDot, auto &_XGradXCf, const auto &_XGradXNm, const TNumType &_arc, const PfEaG &_eAG)
constexpr auto asInt(Enumeration const value) -> typename std::underlying_type< Enumeration >::type
Definition: utils.h:87
static void getOptVar(Eigen::Matrix< TNumType,-1, 1 > &_optVarExt, const TParamStructType &_paramStruct)
Defining the system closed-form state variables.
void setGradXNm0Impl(auto &_gradXNm0, const auto &_XNm0)
--------------------------------—Gradient information--------------------------------—/// ...
agent base center linear velocity is parametric function
static void setOptVar(TParamStructType &_paramStruct, const Eigen::Matrix< TNumType,-1, 1 > &_optVarExt)
const auto & theta() const
Defining the system optimization parameters structure.
ParamFuncsSpline0Dist< TNumType, 2, 1 > paramFuncs
Defining the system numerical state variables, including a scalar objective function L...
void setXNmDotImpl(auto &_XNmDot, auto &_stateCf, const auto &_stateNm, const TNumType &_arc, const PfEaG &_eAG)
void setXCfDotImpl(auto &_XCfDot, const auto &_XCf, const TNumType &_arc, const PfEaG &_eAG) const
void adjustGradXSizeImpl(auto &_gradXNm, auto &_gradXCf)
close to previous evaluation arc
void setXCfNmStep(auto &_XCf, const TNumType &_arc, const PfEaG &_eAG)
const auto & state() const
Defining the system numerical state variables.
void adjustXSizeImpl(auto &_XNm, auto &_XCf)


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