dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
assertions.h
Go to the documentation of this file.
1 /*
2  * assertions.hpp
3  *
4  * Created on: Aug 6, 2009
5  * Author: Jonathan Brandmeyer
6  *
7  * This file is part of libeknav, imported into the OpenPilot
8  * project by Jonathan Brandmeyer.
9  *
10  * Libeknav is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, version 3.
13  *
14  * Libeknav is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18 
19  * You should have received a copy of the GNU General Public License
20  * along with libeknav. If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23 
24 #ifndef AHRS_ASSERTIONS_HPP
25 #define AHRS_ASSERTIONS_HPP
26 
27 #include <Eigen/Core>
28 #include <cmath>
29 
30 template <typename MatrixBase>
31 bool hasNaN(const MatrixBase &expr);
32 
33 template <typename MatrixBase>
34 bool hasInf(const MatrixBase &expr);
35 
36 template <typename MatrixBase>
37 bool perpendicular(const MatrixBase &expl, const MatrixBase &expr);
38 
39 template <typename MatrixBase>
40 bool hasNaN(const MatrixBase &expr)
41 {
42  for (int j = 0; j != expr.cols(); ++j) {
43  for (int i = 0; i != expr.rows(); ++i) {
44  if (std::isnan(expr.coeff(i, j)))
45  return true;
46  }
47  }
48  return false;
49 }
50 
51 template <typename MatrixBase>
52 bool hasInf(const MatrixBase &expr)
53 {
54  for (int i = 0; i != expr.cols(); ++i) {
55  for (int j = 0; j != expr.rows(); ++j) {
56  if (std::isinf(expr.coeff(j, i)))
57  return true;
58  }
59  }
60  return false;
61 }
62 
63 template <typename MatrixBase>
64 bool isReal(const MatrixBase &exp)
65 {
66  return !hasNaN(exp) && !hasInf(exp);
67 }
68 
69 template <typename MatrixBase>
70 bool perpendicular(const MatrixBase &lhs, const MatrixBase &rhs)
71 {
72  // A really weak check for "almost perpendicular". Use it for debugging
73  // purposes only.
74  return fabs(rhs.dot(lhs)) < 0.0001;
75 }
76 
77 #endif /* ASSERTIONS_HPP_ */
for i
Definition: OPPlots.m:140
bool perpendicular(const MatrixBase &expl, const MatrixBase &expr)
Definition: assertions.h:70
bool hasInf(const MatrixBase &expr)
Definition: assertions.h:52
bool hasNaN(const MatrixBase &expr)
Definition: assertions.h:40
bool isReal(const MatrixBase &exp)
Definition: assertions.h:64