Helios++
Helios software for LiDAR simulations
Platform.h
1 #pragma once
2 
3 
4 #include <fstream>
5 
6 #include <glm/glm.hpp>
7 
8 #include "Asset.h"
9 #include "PlatformSettings.h"
10 #include "maths/Rotation.h"
11 #include "Scene.h"
12 #include <NoiseSource.h>
13 #include "Directions.h"
14 #ifdef PYTHON_BINDING
15 #include <PythonDVec3.h>
16 #endif
17 
21 class Platform : public Asset {
22 public:
23  // *** ATTRIBUTES *** //
24  // ******************** //
25  // platform configuration
29  glm::dvec3 cfg_device_relativeMountPosition = glm::dvec3(0, 0, 0);
34  glm::dvec3(0, 1, 0), 0
35  );
36 
37  // misc stuff
41  double lastCheckZ = 0;
45  glm::dvec3 lastGroundCheck = glm::dvec3(0, 0, 0);
49  std::shared_ptr<Scene> scene = nullptr;
50 
51  // Noise generators
55  std::shared_ptr<NoiseSource<double>> positionXNoiseSource = nullptr;
59  std::shared_ptr<NoiseSource<double>> positionYNoiseSource = nullptr;
63  std::shared_ptr<NoiseSource<double>> positionZNoiseSource = nullptr;
67  std::shared_ptr<NoiseSource<double>> attitudeXNoiseSource = nullptr;
71  std::shared_ptr<NoiseSource<double>> attitudeYNoiseSource = nullptr;
75  std::shared_ptr<NoiseSource<double>> attitudeZNoiseSource = nullptr;
76 
77  // Output file writer stuff
81  double dmax = std::numeric_limits<double>::max();
85  glm::dvec3 prevWrittenPos = glm::dvec3(dmax, dmax, dmax);
86 
87  // Platform Settings
96  glm::dvec3 originWaypoint = glm::dvec3(0, 0, 0);
100  glm::dvec3 targetWaypoint = glm::dvec3(0, 0, 0);
105  glm::dvec3 nextWaypoint = glm::dvec3(0, 0, 0);
106 
111  bool onGround = false;
117  bool stopAndTurn = false;
123  bool smoothTurn = false;
129  bool slowdownEnabled = true;
130 
131  // State variables
135  glm::dvec3 position = glm::dvec3(0, 0, 0);
140 
149  bool writeNextTrajectory = true;
150 
151 
152  // *** CACHE ATTRIBUTES *** //
153  // ************************** //
157  glm::dvec3 cached_absoluteMountPosition = glm::dvec3(0, 0, 0);
161  Rotation cached_absoluteMountAttitude = Rotation(glm::dvec3(0, 1, 0), 0);
162 
166  glm::dvec3 cached_dir_current = glm::dvec3(0, 0, 0);
170  glm::dvec3 cached_dir_current_xy = glm::dvec3(0, 0, 0);
171 
175  glm::dvec3 cached_vectorToTarget = glm::dvec3(0, 0, 0);
180  glm::dvec3 cached_vectorToTarget_xy = glm::dvec3(0, 0, 0);
181 
186 
191  glm::dvec3 cached_originToTargetDir_xy = glm::dvec3(0, 0, 0);
196  glm::dvec3 cached_targetToNextDir_xy = glm::dvec3(0, 0, 0);
217 
218 
219  // *** CONSTRUCTION / DESTRUCTION *** //
220  // ************************************ //
224  Platform() = default;
225  virtual std::shared_ptr<Platform> clone();
226  virtual void _clone(std::shared_ptr<Platform> p);
227 
228 
229  // *** M E T H O D S *** //
230  // *********************** //
235  virtual void prepareSimulation(int simFrequency_hz) {updateStaticCache();}
240  virtual void prepareLeg(int const simFrequency_hz) {}
246  virtual void applySettings(
247  std::shared_ptr<PlatformSettings> settings,
248  bool manual
249  );
256  std::shared_ptr<PlatformSettings> retrieveCurrentSettings();
257 
263  virtual void updateStaticCache();
270  void updateDynamicCache();
277  virtual bool waypointReached();
278 
284  virtual void doSimStep(int simFrequency_hz){}
285 
289  virtual void initLegManual() {}
290 
294  virtual void initLeg() {}
295 
296 
297  // *** GETTERS and SETTERS *** //
298  // ***************************** //
303  virtual void setAttitude(Rotation attitude);
308  virtual void setOrigin(glm::dvec3 origin);
313  virtual void setDestination(glm::dvec3 dest);
318  virtual void setAfterDestination(glm::dvec3 next);
323  void setPosition(glm::dvec3 pos);
328  void setOffset(glm::dvec3 pos);
329 
336  }
337 
342  inline glm::dvec3 getAbsoluteMountPosition() const {
344  }
345 
350  inline Rotation getAttitude() const {
351  return this->attitude;
352  }
363  return this->attitude;
364  }
368  virtual glm::dvec3 getCurrentDirection(){
370  }
371 
376  inline glm::dvec3 getPosition() const {
377  return position;
378  }
379 
384  inline glm::dvec3 getVectorToTarget() const {
385  return cached_vectorToTarget;
386  }
387 
395  virtual inline void getRollPitchYaw(
396  double &roll, double &pitch, double &yaw
397  ) {attitude.getAngles(&RotationOrder::XYZ, roll, pitch, yaw);}
398 
404  virtual void setHeadingRad(double rad) {}
410  virtual double getHeadingRad() {return 0;}
411 
416  virtual glm::dvec3 getVelocity() {return glm::dvec3(0,0,0);}
421  virtual bool canMove() const {return false;}
427  virtual bool canStopAndTurn() const {return false;}
432  virtual bool isInterpolated() const {return false;}
433 
434 };
Base class for all assets.
Definition: Asset.h:10
static const glm::dvec3 forward
y : forward-backward direction
Definition: Directions.h:22
static const glm::dvec3 up
z : up-down direction
Definition: Directions.h:26
Class representing a platform asset.
Definition: Platform.h:21
void updateDynamicCache()
Cache update which must be performed between simulation steps and after static modifications....
Definition: Platform.cpp:144
void setOffset(glm::dvec3 pos)
Set platform position.
virtual void setAfterDestination(glm::dvec3 next)
Set platform after destination way point.
Definition: Platform.cpp:104
bool stopAndTurn
Flag to specify if platform must work in stop and turn mode (true) or not (false)....
Definition: Platform.h:117
virtual double getHeadingRad()
Obtain platform heading angle in radians, which can be understood as yaw in most cases.
Definition: Platform.h:410
Rotation attitude
Platform 3D attitude.
Definition: Platform.h:139
glm::dvec3 cached_absoluteMountPosition
Cached absolute mount position.
Definition: Platform.h:157
double cfg_settings_movePerSec_m
How meters per seconds the platform moves. NOTICE this behavior must be overridden by platforms imple...
Definition: Platform.h:92
std::shared_ptr< Scene > scene
Scene where the platform belongs to.
Definition: Platform.h:49
virtual void setAttitude(Rotation attitude)
Set platform attitude.
Definition: Platform.cpp:89
double lastCheckZ
Not used at the moment. Might be removed in the future.
Definition: Platform.h:41
glm::dvec3 cached_vectorToTarget_xy
Distance vector from current position to target over XY plane (z is always 0)
Definition: Platform.h:180
glm::dvec3 cached_originToTargetDir_xy
Director vector from origin to target over the XY plane (z is always 0).
Definition: Platform.h:191
virtual glm::dvec3 getVelocity()
Obtain platform velocity vector.
Definition: Platform.h:416
void setPosition(glm::dvec3 pos)
Set platform position.
Definition: Platform.cpp:108
virtual void updateStaticCache()
Cache update which only needs to be performed after static modifications. Updating static cache also ...
Definition: Platform.cpp:113
virtual Rotation getDirectionalAttitude()
Obtain the directional attitude. While the attitude represents the platform orientation,...
Definition: Platform.h:362
virtual void prepareSimulation(int simFrequency_hz)
Prepare the platform to deal with simulation.
Definition: Platform.h:235
virtual bool canStopAndTurn() const
Check if platform support stop and turn mode (true) or not (false)
Definition: Platform.h:427
virtual void initLeg()
Function to initialize leg when working in default mode.
Definition: Platform.h:294
double cached_originToTargetAngle_xy
Angle in which identifies director vector from origin waypoint to target waypoint.
Definition: Platform.h:211
glm::dvec3 cached_vectorToTarget
Distance vector from current position to target.
Definition: Platform.h:175
double cached_endTargetAngle_xy
Angle between director vector from origin to target and director vector from target to waypoint after...
Definition: Platform.h:201
bool onGround
Flag to specify if the platform must be placed on ground (true) or not (false)
Definition: Platform.h:111
virtual void getRollPitchYaw(double &roll, double &pitch, double &yaw)
Obtain platform roll, pitch and yaw angles. Notice not all platforms track those angles.
Definition: Platform.h:395
bool smoothTurn
Flag to specify if platform must work in smooth turn mode (true) or not (false). Not all platforms su...
Definition: Platform.h:123
Platform()=default
Default platform constructor.
double cached_targetToNextAngle_xy
Angle in which identifies director vector from target waypoint to waypoint after target.
Definition: Platform.h:216
bool slowdownEnabled
Flag to specify if slowdown stage must be enabled (true) or not (false). Not all platforms have a slo...
Definition: Platform.h:129
Rotation getAbsoluteMountAttitude() const
Obtain platform absolute mount attitude.
Definition: Platform.h:334
bool writeNextTrajectory
Flag to specify if next trajectory needs to be written (true) or not (false)
Definition: Platform.h:149
virtual void prepareLeg(int const simFrequency_hz)
Prepare the platform to deal with the next leg.
Definition: Platform.h:240
Rotation getAttitude() const
Obtain platform attitude.
Definition: Platform.h:350
glm::dvec3 getAbsoluteMountPosition() const
Obtain platform absolute mount position.
Definition: Platform.h:342
glm::dvec3 cached_targetToNextDir_xy
Director vector from target to after target waypoint over the XY plane (z is always 0).
Definition: Platform.h:196
double dmax
Not used at the moment. Might be removed in the future.
Definition: Platform.h:81
glm::dvec3 position
Platform 3D position.
Definition: Platform.h:135
glm::dvec3 lastGroundCheck
Not used at the moment. Might be removed in the future.
Definition: Platform.h:45
glm::dvec3 cfg_device_relativeMountPosition
Device mount position relative to the platform.
Definition: Platform.h:29
glm::dvec3 getVectorToTarget() const
Obtain platform vector to target (cache)
Definition: Platform.h:384
glm::dvec3 targetWaypoint
Target waypoint (destination)
Definition: Platform.h:100
virtual bool waypointReached()
Check if platform has reached its destination way point (true) or not (false)
Definition: Platform.cpp:164
glm::dvec3 nextWaypoint
Waypoint after target. For the last target, waypoint after target is equal to the target itself.
Definition: Platform.h:105
std::shared_ptr< NoiseSource< double > > attitudeYNoiseSource
Noise source for y component of platform attitude.
Definition: Platform.h:71
bool mSetOrientationOnLegInit
Not used at the moment. Might be removed in the future.
Definition: Platform.h:144
virtual glm::dvec3 getCurrentDirection()
Obtain platform current direction.
Definition: Platform.h:368
glm::dvec3 originWaypoint
Origin waypoint.
Definition: Platform.h:96
glm::dvec3 cached_dir_current_xy
Current director vector over XY plane (z is always 0)
Definition: Platform.h:170
virtual void setHeadingRad(double rad)
Set the heading angle in radians. This angle can be understood as yaw in most cases.
Definition: Platform.h:404
glm::dvec3 prevWrittenPos
Not used at the moment. Might be removed in the future.
Definition: Platform.h:85
std::shared_ptr< PlatformSettings > retrieveCurrentSettings()
Retrieve current platform settings and build a new PlatformSettings object with them.
Definition: Platform.cpp:78
virtual void applySettings(std::shared_ptr< PlatformSettings > settings, bool manual)
Apply given platform settings to the platform.
Definition: Platform.cpp:68
std::shared_ptr< NoiseSource< double > > attitudeZNoiseSource
Noise source for z component of platform attitude.
Definition: Platform.h:75
Rotation cached_absoluteMountAttitude
Cached absolute mount attitude.
Definition: Platform.h:161
virtual void setDestination(glm::dvec3 dest)
Set platform destination way point.
Definition: Platform.cpp:100
virtual bool isInterpolated() const
Check if platform is simulated (false) or interpolated (true)
Definition: Platform.h:432
std::shared_ptr< NoiseSource< double > > positionXNoiseSource
Noise source for x component of platform position.
Definition: Platform.h:55
std::shared_ptr< NoiseSource< double > > positionZNoiseSource
Noise source for z component of platform position.
Definition: Platform.h:63
virtual void initLegManual()
Function to initialize leg when working in manual mode.
Definition: Platform.h:289
glm::dvec3 getPosition() const
Obtain platform position.
Definition: Platform.h:376
double cached_currentAngle_xy
Angle between current director vector and director vector from target to waypoint after target.
Definition: Platform.h:206
Rotation cfg_device_relativeMountAttitude
Device mount attitude relative to the platform.
Definition: Platform.h:33
std::shared_ptr< NoiseSource< double > > attitudeXNoiseSource
Noise source for x component of platform attitude.
Definition: Platform.h:67
double cached_distanceToTarget_xy
Distance on XY plane between current position and target.
Definition: Platform.h:185
std::shared_ptr< NoiseSource< double > > positionYNoiseSource
Noise source for y component of platform position.
Definition: Platform.h:59
virtual void setOrigin(glm::dvec3 origin)
Set platform origin way point.
Definition: Platform.cpp:96
glm::dvec3 cached_dir_current
Current director vector over XY plane.
Definition: Platform.h:166
virtual bool canMove() const
Check if platform can move (true) or not (false)
Definition: Platform.h:421
virtual void doSimStep(int simFrequency_hz)
Do corresponding computations for the platform at current simulation step.
Definition: Platform.h:284
static const RotationOrder XYZ
Definition: RotationOrder.h:48
Definition: Rotation.h:80
void getAngles(RotationOrder const *order, double &roll, double &pitch, double &yaw)
Get the roll, pitch and yaw for the Rotation.
Definition: Rotation.cpp:360
glm::dvec3 applyTo(glm::dvec3 u)
Definition: Rotation.cpp:250