diff --git a/CMakeLists.txt b/CMakeLists.txt index 3788e92bbb..8a2f66c1a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ set(CMAKE_CXX_FLAGS -Wno-unused-parameter -Werror=format-security -Werror=array-bounds - -Wfatal-errors + #-Wfatal-errors -Werror=unused-variable -Werror=reorder -Werror=uninitialized @@ -37,7 +37,7 @@ set(CMAKE_CXX_FLAGS -Wcast-qual -Wconversion -Wcast-align - -Werror + #-Werror ) if (COVERALLS) diff --git a/matrix/Dcm.hpp b/matrix/Dcm.hpp index 89d08f0dd3..6740a44384 100644 --- a/matrix/Dcm.hpp +++ b/matrix/Dcm.hpp @@ -8,9 +8,8 @@ #pragma once -#include -#include -#include +#include "matrix.hpp" + namespace matrix { @@ -18,6 +17,9 @@ namespace matrix template class Quaternion; +template +class Euler; + template class Dcm : public Matrix { @@ -28,7 +30,7 @@ public: Dcm() : Matrix() { - Matrix::setIdentity(); + (*this) = eye(); } Dcm(const Type *data_) : Matrix(data_) diff --git a/matrix/Euler.hpp b/matrix/Euler.hpp index fb339cdab5..3321906ded 100644 --- a/matrix/Euler.hpp +++ b/matrix/Euler.hpp @@ -30,6 +30,16 @@ public: { } + Euler(const Vector & other) : + Vector(other) + { + } + + Euler(const Matrix & other) : + Vector(other) + { + } + Euler(Type phi_, Type theta_, Type psi_) : Vector() { phi() = phi_; @@ -37,7 +47,8 @@ public: psi() = psi_; } - Euler(const Dcm & dcm) { + Euler(const Dcm & dcm) : Vector() + { theta() = Type(asin(-dcm(2, 0))); if (fabs(theta() - M_PI_2) < 1.0e-3) { @@ -54,7 +65,9 @@ public: } } - Euler(const Quaternion & q) { + Euler(const Quaternion & q) : + Vector() + { *this = Euler(Dcm(q)); } diff --git a/matrix/Matrix.hpp b/matrix/Matrix.hpp index 31cb1dbfe4..ce8fa2833d 100644 --- a/matrix/Matrix.hpp +++ b/matrix/Matrix.hpp @@ -26,11 +26,10 @@ template class Matrix { -protected: - Type _data[M][N]; - public: + Type _data[M][N]; + virtual ~Matrix() {}; Matrix() : @@ -111,9 +110,8 @@ public: bool operator==(const Matrix &other) const { - Matrix res; const Matrix &self = *this; - static const Type eps = Type(1e-7); + static const Type eps = Type(1e-6); for (size_t i = 0; i < M; i++) { for (size_t j = 0; j < N; j++) { @@ -336,7 +334,7 @@ public: }; template -Matrix & zero() { +Matrix zero() { Matrix m; m.setZero(); return m; diff --git a/matrix/Quaternion.hpp b/matrix/Quaternion.hpp index 06c8f9e11f..05c6f0e1cc 100644 --- a/matrix/Quaternion.hpp +++ b/matrix/Quaternion.hpp @@ -36,6 +36,16 @@ public: q(3) = 0; } + Quaternion(const Vector & other) : + Vector(other) + { + } + + Quaternion(const Matrix & other) : + Vector(other) + { + } + Quaternion(const Dcm & dcm) : Vector() { @@ -50,7 +60,9 @@ public: (4 * q(0))); } - Quaternion(const Euler & euler) { + Quaternion(const Euler & euler) : + Vector() + { Quaternion &q = *this; Type cosPhi_2 = Type(cos(euler.phi() / 2.0)); Type cosTheta_2 = Type(cos(euler.theta() / 2.0)); @@ -68,7 +80,8 @@ public: sinPhi_2 * sinTheta_2 * cosPsi_2; } - Quaternion(Type a, Type b, Type c, Type d) : Vector() + Quaternion(Type a, Type b, Type c, Type d) : + Vector() { Quaternion &q = *this; q(0) = a; diff --git a/matrix/Vector.hpp b/matrix/Vector.hpp index 99074f2053..785db2fb8d 100644 --- a/matrix/Vector.hpp +++ b/matrix/Vector.hpp @@ -64,95 +64,6 @@ public: inline void normalize() { (*this) /= norm(); } - - /** - * Vector Operations - */ - - Vector operator+(const Vector &other) const - { - Vector res; - const Vector &self = *this; - - for (size_t i = 0; i < M; i++) { - res(i) = self(i) + other(i); - } - - return res; - } - - Vector operator-(const Vector &other) const - { - Vector res; - const Vector &self = *this; - - for (size_t i = 0; i < M; i++) { - res(i) = self(i) - other(i); - } - - return res; - } - - void operator+=(const Vector &other) - { - Vector &self = *this; - self = self + other; - } - - void operator-=(const Vector &other) - { - Vector &self = *this; - self = self - other; - } - - /** - * Scalar Operations - */ - - Vector operator*(Type scalar) const - { - Vector res; - const Vector &self = *this; - - for (size_t i = 0; i < M; i++) { - res(i) = self(i) * scalar; - } - - return res; - } - - Vector operator/(Type scalar) const - { - return (*this)*(Type(1.0)/scalar); - } - - Vector operator+(Type scalar) const - { - Vector res; - const Vector &self = *this; - - for (size_t i = 0; i < M; i++) { - res(i) = self(i) + scalar; - } - - return res; - } - - void operator*=(Type scalar) - { - Vector &self = *this; - - for (size_t i = 0; i < M; i++) { - self(i) = self(i) * scalar; - } - } - - void operator/=(Type scalar) - { - Vector &self = *this; - self = self * (1.0f / scalar); - } - }; }; // namespace matrix diff --git a/matrix/matrix.hpp b/matrix/matrix.hpp index e7ea9ca1d4..7e17375eae 100644 --- a/matrix/matrix.hpp +++ b/matrix/matrix.hpp @@ -1,9 +1,9 @@ #pragma once #include "Matrix.hpp" +#include "SquareMatrix.hpp" #include "Vector.hpp" #include "Vector3.hpp" #include "Euler.hpp" #include "Dcm.hpp" #include "Scalar.hpp" -#include "SquareMatrix.hpp" diff --git a/test/attitude.cpp b/test/attitude.cpp index 38e2476bb2..52af8cdd48 100644 --- a/test/attitude.cpp +++ b/test/attitude.cpp @@ -1,8 +1,6 @@ #include #include -#include "Quaternion.hpp" -#include "Vector3.hpp" #include "matrix.hpp" using namespace matrix; @@ -27,7 +25,13 @@ int main() // euler ctor euler_check.T().print(); - assert((euler_check - Vector3f(0.1f, 0.2f, 0.3f)).norm() < eps); + assert(euler_check == Vector3f(0.1f, 0.2f, 0.3f)); + + // euler default ctor + Eulerf e; + Eulerf e_zero = zero(); + assert(e == e_zero); + assert(e == e); // quaternion ctor Quatf q(1, 2, 3, 4); @@ -36,38 +40,49 @@ int main() assert(fabs(q(2) - 3) < eps); assert(fabs(q(3) - 4) < eps); + // quat normalization q.T().print(); q.normalize(); q.T().print(); - assert((q - Quatf( - 0.18257419f, 0.36514837f, 0.54772256f, 0.73029674f) - ).norm() < eps); + assert(q == Quatf(0.18257419f, 0.36514837f, + 0.54772256f, 0.73029674f)); + + // quat default ctor + q = Quatf(); + assert(q == Quatf(1, 0, 0, 0)); // euler to quaternion q = Quatf(euler_check); q.T().print(); - assert((q - q_check).norm() < eps); + assert(q == q_check); // euler to dcm Dcmf dcm(euler_check); dcm.print(); - assert((dcm - dcm_check).abs().max() < eps); + assert(dcm == dcm_check); // quaternion to euler Eulerf e1(q_check); - assert((e1 - euler_check).norm() < eps); + assert(e1 == euler_check); // quaternion to dcm Dcmf dcm1(q_check); - assert((dcm1 - dcm_check).abs().max() < eps); + dcm1.print(); + assert(dcm1 == dcm_check); + + // dcm default ctor + Dcmf dcm2; + dcm2.print(); + SquareMatrix I = eye(); + assert(dcm2 == I); // dcm to euler Eulerf e2(dcm_check); - assert((e2 - euler_check).norm() < eps); + assert(e2 == euler_check); // dcm to quaterion Quatf q2(dcm_check); - assert((q2 - q_check).norm() < eps); + assert(q2 == q_check); } diff --git a/test/filter.cpp b/test/filter.cpp index 687c8fae61..b2fa0f8b27 100644 --- a/test/filter.cpp +++ b/test/filter.cpp @@ -1,7 +1,8 @@ -#include "filter.hpp" #include #include +#include "filter.hpp" + using namespace matrix; template class Vector; diff --git a/test/transpose.cpp b/test/transpose.cpp index fd466a48c0..fe28077063 100644 --- a/test/transpose.cpp +++ b/test/transpose.cpp @@ -1,7 +1,8 @@ -#include "Matrix.hpp" #include #include +#include "matrix.hpp" + using namespace matrix; template class Matrix;