trajectory_simulator.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2016 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 TRAJECTORY_SIMULATOR_H
34 #define TRAJECTORY_SIMULATOR_H
35 
39 
40 #include <functional>
41 #include <memory>
42 
43 namespace tuw
44 {
45 class TrajectorySimulator;
46 using TrajectorySimulatorSPtr = std::shared_ptr<TrajectorySimulator>;
47 using TrajectorySimulatorConstSPtr = std::shared_ptr<TrajectorySimulator const>;
48 using TrajectorySimulatorUPtr = std::unique_ptr<TrajectorySimulator>;
49 using TrajectorySimulatorConstUPtr = std::unique_ptr<TrajectorySimulator const>;
50 
52 {
53  // enums
55 public:
56  enum class SimMode
57  {
58  ONLINE,
59  PRECALC
62  };
65 public:
66  enum class BaseSimLatticeType : signed int
67  {
68  ARC_BG_BK = -3,
69  LATTICE_ARC_EQ_DT = -2,
70  LATTICE_ARC_EQ_DS = -1,
71  LATTICE_ENUM_SIZE = 3
72  };
73  static constexpr const std::size_t extArcLatIdxBegin =
75 
77 public:
78  struct LatticePoint
79  {
80  LatticePoint() : arc(-1), statePtr(nullptr)
81  {
82  }
83  LatticePoint(double _arc) : arc(_arc), statePtr(nullptr)
84  {
85  }
86  LatticePoint(double _arc, StateSPtr& _statePtr) : arc(_arc), statePtr(_statePtr)
87  {
88  }
89  virtual ~LatticePoint()
90  {
91  }
92  double arc;
94  };
95 
96  using LatticeVec = std::vector<LatticePoint>;
97  using LatticeVecSPtr = std::shared_ptr<std::vector<LatticePoint> >;
98  using LatticeVecSPtrVec = std::vector<std::shared_ptr<std::vector<LatticePoint> > >;
99 
101 public:
103  {
104  LatticePointType() : LatticePoint(), latticeType(-5)
105  {
106  }
107  LatticePointType(double _arc, int _latticeType) : LatticePoint(_arc), latticeType(_latticeType)
108  {
109  }
110  LatticePointType(double _arc, int _latticeType, StateSPtr& _statePtr)
111  : LatticePoint(_arc, _statePtr), latticeType(_latticeType)
112  {
113  }
115  };
116 
117 public:
119 
120  // special class member functions
121 public:
122  TrajectorySimulator(StateSimPtr _stateSim);
123 
124 public:
125  TrajectorySimulator(StateSimPtr _stateSim, std::unique_ptr<CostsEvaluatorClass> _costsEvaluator);
126 
127 public:
128  virtual ~TrajectorySimulator() = default;
129 
130 public:
131  TrajectorySimulator(const TrajectorySimulator&) = default;
132 
133 public:
135 
136 public:
138 
139 public:
141 
142 public:
143  void setBoolDtScale(const bool& _doScale);
144 
145 public:
146  void setBoolDsScale(const bool& _doScale);
147 
149 public:
150  double& dtBase();
152 public:
153  const double& dt() const;
155 public:
156  double& dsBase();
158 public:
159  const double& ds() const;
161 public:
164 public:
165  const StateSimPtr stateSim() const;
167 public:
168  std::vector<LatticePointType>& simLattice();
170 public:
171  const std::vector<LatticePointType>& simLattice() const;
173 public:
174  void setUserDefLattice(const std::vector<std::vector<double*> >& _userDefLattices);
175 
176 public:
177  void updateUserDefLattice();
178 
179  // pure virtual function
187 public:
188  virtual void simulateTrajectory(double _lastValidArc = 0) = 0;
189 
191 protected:
192  virtual void populatePartSimLatticesDtOnly(const size_t& _firstLaticeInvalidIdx, double _arcParamMax);
195 protected:
196  virtual void populatePartSimLatticesGeneral(size_t _firstLaticeInvalidIdx, double _arcParamMax,
197  double _minArcLatticeVal) = 0;
198 
201 protected:
202  void simAppendToSimPartLat(const double& _arcNow, const int& _latticePtType, const std::size_t& _minArcLatCacheIdx);
204 protected:
205  void appendToPartLat(const double& _arcNow, const int& _latticePtType, const std::size_t& _minArcLatCacheIdx);
207 protected:
208  void setBeginStateToLattices(const double& _arcBegin);
210 protected:
211  void setEndStateToLattices(const double& _arcEnd);
213 protected:
214  void setBeginEndArcsToLattices(const double& _arcBegin, const double& _arcEnd);
215 
218 protected:
219  bool initSimLatticeState0(const double& _lastValidArc, size_t& _firstLaticeInvalidIdx);
221 protected:
222  void initExtLatticeCache(const double& _minArcLatticeVal);
224 protected:
225  void populateTrajSimPartLattice(const size_t& _firstLaticeInvalidIdx);
226 
228 protected:
229  bool isEmptyAllExtLattices() const;
231 public:
232  static size_t lattTypeIdx(int _enumIdx);
233 
234 protected:
235  void computeScaleDtDs();
236 
238 protected:
241 public:
242  std::vector<LatticePointType> simulationLattice_;
244 public:
248 protected:
249  std::vector<int> partLatIdxCache_;
251 protected:
254 private:
255  double dt_;
257 private:
258  double ds_;
259 
260 private:
261  double dtBase_;
262 
263 private:
264  double dsBase_;
265 
266 protected:
267  bool scaleDt_;
268 
269 protected:
270  bool scaleDs_;
271 
272 private:
273  std::vector<std::vector<double*> > userDefPartLattices_;
274 
275 public:
276  std::unique_ptr<CostsEvaluatorClass> costsEvaluator_;
277 
278  friend class TrajectorySimGrade;
279  // public : size_t partLatticeActiveSize_;
280 };
281 }
282 
283 #endif // TRAJECTORY_SIMULATOR_H
StateSimPtr stateSim_
State simulator object.
const double & dt() const
Const reference to arc parametrization interval used for the equal arc-length lattice.
std::shared_ptr< std::vector< LatticePoint > > LatticeVecSPtr
LatticeVecSPtrVec partLattices_
Vector containing the ordered sequence of arc parametrizations for each of the used lattices...
std::vector< LatticePointType > simulationLattice_
Lattice requesting each simulated trajectory state.
void populateTrajSimPartLattice(const size_t &_firstLaticeInvalidIdx)
Main function that performs resizing, reserving and calls the proper population function.
void setBeginEndArcsToLattices(const double &_arcBegin, const double &_arcEnd)
Sets begin and end arcs to all partial lattices on the first and last container positions.
std::vector< int > partLatIdxCache_
Vector containing cached container indices for each partial lattice related to the the highest arc lo...
void initExtLatticeCache(const double &_minArcLatticeVal)
Initializes the cached partial lattices index at the highest arc lower than.
double & dtBase()
Reference to arc parametrization interval used for the equal arc-length lattice.
bool isEmptyAllExtLattices() const
Returns true if all extended lattices are empty (the DS lattice as well as user-defined lattices)...
void setUserDefLattice(const std::vector< std::vector< double *> > &_userDefLattices)
virtual void populatePartSimLatticesGeneral(size_t _firstLaticeInvalidIdx, double _arcParamMax, double _minArcLatticeVal)=0
Performs simulation and populates simulation and partial lattices in the general case of various enab...
void setBoolDsScale(const bool &_doScale)
LatticePoint(double _arc, StateSPtr &_statePtr)
std::unique_ptr< CostsEvaluatorClass > costsEvaluator_
std::shared_ptr< TrajectorySimulator const > TrajectorySimulatorConstSPtr
void appendToPartLat(const double &_arcNow, const int &_latticePtType, const std::size_t &_minArcLatCacheIdx)
Appends the new arc and state pointer to the afferent partial lattice point.
Structure containing the lattice type afferent to a.
constexpr auto asInt(Enumeration const value) -> typename std::underlying_type< Enumeration >::type
Definition: utils.h:87
void setBeginStateToLattices(const double &_arcBegin)
Binds reference to the initial simulated state (at.
std::unique_ptr< TrajectorySimulator > TrajectorySimulatorUPtr
std::vector< LatticePoint > LatticeVec
bool initSimLatticeState0(const double &_lastValidArc, size_t &_firstLaticeInvalidIdx)
Initializes the simulation lattice (truncation from the.
double dt_
Arc parametrization interval used for the equal arc-length lattice.
std::vector< std::vector< double * > > userDefPartLattices_
std::vector< LatticePointType > & simLattice()
Reference to the lattice that requested each simulated trajectory state.
virtual void populatePartSimLatticesDtOnly(const size_t &_firstLaticeInvalidIdx, double _arcParamMax)
Performs simulation and populates simulation and partial lattice when only equal dt lattice is enable...
LatticePointType(double _arc, int _latticeType)
BaseSimLatticeType
Fundamental lattice types.
LatticePointType(double _arc, int _latticeType, StateSPtr &_statePtr)
static constexpr const std::size_t extArcLatIdxBegin
Structure containing an evaluation arc and a state pointer.
bool canComputeDistLattice_
Flags if the StateSim object has access to the StateSimDist functionality.
TrajectorySimulator(StateSimPtr _stateSim)
TrajectorySimulator & operator=(const TrajectorySimulator &)=default
void setBoolDtScale(const bool &_doScale)
void setEndStateToLattices(const double &_arcEnd)
Binds reference to the final simulated state (at.
SimMode
Mode of the simulation.
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
std::unique_ptr< TrajectorySimulator const > TrajectorySimulatorConstUPtr
std::vector< std::shared_ptr< std::vector< LatticePoint > > > LatticeVecSPtrVec
const double & ds() const
Const reference to arc parametrization interval used for the equal distance lattice.
std::shared_ptr< StateSim > StateSimPtr
double ds_
Arc parametrization interval used for the equal distance lattice.
StateSimPtr stateSim()
Reference of the state simulator object.
void simAppendToSimPartLat(const double &_arcNow, const int &_latticePtType, const std::size_t &_minArcLatCacheIdx)
Performs a simulation step (if.
std::shared_ptr< StateType > StateSPtr
virtual ~TrajectorySimulator()=default
double & dsBase()
Reference to arc parametrization interval used for the equal distance lattice.
static size_t lattTypeIdx(int _enumIdx)
Converts shifted (int) lattice index to container (size_t) index.


tuw_control
Author(s): George Todoran
autogenerated on Mon Feb 28 2022 23:52:16