2 #include "gtest/gtest.h" 4 #include <boost/concept_check.hpp> 20 template <
class TNumType,
class TMapDataType>
22 template <
class TNumType,
class TMapDataType>
24 template <
class TNumType,
class TMapDataType>
26 template <
class TNumType,
class TMapDataType>
29 using NumType = double;
30 using MapDataType = double;
31 template <
class TNumType>
37 using StateDiffDriveType = StateWithGradVW<NumType>;
38 using StateSimDiffDriveType = StateWithGradSimVW<NumType, MapDataType, DiscrType>;
39 using StateSimPtr = std::shared_ptr<StateSimDiffDriveType>;
40 using TrajectorySimulatorType =
42 LatticeTypeStateSimEqDtSim, LatticeTypeStateSimEqDsSim, LatticeTypeStateSimCtrlPtKnotsSim>;
45 using PFV = ParamType<NumType, MapDataType>::ParamFuncVars;
48 class TrajectorySimulatorTest :
public ::testing::Test
54 TrajectorySimulatorTest()
57 sp = std::shared_ptr<StateSimDiffDriveType>(
new StateSimDiffDriveType);
62 static constexpr
const int paramFuncArcRefIdxAll = 0;
64 pf[
asInt(
PFV::V)].ctrlPtsArcRefIdx = paramFuncArcRefIdxAll;
65 pf[
asInt(PFV::W)].ctrlPtsSize = 3;
66 pf[
asInt(PFV::W)].ctrlPtsArcRefIdx = paramFuncArcRefIdxAll;
74 sp->paramStruct->paramFuncs.init(pf);
78 trajSim = std::shared_ptr<TrajectorySimulatorType>(
new TrajectorySimulatorType(sp));
81 virtual ~TrajectorySimulatorTest()
95 virtual void TearDown()
105 bool checkSimLatticeConsistency()
107 bool consistent =
true;
113 for (
size_t i = 1; i < trajSim->simLatticeSize(); ++i)
115 if (!(trajSim->simLatticeI(i - 1).arc < trajSim->simLatticeI(i).arc))
125 size_t nrPartStates = 0;
126 for_each_tuple(_tsp->partialLattices_, [&nrPartStates](
auto& partLatticeI)
128 nrPartStates += partLatticeI.lattice.size();
157 size_t expectedDtStates(
const double _DeltaT,
const double _dt)
159 return (ceil(_DeltaT / _dt) + 1);
165 TEST_F(TrajectorySimulatorTest, SimPrecalcFrom0Dt)
167 auto* funcs = &trajSim->stateSim()->paramStruct->paramFuncs;
171 funcs->ctrlPtVal(funcIdx, 0,
PfCpD::ARC) = 0 + initT;
172 funcs->ctrlPtVal(funcIdx, 1,
PfCpD::ARC) = 0.5 + initT;
173 funcs->ctrlPtVal(funcIdx, 2,
PfCpD::ARC) = 1 + initT;
176 funcs->ctrlPtVal(funcIdx, 0,
PfCpD::VAL) = 3.0 * M_PI;
177 funcs->ctrlPtVal(funcIdx, 1,
PfCpD::VAL) = -0.5 * M_PI;
178 funcs->ctrlPtVal(funcIdx, 2,
PfCpD::VAL) = 2.0 * M_PI;
181 funcs->ctrlPtVal(funcIdx, 0,
PfCpD::VAL) = 3.5 * M_PI;
182 funcs->ctrlPtVal(funcIdx, 1,
PfCpD::VAL) = 1.5 * M_PI;
183 funcs->ctrlPtVal(funcIdx, 2,
PfCpD::VAL) = -4.5 * M_PI;
187 auto& latticeDt = trajSim->partialLattice<LatticeTypeStateSimEqDtSim>();
188 auto& latticeDs = trajSim->partialLattice<LatticeTypeStateSimEqDsSim>();
189 auto& latticeCP = trajSim->partialLattice<LatticeTypeStateSimCtrlPtKnotsSim>();
191 latticeDt.setDt(0.1);
193 latticeCP.inUse =
false;
195 size_t statesBeginEnd = 2, statesDt, statesDs, statesLattice0;
196 double sumStates = 0;
198 latticeDt.setDt(0.1);
199 trajSim->simulateTrajectory();
200 statesDt = expectedDtStates(funcs->funcsArcEnd(), latticeDt.dt());
203 sumStates = statesBeginEnd + statesDt + statesDs + statesLattice0;
204 EXPECT_EQ(sumStates, sumAllPartStates(trajSim));
205 EXPECT_EQ(sumStates, trajSim->simLatticeSize());
206 checkSimLatticeConsistency();
208 latticeDt.setDt(0.12);
209 trajSim->simulateTrajectory();
210 statesDt = expectedDtStates(funcs->funcsArcEnd(), latticeDt.dt());
213 sumStates = statesBeginEnd + statesDt + statesDs + statesLattice0;
214 EXPECT_EQ(sumStates, sumAllPartStates(trajSim));
215 EXPECT_EQ(sumStates , trajSim->simLatticeSize());
216 checkSimLatticeConsistency();
218 latticeDt.setDt(0.25);
219 trajSim->simulateTrajectory();
220 statesDt = expectedDtStates(funcs->funcsArcEnd(), latticeDt.dt());
223 sumStates = statesBeginEnd + statesDt + statesDs + statesLattice0;
224 EXPECT_EQ(sumStates, sumAllPartStates(trajSim));
225 EXPECT_EQ(sumStates, trajSim->simLatticeSize());
226 checkSimLatticeConsistency();
229 TEST_F(TrajectorySimulatorTest, SimPrecalcFrom0DtDsCtrlPt)
231 auto* funcs = &trajSim->stateSim()->paramStruct->paramFuncs;
235 funcs->ctrlPtVal(funcIdx, 0,
PfCpD::ARC) = 0 + initT;
236 funcs->ctrlPtVal(funcIdx, 1,
PfCpD::ARC) = 0.557 + initT;
237 funcs->ctrlPtVal(funcIdx, 2,
PfCpD::ARC) = 1 + initT;
240 funcs->ctrlPtVal(funcIdx, 0,
PfCpD::VAL) = 1.0;
241 funcs->ctrlPtVal(funcIdx, 1,
PfCpD::VAL) = 1.0;
242 funcs->ctrlPtVal(funcIdx, 2,
PfCpD::VAL) = 1.0;
245 funcs->ctrlPtVal(funcIdx, 0,
PfCpD::VAL) = 3.5 * M_PI;
246 funcs->ctrlPtVal(funcIdx, 1,
PfCpD::VAL) = 1.5 * M_PI;
247 funcs->ctrlPtVal(funcIdx, 2,
PfCpD::VAL) = -4.5 * M_PI;
252 size_t statesBeginEnd = 2, statesDt, statesDs, statesLattice0;
253 double sumStates = 0;
255 auto& latticeDt = trajSim->partialLattice<LatticeTypeStateSimEqDtSim>();
256 auto& latticeDsVal = trajSim->partialLattice<LatticeTypeStateSimEqDsSim>().ds_;
257 auto& latticeCPVal = trajSim->partialLattice<LatticeTypeStateSimCtrlPtKnotsSim>().inUse;
258 latticeDt.setDt(0.1);
262 latticeDt.setDt(0.1);
265 statesDt = expectedDtStates(funcs->funcsArcEnd(), latticeDt.dt());
267 statesLattice0 = funcs->funcCtrlPtSize(0);
268 sumStates = statesBeginEnd + statesDt + statesDs + statesLattice0;
269 EXPECT_EQ(sumStates, sumAllPartStates(trajSim));
272 EXPECT_EQ(sumStates, trajSim->simLatticeSize());
273 checkSimLatticeConsistency();
275 latticeDt.setDt(0.1);
277 trajSim->simulateTrajectory();
278 statesDt = expectedDtStates(funcs->funcsArcEnd(), latticeDt.dt());
280 statesLattice0 = funcs->funcCtrlPtSize(0);
281 sumStates = statesBeginEnd + statesDt + statesDs + statesLattice0;
282 EXPECT_EQ(sumStates, sumAllPartStates(trajSim));
283 EXPECT_EQ(sumStates, trajSim->simLatticeSize());
284 checkSimLatticeConsistency();
286 latticeDt.setDt(0.1);
288 trajSim->simulateTrajectory();
289 statesDt = expectedDtStates(funcs->funcsArcEnd(), latticeDt.dt());
291 statesLattice0 = funcs->funcCtrlPtSize(0);
292 sumStates = statesBeginEnd + statesDt + statesDs + statesLattice0;
293 EXPECT_EQ(sumStates, sumAllPartStates(trajSim));
294 EXPECT_EQ(sumStates, trajSim->simLatticeSize());
295 checkSimLatticeConsistency();
302 int main(
int argc,
char** argv)
304 ::testing::InitGoogleTest(&argc, argv);
305 return RUN_ALL_TESTS();
Containts parametric function initialization data.
control point arc parameter
Helper function needed to upgrade c++ 2011.
constexpr auto asInt(Enumeration const value) -> typename std::underlying_type< Enumeration >::type
constexpr std::enable_if< II==sizeof...(Tp), void >::type for_each_tuple(std::tuple< Tp... > &, FuncT)
agent base center linear velocity is parametric function
EvalArcGuarantee
Flags if any guarantees about evaluation arc relative to last evaluation arc are present.
virtual void simulateTrajectory(double _lastValidArc=0)=0
Simulates (discrete numerical evaluation) an entire trajectory according to the specified intervals a...
std::shared_ptr< TrajectorySimulator > TrajectorySimulatorSPtr
int main(int argc, char **argv)
CtrlPtDim
Control point variable dimension.
std::shared_ptr< StateSim > StateSimPtr
double ds_
Arc parametrization interval used for the equal distance lattice.
FuncEvalMode
Required type of computation relative to the parametric function.