Commit Graph

438 Commits

Author SHA1 Message Date
Lucas De Marchi 4f8d2059f8 AP_Math: use right epsilon for is_equal()
We are calling fabsf(), which returns a float. We should use the epsilon
from float type, not from the argument type passed to fabsf().

On the other hand when the double version is instantiated we do want to
use the std::numeric_limits<double>::epsilon() value.

This adds a branch to the function, but it's removed when the function
is intantiated by the compiler since the type is known at compile-time.

Fixes this warning when building for PX4:
../../libraries/AP_Math/AP_Math.cpp: In instantiation of 'typename std::enable_if<std::is_floating_point<typename std::common_type<_Tp, _Up>::type>::value, bool>::type is_equal(Arithmetic1, Arithmetic2) [with Arithmetic1 = double; Arithmetic2 = double; typename std::enable_if<std::is_floating_point<typename std::common_type<_Tp, _Up>::type>::value, bool>::type = bool]':
../../libraries/AP_Math/AP_Math.cpp:23:66:   required from here
../../libraries/AP_Math/AP_Math.cpp:17:29: warning: implicit conversion from 'float' to 'double' to match other operand of binary expression [-Wdouble-promotion]
     return fabsf(v_1 - v_2) < std::numeric_limits<decltype(v_1 - v_2)>::epsilon();
                             ^
2017-01-27 12:15:19 -08:00
murata ec4cce15a1 AP_Math: Unify from print or println to printf. 2017-01-27 18:20:22 +11:00
Andrew Tridgell 67a2441b12 AP_Math: started a set of crc functions
these functions are often common between drivers
2017-01-27 18:11:29 +11:00
murata e903cb9945 AP_Math: Change mask value to hexadecimal number. 2017-01-17 10:20:15 -08:00
Pierre Kancir 47f1a754c5 AP_Math: add some test for vector2 equality test 2016-12-20 14:09:04 +00:00
Pierre Kancir eae093cd2a AP_Math: add test for is_equal for int 2016-12-20 14:09:04 +00:00
Pierre Kancir da49149d19 AP_Math: is_equal correct comparison for integer as epsilon doesn't exist.
Credit to Kwikius for the right solution
2016-12-20 14:09:04 +00:00
Pierre Kancir ce734b5f7b AP_Math: Remove unecessary check 2016-12-19 14:36:03 +00:00
Pierre Kancir 556993d7f0 AP_Math: Vector2 add == operator for int 2016-12-06 09:31:21 -08:00
Pierre Kancir 6bf1322633 AP_Math: polygon.cpp correct float comparison 2016-12-06 09:31:21 -08:00
Pierre Kancir 79a9e8dfad AP_Math: Matrix_alg fix implicite cast from bool to float 2016-12-05 12:39:31 -08:00
Pierre Kancir fb7a00799f AP_Math: quaternion fix missing return 2016-12-05 10:33:41 -08:00
Andrew Tridgell a8d10e8c2c AP_Math: added get_random16() 2016-12-02 09:49:38 +11:00
murata f9add59b58 Global: Aggregate the same definitions.
Global: Aggregate the same definitions.
2016-11-09 11:46:55 -03:00
Andrew Tridgell b00fd95725 AP_Math: define Vector3l for += op 2016-11-09 17:08:13 +11:00
murata c808ee2f49 Global: To nullptr from NULL.
RC_Channel: To nullptr from NULL.

AC_Fence: To nullptr from NULL.

AC_Avoidance: To nullptr from NULL.

AC_PrecLand: To nullptr from NULL.

DataFlash: To nullptr from NULL.

SITL: To nullptr from NULL.

GCS_MAVLink: To nullptr from NULL.

DataFlash: To nullptr from NULL.

AP_Compass: To nullptr from NULL.

Global: To nullptr from NULL.

Global: To nullptr from NULL.
2016-11-02 16:04:47 -02:00
Mathieu OTHACEHE 152edf7189 Global: remove mode line from headers
Using a global .dir-locals.el file is a better alternative than
reincluding the same emacs header in every file of the project.
2016-10-24 09:42:01 -02:00
Jonathan Challinger 80d9092993 AP_Math: remove rotateXY and rotateXYinv 2016-10-13 10:02:14 +11:00
Lucas De Marchi ae53920e5b build: don't build examples with old build system
We currently check examples are buildable with waf which doesn't need
the libraries to be specified in a make.inc file.  Having the makefiles
there is misleading since people try to build and realize the build is
broken.
2016-10-11 13:03:08 +11:00
Lucas De Marchi 0d4caa3ccc AP_Math: remove declaration of not implemented functions 2016-08-03 00:16:35 -03:00
Murilo Belluzzo 70942472d3 AP_Math: Matrix: Change deallocator to match allocator used 2016-08-03 00:09:11 -03:00
Lucas De Marchi 7b7e73680f AP_Math: add USEC_PER_MSEC 2016-07-30 00:55:28 -03:00
Peter Barker 2047d53470 Math: move closest_point in from AC_Avoid 2016-07-25 20:24:37 +09:00
Peter Barker 779f78d471 AP_Math: vector3 perpendicular function 2016-07-25 20:24:37 +09:00
Peter Barker f6cb0ffb6f AP_Math: add Vector2f perpendicular
Add closest_distance_between_radial_and_point function
2016-07-25 20:24:37 +09:00
Peter Barker b6d0b028c3 AP_Math: add operator[] to Vector2 2016-07-25 20:24:37 +09:00
Daniel Ricketts 249d95b413 AP_Math: add Polygon_outside and Polygon_complete functions 2016-06-25 15:55:55 +09:00
Leonard Hall e0eecd56b2 AP_Math: use is_zero and float constants 2016-06-24 16:16:34 +09:00
Leonard Hall 7f933140c7 AP_Math: small formatting fix to quaternion rotation_matrix
No functional change
2016-06-24 16:16:33 +09:00
Leonard Hall 8afd29cc85 AP_Math: add quaternion::rotation_matrix_norm 2016-06-24 16:16:28 +09:00
Pierre Kancir a8e5ff93b5 AP_Math: Correct missing declaration warning 2016-06-21 12:17:46 -03:00
Tom Pittenger 00aaa78757 AP_Math: add separate check_lat() and check_lng() 2016-06-06 13:02:56 -07:00
Andrew Tridgell 3969bde84a AP_Math: fixed coverity warning in example 2016-06-05 07:20:46 +10:00
Peter Barker cb16d0b6c6 AP_Math: correct examples build on px4 2016-06-04 12:31:36 -03:00
Tom Pittenger 7b4c503052 AP_Math: use new check_latlng helper 2016-06-01 17:38:48 -07:00
Tom Pittenger ce9ecf9f3d AP_Math: added check_latlng helper 2016-06-01 17:38:48 -07:00
Gustavo Jose de Sousa ef61096e08 AP_Math: geodesic_grid tool: show triangle number for sections too 2016-05-18 13:28:52 -03:00
Gustavo Jose de Sousa a6deb65d95 AP_Math: geodesic_grid tool: add option --section 2016-05-18 13:28:52 -03:00
Lucas De Marchi 1ac712fa65 AP_Math: fix is_zero() after template conversion 2016-05-17 15:49:29 -07:00
Lucas De Marchi fa6f2c6b67 AP_Math: fix some coding style mistakes
- fix alignement of &
    - remove const from bool arguments
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa 390b196eda AP_Math: AP_GeodesicGrid: add notice for auto generated code 2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa b3068baa11 AP_Math: add geodesic_grid toolset
That was used to aid development AP_GeodesicGrid and understanding its
concepts.
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa 9d34b3b996 AP_Math: AP_GeodesicGrid: make all methods static
Since all members are.
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa 3b05ec1157 AP_Math: make vectors and matrix constructors constexpr
That allows some object to be constructed at compile time.
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa 77223a7fcb AP_Math: AP_GeodesicGrid: make data static
That gives the change of storing that data in flash storage in some
architectures. That doesn't happen yet though, some extra changes are required
for that to happen.
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa fd2428db34 AP_Math: AP_GeodesicGrid: reduce number of _neighbor_umbrellas items
Only the first half is necessary. The values for the other half can be derived.
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa 43d9e00ab7 AP_Math: AP_GeodesicGrid: use uint8_t for _neighbor_umbrellas
All integers there are limited to the range [0,20), so uint8_t is enough.
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa 54889e4175 AP_Math: AP_GeodesicGrid: reduce number of inverses by half
We don't actually need all of them, since the second half is for the opposite
triangles. In that case we just need to negate the resulting vector when
changing basis.
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa f31161ecb6 AP_Math: AP_GeodesicGrid: remove triangles
There's no need to keep those triangles, since we just need the inverses.
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa b34c04a4f9 AP_Math: test_geodesic_grid: test also non-centroid vectors 2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa 8e8ab3af96 AP_Math: AP_GeodesicGrid: remove section_triangle() function
That function was only being used by the unit tests and the benchmark. In order
to remove memory usage, the triangles will be removed, since we don't actually
need to keep them in real situations. Thus, this patch removes that function
and copy those triangles to the test and benchmark.
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa c7eb46fae2 AP_Math: AP_GeodesicGrid: optimize _from_neighbor_umbrella()
This is the second optimization. With that we don't have to iterate over the
umbrella's components.

The table below summarizes the mean CPU time in ns from the brenchmark results
on an Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz processor:

       | Naive implementation | First Optimization | Second Optimization
------------------------------------------------------------------------
Min.   |                 26.0 |              28.00 |                26.0
1st Qu.|                 78.0 |              48.75 |                39.0
Median |                132.0 |              57.00 |                41.0
Mean   |                130.1 |              61.20 |                41.6
3rd Qu.|                182.2 |              76.00 |                47.0
Max.   |                234.0 |              98.00 |                54.0
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa eb90ef23a1 AP_Math: AP_GeodesicGrid: fix algorithm for null vector
If v is the null vector, then alpha * v is still the null vector for any alpha
as a real number. That means that the null vector doesn't cross any section.
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa c28c3265c8 AP_Math: AP_GeodesicGrid: optimize with neighbor umbrellas
This is a first optimization of the algorithm. The struct for the neighbor
umbrella has only one member, but new members will be added in the next
optimization.

The table below summarizes the mean CPU time in ns from the brenchmark results
on an Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz processor:

Cases  | Naive implementation | First Optimization
--------------------------------------------------
Min.   |                 26.0 |              28.00
1st Qu.|                 78.0 |              48.75
Median |                132.0 |              57.00
Mean   |                130.1 |              61.20
3rd Qu.|                182.2 |              76.00
Max.   |                234.0 |              98.00

This optimization reduces the mean time for the worst case (Max. line) by more
than 50%.
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa 0ff05b7af3 AP_Math: test_geodesic_grid: test triangles indexes
That helps figuring out which intermediate step failed the high level call.
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa 4398e1e49b AP_Math: AP_GeodesicGrid: change order of triangles
- Change the order of the icosahedron triangles so that there's a uniform way of
finding the opposite triangle. The order visually still makes sense.

 - Change test to accommodate the order change.
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa ea412ad629 AP_Math: benchmark_geodesic_grid: add benchmark
That will help to benchmark improvements on the section search algorithm.
2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa 797a2da031 AP_Math: test_geodesic_grid: test when inclusive=true 2016-05-16 19:08:36 -03:00
Gustavo Jose de Sousa b299261ad4 AP_Math: AP_GeodesicGrid: add first implementation
The search for the geodesic section is still naive in this version.
Additionally, add unit tests.
2016-05-16 19:08:35 -03:00
Gustavo Jose de Sousa 3f2ad764ca AP_Math: Matrix3: add inverse() and invert() functions
Additionally, add unit tests.
2016-05-16 19:08:35 -03:00
Gustavo Jose de Sousa 06eea2838f AP_Math: Matrix3: add det() function
Function to calculate determinant. Additionally, add unit tests.
2016-05-16 19:08:35 -03:00
Gustavo Jose de Sousa 26959f1448 AP_Math: define golden ratio constant 2016-05-16 19:08:35 -03:00
dgrat 7ff8004f8f AP_Math: Replace is_zero() with a template function
This function only makes sense for floating point types. However this
function was also used for ints.
2016-05-16 19:08:35 -03:00
Ricardo de Almeida Gonzaga 481e3a2af6 AP_Math: Fix typos 2016-05-13 19:20:06 -03:00
Lucas De Marchi aa974399d0 AP_Math: use inline wrappers for constrain_* functions
This avoids some warnings about "constrain_float defined but not used"
in some compilers.
2016-05-11 22:51:19 -03:00
Lucas De Marchi bd6e268122 AP_Math: fix coding style
- cleanup whitespace
  - function reorder
  - fix brace position
2016-05-10 11:41:26 -03:00
Lucas De Marchi 1dbffef7ea AP_Math: remove trailing whitespace on headers 2016-05-10 11:41:26 -03:00
Lucas De Marchi ab1fa4b435 AP_Math: reorganize headers
Sort and add pragma once where needed.
2016-05-10 11:41:26 -03:00
dgrat 6d3b491c02 AP_Math: Replace is_equal with a type safe template function
It makes sense to consider also other floating point types.
2016-05-10 11:41:26 -03:00
dgrat 503867b7dc AP_Math: Replace safe_sqrt() by template function 2016-05-10 11:41:26 -03:00
dgrat 5deb0e8e03 AP_Math: Replace safe_asin() by template function 2016-05-10 11:41:26 -03:00
Lucas De Marchi 846b4927ec AP_Math: use if/else chain instead of 2 ternary operators 2016-05-10 11:41:26 -03:00
dgrat 174f899a29 AP_Math: Replace the constrain_* functions by a single template
Besides being simpler this reduces ~4k in the binary size for PX4.
2016-05-10 11:41:26 -03:00
Lucas De Marchi 348b07609c AP_Math: remove macros from unit tests
Avoid warnings like:

[2130/2168] Compiling libraries/AP_Math/tests/test_math.cpp
../../libraries/AP_Math/tests/test_math.cpp: In member function ‘virtual void MathTest_IsZero_Test::TestBody()’:
../../libraries/AP_Math/tests/test_math.cpp:73:196: warning: converting ‘false’ to pointer type for argument 1 of ‘char
testing::internal::IsNullLiteralHelper(testing::internal::Secret*)’ [-Wconversion-null]
../../libraries/AP_Math/tests/test_math.cpp:74:199: warning: converting ‘false’ to pointer type for argument 1 of ‘char
testing::internal::IsNullLiteralHelper(testing::internal::Secret*)’ [-Wconversion-null]

Use EXPECT_TRUE() and EXPECT_FALSE() from gtest instead.
2016-05-10 11:41:26 -03:00
dgrat 41661f815f AP_Math: Replace the pythagorous* functions with a variadic template
The new function can deal with a variable number of function parameters.
Additionally, I renamed the functions to norm(), because this is the
standard name used in several other projects.
2016-05-10 11:41:26 -03:00
Lucas De Marchi 880f130670 AP_Math: fix loss of precision on float addition
When using wrap_180_cd() we are adding a small float (180 * 100) to a
possibly big number. This may lose float precision as illustrated by the
unit test failing:

    OUT: ../../libraries/AP_Math/tests/test_math.cpp:195: Failure
    OUT: Value of: wrap_180_cd(-3600000000.f)
    OUT:   Actual: -80
    OUT: Expected: 0.f
    OUT: Which is: 0
2016-05-10 11:41:26 -03:00
dgrat 76362caee0 AP_Math: Replace wrap_* functions with template versions 2016-05-10 11:41:26 -03:00
dgrat 49cfd6fd9b AP_Math: Add gtest support for some functions
These functions (or variants thereof) now have unit tests:

  - is_zero()
  - is_equal()
  - sq()
  - pythagorous()
  - constrain()
  - wrap_180()
  - wrap_360()

Some tests in wrap_180_cd are failing: -180 should be wrapped to 180,
not -180.
2016-05-10 11:41:26 -03:00
Lucas De Marchi ceea7540fd AP_Math: rename test file
This will be reused for more math tests.
2016-05-10 11:41:26 -03:00
Gustavo Jose de Sousa b594b5a08b AP_Math: matrix_alg: disable FE_OVERFLOW in inverse4x4() for SITL
There are occasional overflows on the determinant calculation in inverse4x4()
when using calibration SITL model.
2016-05-10 16:16:37 +10:00
Gustavo Jose de Sousa a7543d369f AP_Math: matrix_alg: protect inverseixi() against overflow
Fail on inverse3x3() and inverse4x4() if there's float overflow during the
determinant calculation.
2016-05-10 16:16:37 +10:00
Gustavo Jose de Sousa 39f72610e2 AP_Math: quaternion: fix style
Remove trailing spaces and run astyle.
2016-05-10 16:16:37 +10:00
Andrew Tridgell e8142b0b5b AP_Math: added wrap_360() 2016-05-07 18:27:21 +10:00
Andrew Tridgell 97d27ce58f AP_Math: fixed memory leak
found by coverity
2016-04-26 16:41:44 +10:00
Andrew Tridgell 6165c42535 AP_Math: added from_axis_angle() method on Matrix3f
for arbitrary rotations in simulator
2016-04-22 10:28:15 +10:00
Michael du Breuil bb7cf6c0b6 AP_Math: Update location_sanitize to sanitize for lat/lng 2016-04-17 19:00:03 -07:00
Ricardo de Almeida Gonzaga 5bd034a5a8 Global: start using cmath instead of math.h 2016-04-05 21:06:19 -07:00
Andrew Tridgell 6bff07397e AP_Math: added linear_interpolate() function 2016-04-02 22:44:47 +11:00
Lucas De Marchi b4a8a0b961 AP_Math: replace header guard with pragma once 2016-03-16 18:40:41 +11:00
Gustavo Jose de Sousa 6729475b25 AP_Math: fix eulers example for PX4 2016-03-14 11:54:31 -03:00
Gustavo Jose de Sousa d9bb696fa3 AP_Math: avoid bias in rand_num() in eulers example
Use RAND_MAX to avoid bias.
2016-03-14 11:54:31 -03:00
Tom Pittenger 278fb2e60d AP_Math: add location sanity checker/fixer util 2016-03-02 08:48:26 -08:00
dgrat 672acdc8ef AP_Math: Created location.h header for location functions
Helps to order AP_Math functions by purpose.
2016-02-27 02:51:33 -03:00
Lucas De Marchi 7f685a12bd AP_Math: remove trailing whitespaces and tabs 2016-02-27 02:51:33 -03:00
dgrat 5148e41c1a AP_Math: Cleaned macro definitions
Moved Definitions into a separate header. Replaced PI with M_PI and
removed the M_PI_*_F macros.
2016-02-27 02:51:33 -03:00
dgrat 7c4c8ea579 AP_Math: Remove ROTATION_COMBINATION_SUPPORT
This function is not used.
2016-02-27 02:51:33 -03:00
Daniel Frenzel ead51a9d19 AP_Math: Removed useless "undef INLINE" 2016-02-25 02:10:39 -03:00
Daniel Frenzel ef7cf7c4aa AP_Math: Removed useless header
"float.h" does not exist. It is useless and wrong to include it.
2016-02-25 02:10:39 -03:00
Peter Barker 80bc7a50d7 AP_Math: define MATH_CHECK_INDEXES
Wrapped in ifndefs so the top-level Makefile can override

Assume MATH_CHECK_INDEXES is always defined
2016-02-19 12:34:23 -02:00
Gustavo Jose de Sousa c2e3f05dbf waf: ardupilotwaf: prefix build context methods with ap_
It helps to distinguish between things from waf and things from ardupilotwaf.
2016-01-22 20:10:29 -02:00