avoid double promotions

This commit is contained in:
Daniel Agar
2017-03-18 22:00:29 -04:00
committed by Lorenz Meier
parent 412f956636
commit 4b8bedef48
12 changed files with 53 additions and 60 deletions
@@ -37,16 +37,14 @@
* @author Lorenz Meier <lorenz@px4.io>
*/
#include <px4_defines.h>
#include "estimator_22states.h"
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <px4_defines.h>
#include <mathlib/mathlib.h>
#include <cmath>
#ifndef M_PI_F
#define M_PI_F static_cast<float>(M_PI)
#endif
using std::cos;
using std::sin;
#define MIN_AIRSPEED_MEAS 5.0f
@@ -1855,7 +1853,7 @@ void AttPosEKF::FuseOptFlow()
Vector3f relVelSensor;
// Perform sequential fusion of optical flow measurements only with valid tilt and height
flowStates[1] = fmax(flowStates[1], statesAtFlowTime[9] + minFlowRng);
flowStates[1] = math::max(flowStates[1], statesAtFlowTime[9] + minFlowRng);
float heightAboveGndEst = flowStates[1] - statesAtFlowTime[9];
bool validTilt = Tnb.z.z > 0.71f;
if (validTilt)
@@ -2114,7 +2112,7 @@ void AttPosEKF::OpticalFlowEKF()
} else {
return;
}
distanceTravelledSq = fmin(distanceTravelledSq, 100.0f);
distanceTravelledSq = math::min(distanceTravelledSq, 100.0f);
Popt[1][1] += (distanceTravelledSq * sq(gndHgtSigma));
}
@@ -2154,7 +2152,7 @@ void AttPosEKF::OpticalFlowEKF()
varInnovRng = 1.0f/SK_RNG[1];
// constrain terrain height to be below the vehicle
flowStates[1] = fmax(flowStates[1], statesAtRngTime[9] + minFlowRng);
flowStates[1] = math::max(flowStates[1], statesAtRngTime[9] + minFlowRng);
// estimate range to centre of image
range = (flowStates[1] - statesAtRngTime[9]) * SK_RNG[2];
@@ -2174,7 +2172,7 @@ void AttPosEKF::OpticalFlowEKF()
}
// constrain the states
flowStates[0] = ConstrainFloat(flowStates[0], 0.1f, 10.0f);
flowStates[1] = fmax(flowStates[1], statesAtRngTime[9] + minFlowRng);
flowStates[1] = math::max(flowStates[1], statesAtRngTime[9] + minFlowRng);
// correct the covariance matrix
float nextPopt[2][2];
@@ -2183,8 +2181,8 @@ void AttPosEKF::OpticalFlowEKF()
nextPopt[1][0] = -Popt[1][0]*((Popt[1][1]*SK_RNG[1]*SK_RNG[2]) * SK_RNG[2] - 1.0f);
nextPopt[1][1] = -Popt[1][1]*((Popt[1][1]*SK_RNG[1]*SK_RNG[2]) * SK_RNG[2] - 1.0f);
// prevent the state variances from becoming negative and maintain symmetry
Popt[0][0] = fmax(nextPopt[0][0],0.0f);
Popt[1][1] = fmax(nextPopt[1][1],0.0f);
Popt[0][0] = math::max(nextPopt[0][0],0.0f);
Popt[1][1] = math::max(nextPopt[1][1],0.0f);
Popt[0][1] = 0.5f * (nextPopt[0][1] + nextPopt[1][0]);
Popt[1][0] = Popt[0][1];
}
@@ -2223,7 +2221,7 @@ void AttPosEKF::OpticalFlowEKF()
vel.z = statesAtFlowTime[6];
// constrain terrain height to be below the vehicle
flowStates[1] = fmax(flowStates[1], statesAtFlowTime[9] + minFlowRng);
flowStates[1] = math::max(flowStates[1], statesAtFlowTime[9] + minFlowRng);
// estimate range to centre of image
range = (flowStates[1] - statesAtFlowTime[9]) / Tnb_flow.z.z;
@@ -2291,7 +2289,7 @@ void AttPosEKF::OpticalFlowEKF()
}
// constrain the states
flowStates[0] = ConstrainFloat(flowStates[0], 0.1f, 10.0f);
flowStates[1] = fmax(flowStates[1], statesAtFlowTime[9] + minFlowRng);
flowStates[1] = math::max(flowStates[1], statesAtFlowTime[9] + minFlowRng);
// correct the covariance matrix
for (uint8_t i = 0; i < 2 ; i++) {
@@ -2307,8 +2305,8 @@ void AttPosEKF::OpticalFlowEKF()
}
// prevent the state variances from becoming negative and maintain symmetry
Popt[0][0] = fmax(nextPopt[0][0],0.0f);
Popt[1][1] = fmax(nextPopt[1][1],0.0f);
Popt[0][0] = math::max(nextPopt[0][0],0.0f);
Popt[1][1] = math::max(nextPopt[1][1],0.0f);
Popt[0][1] = 0.5f * (nextPopt[0][1] + nextPopt[1][0]);
Popt[1][0] = Popt[0][1];
}
@@ -76,7 +76,7 @@ void swap_var(float &d1, float &d2);
float Vector3f::length() const
{
return sqrt(x*x + y*y + z*z);
return sqrtf(x*x + y*y + z*z);
}
void Vector3f::zero()