33 #ifndef AGV_DIFF_DRIVE_V_W_HPP 34 #define AGV_DIFF_DRIVE_V_W_HPP 55 template <
class TNumType,
class TLeafType>
64 return this->
template sub<0>();
70 return this->
template sub<0>();
76 return this->
template sub<1>();
82 return this->
template sub<1>();
107 template <
class TNumType,
class TLeafType>
116 return this->
template sub<0>();
122 return this->
template sub<0>();
128 return this->
template sub<1>();
134 return this->
template sub<1>();
140 return this->
template sub<2>();
144 const auto&
x()
const 146 return this->
template sub<2>();
152 return this->
template sub<3>();
156 const auto&
y()
const 158 return this->
template sub<3>();
183 template <
class TNumType,
class TLeafType>
192 return this->
template sub<0>();
198 return this->
template sub<0>();
204 return this->
template sub<1>();
208 const auto&
v()
const 210 return this->
template sub<1>();
216 return this->
template sub<2>();
220 const auto&
w()
const 222 return this->
template sub<2>();
228 return this->
template sub<3>();
232 const auto&
av()
const 234 return this->
template sub<3>();
240 return this->
template sub<4>();
244 const auto&
aw()
const 246 return this->
template sub<4>();
252 return this->
template sub<5>();
256 const auto&
t()
const 258 return this->
template sub<5>();
264 return this->
template sub<6>();
268 const auto&
s()
const 270 return this->
template sub<6>();
284 template <
class TNumType,
typename TLeafType>
293 return this->
template sub<0>();
298 return this->
template sub<0>();
304 return this->
template sub<1>();
309 return this->
template sub<1>();
315 return this->
template sub<2>();
320 return this->
template sub<2>();
328 template <
class TNumType>
331 template <
class TNumType>
334 template <
class TNumType>
337 template <
class TNumType>
349 template <
class TNumType,
class TCfDataType>
362 template <
class TNumType,
class MapDataType,
class TStateType,
template <
class>
class TDiscretizationType,
365 :
public StateSimBase<StateSimVWBase<TNumType, MapDataType, TStateType, TDiscretizationType, TFuncsType...>,
366 ParamType<TNumType, MapDataType>, TStateType, TDiscretizationType, TFuncsType...>
373 this->paramStruct->paramFuncs.precompute();
379 for (
int i = 0; i < _XNm0.data().size(); ++i)
383 _XNm0.x() = this->paramStruct->state0.stateNm().x();
384 _XNm0.y() = this->paramStruct->state0.stateNm().y();
388 void setXCfImpl(
auto& _XCf,
const TNumType& _arc,
const PfEaG& _eAG)
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));
396 _XCf.s() = paramFuncs.computeS();
401 void setXCfDotImpl(
auto& _XCfDot,
const auto& _XCf,
const TNumType& _arc,
const PfEaG& _eAG)
const 403 _XCfDot.theta() = _XCf.w();
404 _XCfDot.v() = _XCf.av();
405 _XCfDot.w() = _XCf.aw();
409 _XCfDot.s() = fabs(_XCf.v());
414 void setXNmDotImpl(
auto& _XNmDot,
auto& _stateCf,
const auto& _stateNm,
const TNumType& _arc,
const PfEaG& _eAG)
416 setXCfNmStep(_stateCf, _arc, _eAG);
422 cosTheta_ = cos(_stateCf.theta());
423 sinTheta_ = sin(_stateCf.theta());
424 arcNmDotCache_ = _arc;
426 _XNmDot.x() = _stateCf.v() * cosTheta_;
427 _XNmDot.y() = _stateCf.v() * sinTheta_;
437 arcCfNmStepCache_ = _arc;
438 auto& paramFuncs = this->paramStruct->paramFuncs;
439 const auto& state0 = this->paramStruct->state0;
440 paramFuncs.setEvalArc(_arc, _eAG);
442 const TNumType thetaIndef = paramFuncs.computeFuncInt1(
asInt(PFV::W));
443 _XCf.theta() = thetaIndef + state0.stateCf().theta();
444 _XCf.v() = paramFuncs.computeFuncVal(
asInt(
PFV::V));
452 for (
int i = 0; i < _gradXNm0.data().size(); ++i)
454 _gradXNm0.data()(i) = 0;
461 auto& paramFuncs = this->paramStruct->paramFuncs;
462 int ctrlPtOptNr = paramFuncs.funcCtrlPtSize(0) - 1;
463 if (_gradXNm.sub(0).sub(0).data().size() != ctrlPtOptNr)
465 for (
size_t i = 0; i < _gradXNm.subSize(); ++i)
467 for (
size_t j = 0; j < _gradXNm.sub(i).subSize(); ++j)
469 _gradXNm.sub(i).sub(j).subResize(ctrlPtOptNr);
472 for (
size_t i = 0; i < _gradXCf.subSize(); ++i)
474 for (
size_t j = 0; j < _gradXCf.sub(i).subSize(); ++j)
476 _gradXCf.sub(i).sub(j).subResize(ctrlPtOptNr);
483 void setGradXCfImpl(
auto& _gradXCf,
const auto& _XCf,
const TNumType& _arc,
const PfEaG& _eAG)
485 setGradXCfNmStep(_gradXCf, _XCf, _arc, _eAG);
489 void setGradXNmDotImpl(
auto& _gradXNmDot,
auto& _XGradXCf,
const auto& _XGradXNm,
const TNumType& _arc,
496 arcGradNmStepCache_ = _arc;
498 auto& gradXCf = _XGradXCf.stateGrad();
499 const auto& XCf = _XGradXCf.state();
500 setGradXCfNmStep(gradXCf, XCf, _arc, _eAG);
503 static Eigen::Matrix<TNumType, 2, 1> dfduX;
504 static Eigen::Matrix<TNumType, 2, 1> dfduY;
506 dfduX(0) = cosTheta_;
507 dfduX(1) = sinTheta_;
508 dfduY(0) = -XCf.v() * sinTheta_;
509 dfduY(1) = +XCf.v() * cosTheta_;
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();
522 for (
int i = 0; i < dXdParamV.size(); ++i)
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);
540 void setGradXCfNmStep(
auto& _gradXCf,
const auto& _XCf,
const TNumType& _arc,
const PfEaG& _eAG)
546 arcGradCache_ = _arc;
547 auto& paramFuncs = this->paramStruct->paramFuncs;
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)
554 auto& dVdParamVI = dVdParamV.sub(i);
555 auto& dSdParamVI = dSdParamV.sub(i);
557 if (i + 1 < dVdParamV.subSize())
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)
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;
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)
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;
580 auto& dThdParamW = _gradXCf.theta().optParamW();
581 auto& dWdParamW = _gradXCf.w().optParamW();
582 for (
size_t i = 0; i < dThdParamW.subSize(); ++i)
584 auto& dThdParamWI = dThdParamW.sub(i);
585 auto& dWdParamWI = dWdParamW.sub(i);
586 if (i + 1 < dThdParamW.subSize())
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)
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;
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)
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;
609 auto& dThdParamT = _gradXCf.theta().optParamT();
610 auto& dVdParamT = _gradXCf.v().optParamT();
611 auto& dWdParamT = _gradXCf.w().optParamT();
612 auto& dSdParamT = _gradXCf.s().optParamT();
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)
620 auto& dThdParamTI = dThdParamT.sub(i);
621 auto& dVdParamTI = dVdParamT.sub(i);
622 auto& dWdParamTI = dWdParamT.sub(i);
623 auto& dSdParamTI = dSdParamT.sub(i);
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))
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))
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);
652 else if ((_arc > evalArcBelow) && (i + 1 < dVdParamT.subSize()))
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)
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;
668 if (_arc < evalArcAbove2)
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);
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);
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.;
700 else if (_arc > evalArcBelow)
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.;
734 template <
class TNumType,
class TParamStructType>
737 static void setOptVar(TParamStructType& _paramStruct,
const Eigen::Matrix<TNumType, -1, 1>& _optVarExt)
739 auto& paramFuncs = _paramStruct.paramFuncs;
740 size_t idxOptVec = 0;
741 for (
size_t i = 0; i < paramFuncs.funcsSize(); ++i)
743 for (
size_t j = 1; j < paramFuncs.funcCtrlPtSize(i); ++j)
745 paramFuncs.ctrlPtVal(i, j,
CtrlPtDim::VAL) = _optVarExt(idxOptVec++);
748 for (
size_t j = 1; j < paramFuncs.funcsArcSize(0); ++j)
750 paramFuncs.funcsArc(0, j) = _optVarExt(idxOptVec++);
753 static void getOptVar(Eigen::Matrix<TNumType, -1, 1>& _optVarExt,
const TParamStructType& _paramStruct)
755 auto& paramFuncs = _paramStruct.paramFuncs;
756 int newSize = paramFuncs.funcsSize() * (paramFuncs.funcCtrlPtSize(0) - 1) + (paramFuncs.funcsArcSize(0) - 1);
757 if (newSize != _optVarExt.size())
759 _optVarExt.resize(newSize);
761 size_t idxOptVec = 0;
762 for (
size_t i = 0; i < paramFuncs.funcsSize(); ++i)
764 for (
size_t j = 1; j < paramFuncs.funcCtrlPtSize(i); ++j)
766 _optVarExt(idxOptVec++) = paramFuncs.ctrlPtVal(i, j,
CtrlPtDim::VAL);
769 for (
size_t j = 1; j < paramFuncs.funcsArcSize(0); ++j)
771 _optVarExt(idxOptVec++) = paramFuncs.funcsArc(0, j);
776 template <
class TNumType,
class TMapDataType,
template <
class>
class TDiscretizationType>
781 template <
class TNumType,
class TMapDataType,
template <
class>
class TDiscretizationType,
class... TCostFuncType>
783 :
public StateSimVWBase<TNumType, TMapDataType, StateWithLVW<TNumType>, TDiscretizationType, TCostFuncType...>
787 template <
class TNumType,
class TMapDataType,
template <
class>
class TDiscretizationType>
792 template <
class TNumType,
class TMapDataType,
template <
class>
class TDiscretizationType,
class... TCostFuncType>
794 TDiscretizationType, TCostFuncType...>
800 #endif // AGV_DIFF_DRIVE_V_W_HPP
typename ParamType< TNumType, TMapDataType >::ParamFuncVars PFV
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)
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)
const auto & optParamT() const
constexpr auto asInt(Enumeration const value) -> typename std::underlying_type< Enumeration >::type
static void getOptVar(Eigen::Matrix< TNumType,-1, 1 > &_optVarExt, const TParamStructType &_paramStruct)
const auto & JInt() const
StateVW< TNumType > state0
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
const auto & optParamW() const
TNumType arcCfNmStepCache_
Defining the system optimization parameters structure.
ParamFuncsSpline0Dist< TNumType, 2, 1 > paramFuncs
void setXNm0Impl(auto &_XNm0)
Defining the system numerical state variables, including a scalar objective function L...
TNumType arcGradNmStepCache_
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
const auto & state() const
void setXCfNmStep(auto &_XCf, const TNumType &_arc, const PfEaG &_eAG)
const auto & JPow() const
const auto & optParamV() const
const auto & state() const
Defining the system numerical state variables.
void adjustXSizeImpl(auto &_XNm, auto &_XCf)