12#ifndef STATEOBSERVATIONDEFINITIONSHPP
13#define STATEOBSERVATIONDEFINITIONSHPP
22#ifdef STATEOBSERVATION_VERBOUS_CONSTRUCTORS
26#include <boost/assert.hpp>
27#include <boost/timer/timer.hpp>
30#include <Eigen/Geometry>
33# include <boost/math/constants/constants.hpp>
34# define M_PI boost::math::constants::pi<double>()
37#include <state-observation/api.h>
50 static constexpr bool value = std::is_base_of<Eigen::EigenBase<T>, T>::value;
60template<
typename _Scalar,
int _Rows,
int _Cols,
int _Options,
int _MaxRows,
int _MaxCols>
61struct isMatrix<Eigen::
Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>> : std::true_type
66struct EigenType : std::enable_if<isEigen<T>::value, T>
79typedef Eigen::Matrix<double, 1, 1>
Vector1;
82typedef Eigen::Matrix<double, 2, 1>
Vector2;
94typedef Eigen::Matrix<double, 5, 1>
Vector5;
97typedef Eigen::Matrix<double, 6, 1>
Vector6;
138typedef Eigen::Index Index;
139typedef long int TimeIndex;
140typedef Index TimeSize;
143static const bool isDebug =
true;
145static const bool isDebug =
false;
148template<
int compileTimeRows = -1,
int compileTimeCols = -1>
152 template<
typename CustomNullaryOp>
153 static const Eigen::CwiseNullaryOp<CustomNullaryOp, typename Eigen::Matrix<double, compileTimeRows, compileTimeCols>>
154 nullaryExp(
const CustomNullaryOp & func, Index rows = compileTimeRows, Index cols = compileTimeCols)
160 return Eigen::Matrix<double, compileTimeRows, compileTimeCols>::NullaryExpr(func);
164template<
int compileTimeCols>
168 template<
typename CustomNullaryOp>
169 static const Eigen::CwiseNullaryOp<CustomNullaryOp,
typename Eigen::Matrix<double, -1, compileTimeCols>>
nullaryExp(
170 const CustomNullaryOp & func,
172 Index cols = compileTimeCols)
174 return Eigen::Matrix<double, -1, compileTimeCols>::NullaryExpr(rows, cols, func);
178template<
int compileTimeRows>
182 template<
typename CustomNullaryOp>
183 static const Eigen::CwiseNullaryOp<CustomNullaryOp,
typename Eigen::Matrix<double, compileTimeRows, -1>>
nullaryExp(
184 const CustomNullaryOp & func,
185 Index rows = compileTimeRows,
188 return Eigen::Matrix<double, compileTimeRows, -1>::NullaryExpr(rows, cols, func);
196 template<
typename CustomNullaryOp>
197 static const Eigen::CwiseNullaryOp<CustomNullaryOp,
typename Eigen::Matrix<double, -1, -1>>
nullaryExp(
198 const CustomNullaryOp & func,
202 return Eigen::Matrix<double, -1, -1>::NullaryExpr(rows, cols, func);
206template<
typename MatrixT>
208 MatrixType<MatrixT>::type::ColsAtCompileTime>
214template<
typename T, const T defaultValue = T()>
221template<
typename T, const T defaultValue>
222const T DebugItemDefaultValue<T, defaultValue>::v = defaultValue;
235template<errorType i = message,
int dummy = 0>
244 static const char * v;
251 static const std::runtime_error v;
258 static const std::runtime_error * v;
263 If this happened during initialization then run command chckitm_set() \
264 to switch it to set. And if the initialization is incomplete, run \
265 chckitm_reset() afterwards.";
278void STATE_OBSERVATION_DLLAPI defaultSum(
const Vector & stateVector,
const Vector & tangentVector,
Vector & sum);
279void STATE_OBSERVATION_DLLAPI defaultDifference(
const Vector & stateVector1,
280 const Vector & stateVector2,
287template<
typename T,
typename defaultValue = DebugItemDefaultValue<T>,
bool debug = true>
291 DebugItem() : b_(defaultValue::v) {}
292 explicit DebugItem(
const T & v) : b_(v) {}
293 inline T & operator=(T v)
297 inline operator T()
const
301 inline T set(
const T & v)
315template<
typename T,
typename defaultValue>
316class DebugItem<T, defaultValue, false>
320 explicit DebugItem(T) {}
326 inline operator T()
const
328 return defaultValue::v;
330 inline T set(
const T &)
332 return defaultValue::v;
336 return defaultValue::v;
349 static bool check(
const T &)
354 static bool checkAssert(
const T &)
358 inline static constexpr char errorMessage[] =
"";
359 using ExceptionT = std::runtime_error;
374 bool alwaysCheck =
false,
375 bool assertion =
true,
376 bool eigenAlignedNew =
false,
388 inline T & operator=(
const T &);
389 inline operator T()
const;
390 inline operator const T &()
const;
392 inline const T & chckitm_getValue()
const;
394 inline T & operator()();
395 inline const T & operator()()
const;
397 inline T & getRefUnchecked();
398 inline const T & getRefUnchecked()
const;
400 inline bool isSet()
const;
404 inline void set(
bool value);
406 void setAssertMessage(std::string s);
407 void setExceptionPtr(std::exception * e);
416 static const bool do_check_ = !lazy || isDebug;
417 static const bool do_assert_ = do_check_ && assertion;
418 static const bool do_exception_ = do_check_ && !assertion;
425 AssertMsg assertMsg_;
426 ExceptionPtr exceptionPtr_;
428 bool chckitm_check_()
const;
432 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(eigenAlignedNew)
439 static bool check(
const T & m)
444 static bool checkAssert(
const T & m)
446 BOOST_ASSERT(check(m) && errorMessage);
449 inline static constexpr char errorMessage[] =
"Matrix contains a NaN.";
450 using ExceptionT = std::runtime_error;
468template<
typename MatrixType = Matrix,
bool lazy = false>
469class IndexedMatrixT :
protected DebugItem<bool, detail::defaultTrue, !lazy || isDebug>
471 typedef DebugItem<bool, detail::defaultTrue, !lazy || isDebug> IsSet;
484 inline void set(
bool value =
true);
504 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
526template<
typename MatrixType = Matrix,
typename Allocator = std::allocator<MatrixType>>
539 typedef std::vector<MatrixType, Allocator> Array;
595 inline TimeSize size()
const;
614 void readFromFile(
const char * filename, Index rows, Index cols = 1,
bool withTimeStamp =
true);
615 void readFromFile(
const std::string & filename, Index rows, Index cols = 1,
bool withTimeStamp =
true);
639 typedef std::deque<MatrixType, Allocator> Deque;
643 inline void check_(TimeIndex time)
const;
663constexpr double gravityConstant = 9.80665;
672constexpr double epsilon1 = std::numeric_limits<double>::epsilon();
694typedef boost::timer::auto_cpu_timer auto_cpu_timer;
695typedef boost::timer::cpu_timer cpu_timer;
696typedef boost::timer::cpu_timer cpu_times;
703 using clock =
typename std::conditional<std::chrono::high_resolution_clock::is_steady,
704 std::chrono::high_resolution_clock,
705 std::chrono::steady_clock>::type;
706 using time_ns = clock::time_point;
711 startTime = clock::now();
718 auto elapsed = clock::now() - startTime;
719 return static_cast<double>(elapsed.count());
723std::string STATE_OBSERVATION_DLLAPI matrixToString(
const Matrix & mat);
725std::string STATE_OBSERVATION_DLLAPI vectorToString(
const Vector & v);
727Matrix STATE_OBSERVATION_DLLAPI stringToMatrix(
const std::string & str, Index rows, Index cols);
729Vector STATE_OBSERVATION_DLLAPI stringToVector(
const std::string & str, Index length);
731Vector STATE_OBSERVATION_DLLAPI stringToVector(
const std::string & str);
734#include <state-observation/tools/definitions.hxx>
this is a structure allowing for automatically verifying that the item has been initialized or not....
CheckedItem(bool initialize=true)
The parameter initialize sets whether the isSet() parameter is initialized to false.
void set(bool value)
set the value of the initialization check boolean
This class describes a structure that enables to store array of matrices with time indexation.
TimeIndex setLastIndex(int index)
Set the time index of the last element.
TimeIndex getNextIndex() const
void truncateAfter(TimeIndex timeIndex)
removes all the elements with larger indexes than timeIndex
void checkNext_(TimeIndex time) const
void writeInFile(const std::string &filename, bool clear=false, bool append=false)
TimeIndex setFirstIndex(int index)
set the time index of the first element
MatrixType & back()
gets the last value
void truncateBefore(TimeIndex timeIndex)
removes all the elements with smaller indexes than timeIndex
void clear()
Clears the vector but keeps the last index.
bool checkIndex(TimeIndex k) const
checks whether the index is present in the array
void writeInFile(const char *filename, bool clear=false, bool append=false)
void pushBack(const MatrixType &v)
Pushes back the matrix to the array, the new value will take the next time.
void check_(TimeIndex time) const
MatrixType operator[](TimeIndex index) const
gets the value with the given time index
MatrixType & front()
gets the first value
void popFront()
removes the first (oldest) element of the array
IndexedMatrixArrayT(TimeSize size, TimeIndex initTime=0)
Construct a new Indexed Vector Array T with a predifined size.
void resize(TimeSize i, const MatrixType &m=MatrixType())
resizes the array
const MatrixType & front() const
gets the first value
void setValue(const MatrixType &v, TimeIndex k)
IndexedMatrixArrayT()
Default constructor.
TimeIndex getFirstIndex() const
Get the time index.
void readFromFile(const char *filename, Index rows, Index cols=1, bool withTimeStamp=true)
const MatrixType & back() const
gets the last value
TimeIndex getLastIndex() const
Get the time index.
MatrixType & operator[](TimeIndex index)
gets the value with the given time index, non const version
void readVectorsFromFile(const std::string &filename, bool withTimeStamp=true)
Array getArray() const
converts the array into a standard vector
This class describes a structure composed by a matrix of a given size and a time-index parameter....
void setIndex(TimeIndex index)
set the index of the matrix
IndexedMatrixT & set(const MatrixType &v, TimeIndex k)
Set the value of the matrix and the time sample.
IndexedMatrixT(const MatrixType &v, TimeIndex k)
A constructor with a given matrix value and a time index.
MatrixType & operator()()
Get the matrix value.
IndexedMatrixT()
Default constructor.
TimeIndex getTime() const
Get the time index.
void reset()
Switch off the initalization flag, the value is no longer accessible.
const MatrixType & operator()() const
Get the matrix value (const version).
bool isSet() const
Says whether the matrix is initialized or not.
void set(bool value=true)
Switch the vector to "initialized" state.
constexpr double epsilonAngle
angles considered Zero
const Vector gravity
Gravity Vector along Z.
constexpr double epsilon1
number considered zero when compared to 1
Filtering of divergent component of motion (DCM) and estimation of a bias betweeen the DCM and the co...
Eigen::Matrix4d Matrix4
4x4 Scalar Matrix
Eigen::AngleAxis< double > AngleAxis
Euler Axis/Angle representation of orientation.
Eigen::Quaterniond Quaternion
Quaternion.
bool isApprox(double a, double b, double relativePrecision=cst::epsilon1)
checks if two scalars have approximately the same value up to a given relative precision
Eigen::Matrix< double, 3, 3, Eigen::DontAlign > Matrix3Unaligned
3x3 Scalar Matrix Unaligned
bool isApproxAbs(double a, double b, double absolutePrecision=cst::epsilon1)
checks if two scalars have approximately the same value up to a given absolute precision
Eigen::Rotation2D< double > Rotation2D
2D rotations
Eigen::Matrix2d Matrix2
2D scalar Matrix
Eigen::Vector3d Vector3
3D vector
Eigen::Vector4d Vector4
4D vector
Eigen::Matrix< double, 1, 1 > Vector1
1D Vector
Eigen::Matrix3d Matrix3
3x3 Scalar Matrix
Eigen::MatrixXd Matrix
Dynamic sized Matrix.
Eigen::Matrix< double, 5, 1 > Vector5
5D vector
Eigen::Matrix< double, 6, 1 > Vector6
6D vector
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vector3Unaligned
3D vector unaligned
Eigen::Matrix< double, 6, 6 > Matrix6
6x6 Scalar Matrix
Eigen::Matrix< double, 5, 5 > Matrix5
5x5 Scalar Matrix
Eigen::Matrix< double, 12, 12 > Matrix12
12x12 scalar Matrix
Eigen::Matrix< double, 2, 1 > Vector2
2d Vector
Eigen::VectorXd Vector
Dynamic sized scalar vector.
Eigen::Quaternion< double, Eigen::DontAlign > QuaternionUnaligned
Quaternion Unaligned.
Eigen::Matrix< double, 1, 1 > Matrix1
1D scalar Matrix
Additional checker that allows to check for the presence of NaN values in the item.
This structure is used as an additionalChecker for a CheckedItem that doesn't require additional test...
Checks if it is derived from EigenBase (the base class of all dense functions).
Checks if a class is a specialization of Eigen::Matrix.