Helios++
Helios software for LiDAR simulations
FunctionalPlatformTest.h
1 #pragma once
2 
3 #include "BaseTest.h"
4 #include <platform/InterpolatedMovingPlatform.h>
5 
6 namespace HeliosTests{
7 
19 public:
23  double eps = 0.0001; // Decimal precision for validation purposes
24 
25  // *** CONSTRUCTOR *** //
26  // ********************* //
30  FunctionalPlatformTest() : BaseTest("Functional platform test") {}
31  virtual ~FunctionalPlatformTest() = default;
32 
33  // *** R U N *** //
34  // *************** //
38  bool run() override;
39 
40  // *** SUB-TESTS *** //
41  // ******************* //
47 };
48 
49 // *** R U N *** //
50 // *************** //
52  if(!testInterpolatedMovingPlatform()) return false;
53  return true;
54 }
55 
56 // *** SUB-TESTS *** //
57 // ******************* //
59  // Prepare what is necessary to build the InterpolatedMovingPlatform
60  int simFreq = 10;
61  std::function<void(void)> simulationFunction = [] (void) -> void {};
62  SimulationStepLoop stepLoop(simulationFunction);
63  stepLoop.setFrequency(simFreq);
65  arma::Mat<double>(
66  "0.0 -6 -2 0;"
67  "0.2 -4 2 0;"
68  "0.3 -3 3 0;"
69  "0.5 -1 4 0;"
70  "0.7 1 4 0;"
71  "0.8 2 2 1;"
72  "0.9 3 1 1;"
73  "1.1 5 1 1;"
74  "1.2 6 -1 1"
75  ),
76  0,
77  "t",
78  vector<string>({"t", "x", "y", "z"})
79  );
82  stepLoop,
83  tdm,
84  ddm,
85  InterpolatedMovingPlatform::InterpolationScope::POSITION,
86  false,
87  0.0
88  );
89 
90  // Validate InterpolatedMovingPlatform
91  arma::Mat<double> impE( // Expected output
92  "-6 -2 0;" // t=0.0
93  "-5 0 0;" // t=0.1
94  "-4 2 0;" // t=0.2
95  "-3 3 0;" // t=0.3
96  "-2 3.5 0;" // t=0.4
97  "-1 4 0;" // t=0.5
98  "0 4 0;" // t=0.6
99  "1 4 0;" // t=0.7
100  "2 2 1;" // t=0.8
101  "3 1 1;" // t=0.9
102  "4 1 1;" // t=1.0
103  "5 1 1;" // t=1.1
104  "6 -1 1;" // t=1.2
105  );
106  for(size_t i = 0 ; i < impE.n_rows ; ++i){
107  imp.doSimStep(simFreq);
108  if(std::fabs(stepLoop.getCurrentTime()-((double)i)/10.0) > eps)
109  return false;
110  glm::dvec3 _impPos = imp.getPosition();
111  arma::Col<double> impPos(3);
112  impPos[0] = _impPos.x; impPos[1] = _impPos.y; impPos[2] = _impPos.z;
113  if(arma::any((impPos-impE.row(i).as_col()) > eps)) return false;
114  stepLoop.nextStep();
115  }
116 
117  // Return true on success
118  return true;
119 }
120 
121 }
BaseTest class.
Definition: BaseTest.h:20
Functional platform test.
Definition: FunctionalPlatformTest.h:18
bool run() override
Definition: FunctionalPlatformTest.h:51
bool testInterpolatedMovingPlatform()
Test the InterpolatingMovingPlatform.
Definition: FunctionalPlatformTest.h:58
FunctionalPlatformTest()
Functional platform test constructor.
Definition: FunctionalPlatformTest.h:30
double eps
Decimal precision for validation purposes.
Definition: FunctionalPlatformTest.h:23
Class representing a MovingPlatform which position is defined by a function interpolated from a Desig...
Definition: InterpolatedMovingPlatform.h:23
void doSimStep(int simFrequency_hz) override
Definition: InterpolatedMovingPlatform.cpp:106
void nextStep() override
Advances to current loop iteration without cyclic behavior.
Definition: LinearVoidStepLoop.h:48
glm::dvec3 getPosition() const
Obtain platform position.
Definition: Platform.h:376
Class extending LinearVoidStepLoop to support main simulation loop.
Definition: SimulationStepLoop.h:15
void setFrequency(std::size_t const frequency)
Definition: SimulationStepLoop.h:46
double getCurrentTime() const
Obtain the virtual time (simulation time) that elapsed to reach current step.
Definition: SimulationStepLoop.h:67
The heart of a differential design matrix is the idea that the columns are defining the values of var...
Definition: DiffDesignMatrix.h:169
This class represents a DesignMatrix where each row satisfy that its elements can be placed into a co...
Definition: TemporalDesignMatrix.h:74
DiffDesignMatrix< TimeType, VarType > toDiffDesignMatrix(DiffDesignMatrixType diffType=DiffDesignMatrixType::FORWARD_FINITE_DIFFERENCES, bool const sort=true) const
Build a DiffDesignMatrix from the TemporalDesignMatrix.