33 #ifndef AGV_DIFF_DRIVE_V_W_LATTICES_HPP 34 #define AGV_DIFF_DRIVE_V_W_LATTICES_HPP 42 template <
typename TNumType,
class TSimType,
class... TCostFuncsType>
44 :
public LatticeTypeBaseCRTP<LatticeTypeStateSimBeginEnd<TNumType, TSimType, TCostFuncsType...>, TNumType, TSimType,
53 _latticeArcs.resize(1);
54 _latticeArcs[0] = _sim.paramStruct->paramFuncs.funcsArcEnd();
58 void computeDArcIdPImpl(
const TSimType& _sim,
const TNumType _arc,
const size_t& _lattIdx,
auto& _dstStateGrad)
60 auto& dstStateGradCf = _dstStateGrad.stateCf();
61 auto& dstStateGradNm = _dstStateGrad.stateNm();
62 size_t optParamTBackIdx = dstStateGradCf.sub(0).data().size() - 1;
63 dstStateGradCf.mat().col(optParamTBackIdx).noalias() += _sim.stateCfDotCache().data();
64 dstStateGradNm.mat().col(optParamTBackIdx).noalias() += _sim.stateNmDotCache().data();
73 template <
typename TNumType,
class TSimType,
class... TCostFuncsType>
75 :
public LatticeTypeBaseCRTP<LatticeTypeStateSimEqDt<TNumType, TSimType, TCostFuncsType...>, TNumType, TSimType,
84 const TNumType arcParamMax = _sim.paramStruct->paramFuncs.funcsArcEnd();
88 dt = arcParamMax / (TNumType)(nrPts_);
95 if ((
int)_latticeArcs.size() != nrPts_)
97 _latticeArcs.resize(nrPts_);
99 for (
int i = 0; i < nrPts_; ++i)
101 _latticeArcs[i] = (i + 1) * dt;
103 _latticeArcs.back() = arcParamMax;
107 void computeDArcIdPImpl(
const TSimType& _sim,
const TNumType _arc,
const size_t& _lattIdx,
auto& _dstStateGrad)
110 auto& dstStateGradCf = _dstStateGrad.stateCf();
111 auto& dstStateGradNm = _dstStateGrad.stateNm();
113 const TNumType dtIdpEnd = (TNumType)(_lattIdx + 1) / (TNumType)(this->
lattice.size() );
114 size_t optParamTBackIdx = dstStateGradCf.sub(0).data().size() - 1;
116 dstStateGradCf.mat().col(optParamTBackIdx).noalias() += _sim.stateCfDotCache().data() * dtIdpEnd;
117 dstStateGradNm.mat().col(optParamTBackIdx).noalias() += _sim.stateNmDotCache().data() * dtIdpEnd;
152 template <
typename TNumType,
class TSimType,
class... TCostFuncsType>
154 :
public LatticeTypeBaseCRTP<LatticeTypeStateSimEqDs<TNumType, TSimType, TCostFuncsType...>, TNumType, TSimType,
175 auto& paramFuncs = _sim.paramStruct->paramFuncs;
179 paramFuncs.setEvalArc(paramFuncs.funcsArcEnd());
180 sEnd = paramFuncs.computeS();
181 ds_ = sEnd / (TNumType)(nrPts_);
182 paramFuncs.setEvalArc(paramFuncs.funcsArcBegin());
183 if ((
int)_latticeArcs.size() != nrPts_)
185 _latticeArcs.resize(nrPts_);
187 for (
int i = 0; i < nrPts_; ++i)
189 _latticeArcs[i] = (i + 1) * ds_;
191 _latticeArcs.back() = sEnd;
192 paramFuncs.computeS2TLattice(_latticeArcs, _latticeArcs);
197 void computeDArcIdPImpl(
const TSimType& _sim,
const TNumType _arc,
const size_t& _lattIdx,
auto& _dstStateGrad)
203 TNumType tEnd = _sim.paramStruct->paramFuncs.funcsArcEnd();
204 auto& simNonConst =
const_cast<TSimType&
>(_sim);
209 dsdp = _sim.state().stateGradCf().s().data();
210 dsdp(dsdp.rows() - 1) += _sim.stateCfDotCache().s();
215 stateDotCache.resize(_sim.stateNmDotCache().data().size() + _sim.stateCfDotCache().data().size());
217 stateDotCache.block(0, 0, _sim.stateNmDotCache().data().size(), 1).noalias() = _sim.stateNmDotCache().data();
218 stateDotCache.block(_sim.stateNmDotCache().data().size(), 0, _sim.stateCfDotCache().data().size(), 1).noalias() =
219 _sim.stateCfDotCache().data();
220 auto& v = _sim.state().stateCf().v();
223 TNumType iByNS = (TNumType)(_lattIdx + 1) /
224 (TNumType)(this->
lattice.size() ) ;
225 _dstStateGrad.mat() += (stateDotCache) * ((iByNS * dsdp - _dstStateGrad.stateCf().s().data()) / v).transpose();
261 Eigen::Matrix<TNumType, -1, 1>
dsdp;
267 template <
typename TNumType,
class TSimType,
class... TCostFuncsType>
269 :
public LatticeTypeBaseCRTP<LatticeTypeStateSimCtrlPtKnots<TNumType, TSimType, TCostFuncsType...>, TNumType,
270 TSimType, TCostFuncsType...>
280 _latticeArcs.resize(_sim.paramStruct->paramFuncs.funcsArcSize(0) - 1);
281 auto& paramFuncs = _sim.paramStruct->paramFuncs;
282 for (
size_t i = 0; i < _latticeArcs.size(); ++i)
284 _latticeArcs[i] = paramFuncs.funcsArc(0, i + 1);
289 _latticeArcs.clear();
294 void computeDArcIdPImpl(
const TSimType& _sim,
const TNumType _arc,
const size_t& _lattIdx,
auto& _dstStateGrad)
298 auto& dstStateGradCf = _dstStateGrad.stateCf();
299 auto& dstStateGradNm = _dstStateGrad.stateNm();
300 size_t optParamTIdx =
301 dstStateGradCf.sub(0).optParamV().data().size() + dstStateGradCf.sub(0).optParamW().data().size();
302 dstStateGradCf.mat().col(optParamTIdx + _lattIdx).noalias() += _sim.stateCfDotCache().data();
303 dstStateGradNm.mat().col(optParamTIdx + _lattIdx).noalias() += _sim.stateNmDotCache().data();
317 #endif // AGV_DIFF_DRIVE_V_W_LATTICES_HPP virtual void precompute(TSimType &_sim) override
static void computeLatticeArcsImpl(TSimType &_sim, std::vector< TNumType > &_latticeArcs)
virtual void precompute(TSimType &_sim) override
void setDt(const TNumType &_dt)
void setNrPts(const size_t &_nrPts)
void computeDArcIdPImpl(const TSimType &_sim, const TNumType _arc, const size_t &_lattIdx, auto &_dstStateGrad)
void computeLatticeArcsImpl(TSimType &_sim, std::vector< TNumType > &_latticeArcs) const
void setDs(const TNumType &_ds)
void computeDArcIdPImpl(const TSimType &_sim, const TNumType _arc, const size_t &_lattIdx, auto &_dstStateGrad)
void computeLatticeArcsImpl(TSimType &_sim, std::vector< TNumType > &_latticeArcs)
void setNrPts(const size_t &_nrPts)
std::vector< LatticePoint< NumType, StateType > > lattice
Eigen::Matrix< TNumType,-1, 1 > dsdp
virtual void precompute(TSimType &_sim) override
close to previous evaluation arc
void computeLatticeArcsImpl(TSimType &_sim, std::vector< TNumType > &_latticeArcs) const
void computeDArcIdPImpl(const TSimType &_sim, const TNumType _arc, const size_t &_lattIdx, auto &_dstStateGrad)
Eigen::Matrix< TNumType,-1, 1 > stateDotCache
LatticeTypeBaseCRTP()=default
this evaluation arc is at the arc parametrization begin
virtual void precompute(TSimType &_sim) override
void computeDArcIdPImpl(const TSimType &_sim, const TNumType _arc, const size_t &_lattIdx, auto &_dstStateGrad)