EKF: Eliminate use of power function to square numbers

Use of the power function to square a number can be very inefficient depending on processor and compiler. Replace with an inlined function  that multiplies the number by itself. This has not been put into the maths library because the use of the sq() function is peculiar to the autocode generated for the EKF and an inlined function was desired.
This commit is contained in:
Paul Riseborough 2016-02-08 10:58:25 +11:00
parent 42a943b37e
commit 2c8c6efb45
2 changed files with 6 additions and 4 deletions

View File

@ -44,8 +44,6 @@
#include <math.h>
#include <mathlib/mathlib.h>
#define sq(_arg) powf(_arg, 2.0f)
void Ekf::initialiseCovariance()
{
for (unsigned i = 0; i < _k_num_states; i++) {

View File

@ -42,8 +42,6 @@
#include "estimator_interface.h"
#define sq(_arg) powf(_arg, 2.0f)
class Ekf : public EstimatorInterface
{
public:
@ -202,4 +200,10 @@ private:
// Determine if we are airborne or motors are armed
void calculateVehicleStatus();
// return the square of two foating point numbers - used in autocoded sections
inline float sq(float var)
{
return var * var;
}
};