mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 08:03:33 +08:00
Added more warnings, and fixed issues.
This commit is contained in:
+1
-1
@@ -31,7 +31,7 @@ public:
|
||||
Matrix<Type, 3, 3>::setIdentity();
|
||||
}
|
||||
|
||||
Dcm(const Type *data) : Matrix<Type, 3, 3>(data)
|
||||
Dcm(const Type *data_) : Matrix<Type, 3, 3>(data_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
+13
-18
@@ -30,33 +30,28 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
Euler(Type phi, Type theta, Type psi) : Vector<Type, 3>()
|
||||
Euler(Type phi_, Type theta_, Type psi_) : Vector<Type, 3>()
|
||||
{
|
||||
this->phi() = phi;
|
||||
this->theta() = theta;
|
||||
this->psi() = psi;
|
||||
phi() = phi_;
|
||||
theta() = theta_;
|
||||
psi() = psi_;
|
||||
}
|
||||
|
||||
Euler(const Dcm<Type> & dcm) {
|
||||
Type theta = asin(-dcm(2, 0));
|
||||
Type phi = 0;
|
||||
Type psi = 0;
|
||||
theta() = Type(asin(-dcm(2, 0)));
|
||||
|
||||
if (fabs(theta - M_PI_2) < 1.0e-3) {
|
||||
psi = atan2(dcm(1, 2) - dcm(0, 1),
|
||||
dcm(0, 2) + dcm(1, 1));
|
||||
if (fabs(theta() - M_PI_2) < 1.0e-3) {
|
||||
psi() = Type(atan2(dcm(1, 2) - dcm(0, 1),
|
||||
dcm(0, 2) + dcm(1, 1)));
|
||||
|
||||
} else if (fabs(theta + M_PI_2) < 1.0e-3) {
|
||||
psi = atan2(dcm(1, 2) - dcm(0, 1),
|
||||
dcm(0, 2) + dcm(1, 1));
|
||||
} else if (fabs(theta() + M_PI_2) < 1.0e-3) {
|
||||
psi() = Type(atan2(dcm(1, 2) - dcm(0, 1),
|
||||
dcm(0, 2) + dcm(1, 1)));
|
||||
|
||||
} else {
|
||||
phi = atan2f(dcm(2, 1), dcm(2, 2));
|
||||
psi = atan2f(dcm(1, 0), dcm(0, 0));
|
||||
phi() = Type(atan2f(dcm(2, 1), dcm(2, 2)));
|
||||
psi() = Type(atan2f(dcm(1, 0), dcm(0, 0)));
|
||||
}
|
||||
this->phi() = phi;
|
||||
this->theta() = theta;
|
||||
this->psi() = psi;
|
||||
}
|
||||
|
||||
Euler(const Quaternion<Type> & q) {
|
||||
|
||||
+13
-12
@@ -38,10 +38,10 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
Matrix(const Type *data) :
|
||||
Matrix(const Type *data_) :
|
||||
_data()
|
||||
{
|
||||
memcpy(_data, data, sizeof(_data));
|
||||
memcpy(_data, data_, sizeof(_data));
|
||||
}
|
||||
|
||||
Matrix(const Matrix &other) :
|
||||
@@ -113,10 +113,11 @@ public:
|
||||
{
|
||||
Matrix<Type, M, N> res;
|
||||
const Matrix<Type, M, N> &self = *this;
|
||||
static const Type eps = Type(1e-7);
|
||||
|
||||
for (size_t i = 0; i < M; i++) {
|
||||
for (size_t j = 0; j < N; j++) {
|
||||
if (self(i , j) != other(i, j)) {
|
||||
if (fabs(self(i , j) - other(i, j)) > eps) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -298,7 +299,7 @@ public:
|
||||
Matrix<Type, M, N> r;
|
||||
for (int i=0; i<M; i++) {
|
||||
for (int j=0; j<M; j++) {
|
||||
r(i,j) = fabs((*this)(i,j));
|
||||
r(i,j) = Type(fabs((*this)(i,j)));
|
||||
}
|
||||
}
|
||||
return r;
|
||||
@@ -306,30 +307,30 @@ public:
|
||||
|
||||
Type max()
|
||||
{
|
||||
Type max = (*this)(0,0);
|
||||
Type max_val = (*this)(0,0);
|
||||
for (int i=0; i<M; i++) {
|
||||
for (int j=0; j<M; j++) {
|
||||
Type val = (*this)(i,j);
|
||||
if (val > max) {
|
||||
max = val;
|
||||
if (val > max_val) {
|
||||
max_val = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
return max;
|
||||
return max_val;
|
||||
}
|
||||
|
||||
Type min()
|
||||
{
|
||||
Type min = (*this)(0,0);
|
||||
Type min_val = (*this)(0,0);
|
||||
for (int i=0; i<M; i++) {
|
||||
for (int j=0; j<M; j++) {
|
||||
Type val = (*this)(i,j);
|
||||
if (val < min) {
|
||||
min = val;
|
||||
if (val < min_val) {
|
||||
min_val = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
return min;
|
||||
return min_val;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
+15
-15
@@ -40,24 +40,24 @@ public:
|
||||
Vector<Type, 4>()
|
||||
{
|
||||
Quaternion &q = *this;
|
||||
q(0) = 0.5 * sqrt(1 + dcm(0, 0) +
|
||||
dcm(1, 1) + dcm(2, 2));
|
||||
q(1) = (dcm(2, 1) - dcm(1, 2)) /
|
||||
(4 * q(0));
|
||||
q(2) = (dcm(0, 2) - dcm(2, 0)) /
|
||||
(4 * q(0));
|
||||
q(3) = (dcm(1, 0) - dcm(0, 1)) /
|
||||
(4 * q(0));
|
||||
q(0) = Type(0.5 * sqrt(1 + dcm(0, 0) +
|
||||
dcm(1, 1) + dcm(2, 2)));
|
||||
q(1) = Type((dcm(2, 1) - dcm(1, 2)) /
|
||||
(4 * q(0)));
|
||||
q(2) = Type((dcm(0, 2) - dcm(2, 0)) /
|
||||
(4 * q(0)));
|
||||
q(3) = Type((dcm(1, 0) - dcm(0, 1)) /
|
||||
(4 * q(0)));
|
||||
}
|
||||
|
||||
Quaternion(const Euler<Type> & euler) {
|
||||
Quaternion &q = *this;
|
||||
Type cosPhi_2 = cos(euler.phi() / 2.0);
|
||||
Type cosTheta_2 = cos(euler.theta() / 2.0);
|
||||
Type cosPsi_2 = cos(euler.psi() / 2.0);
|
||||
Type sinPhi_2 = sin(euler.phi() / 2.0);
|
||||
Type sinTheta_2 = sin(euler.theta() / 2.0);
|
||||
Type sinPsi_2 = sin(euler.psi() / 2.0);
|
||||
Type cosPhi_2 = Type(cos(euler.phi() / 2.0));
|
||||
Type cosTheta_2 = Type(cos(euler.theta() / 2.0));
|
||||
Type cosPsi_2 = Type(cos(euler.psi() / 2.0));
|
||||
Type sinPhi_2 = Type(sin(euler.phi() / 2.0));
|
||||
Type sinTheta_2 = Type(sin(euler.theta() / 2.0));
|
||||
Type sinPsi_2 = Type(sin(euler.psi() / 2.0));
|
||||
q(0) = cosPhi_2 * cosTheta_2 * cosPsi_2 +
|
||||
sinPhi_2 * sinTheta_2 * sinPsi_2;
|
||||
q(1) = sinPhi_2 * cosTheta_2 * cosPsi_2 -
|
||||
@@ -102,7 +102,7 @@ public:
|
||||
v(1) = w(0);
|
||||
v(2) = w(1);
|
||||
v(3) = w(2);
|
||||
return Q * v * 0.5;
|
||||
return Q * v * Type(0.5);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
SquareMatrix(const Type *data) :
|
||||
Matrix<Type, M, M>(data)
|
||||
SquareMatrix(const Type *data_) :
|
||||
Matrix<Type, M, M>(data_)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public:
|
||||
SquareMatrix<float, M> res;
|
||||
res.setIdentity();
|
||||
SquareMatrix<float, M> A_pow = *this;
|
||||
float k_fact = 1;
|
||||
size_t k_fact = 1;
|
||||
size_t k = 1;
|
||||
|
||||
while (k < n) {
|
||||
|
||||
+1
-15
@@ -58,7 +58,7 @@ public:
|
||||
|
||||
Type norm() const {
|
||||
const Vector &a(*this);
|
||||
return sqrt(a.dot(a));
|
||||
return Type(sqrt(a.dot(a)));
|
||||
}
|
||||
|
||||
inline void normalize() {
|
||||
@@ -81,20 +81,6 @@ public:
|
||||
return res;
|
||||
}
|
||||
|
||||
bool operator==(const Vector<Type, M> &other) const
|
||||
{
|
||||
Vector<Type, M> res;
|
||||
const Vector<Type, M> &self = *this;
|
||||
|
||||
for (size_t i = 0; i < M; i++) {
|
||||
if (self(i) != other(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector<Type, M> operator-(const Vector<Type, M> &other) const
|
||||
{
|
||||
Vector<Type, M> res;
|
||||
|
||||
Reference in New Issue
Block a user