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.
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.
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.
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
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.
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%.
- 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.
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.
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.
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
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.
For ROTATION_ROLL_90_PITCH_68_YAW_293 consider the angles as 90, 68.8
and 293.3 degrees to pre-calculate rotation. This matches the rotation
matrix used in code.
While at it, check not only the values are close enough but also the
length of the vector.
The rotations are supposed to follow the name of the enum, in order. The
ROTATION_YAW_293_PITCH_68_ROLL_90 was added with the name of an
intrinsic 321 rotation, but the matrix is actually a 123 rotation,
following the other rotations already present.
Change the name to follow the other names.
The problem with the current MIN/MAX macros is that they evaluate twice
the arguments. For example, these cases provide unintended results:
// a is incremented twice
a = MIN(a++, b);
// foo() with side-effects
a = MIN(foo(), b);
The alternative implementation here was provided by Daniel Frenzel using
template function. It doesn't have type safety as std::min and std::max,
but adding type safety would mean to check case by case what would be a
reasonable type and add proper casts. Here the arguments for MIN and MAX
can have different types and the return type is deduced from the
expression in the function.
Inspecting the current callers no place was found with the unintended
results above, but some in which now we don't calculate twice the
parameters will benefit from this new version. Examples:
float velocity_max = MIN(_pos_control.get_speed_xy(), safe_sqrt(0.5f*_pos_control.get_accel_xy()*_radius));
float acro_level_mix = constrain_float(1-MAX(MAX(abs(roll_in), abs(pitch_in)), abs(yaw_in))/4500.0, 0, 1)*ahrs.cos_pitch()
accel_x_cmss = (GRAVITY_MSS * 100) * (-(_ahrs.cos_yaw() * _ahrs.sin_pitch() / MAX(_ahrs.cos_pitch(),0.5f)) - _ahrs.sin_yaw() * _ahrs.sin_roll() / MAX(_ahrs.cos_roll(),0.5f));
track_leash_slack = MIN(_track_leash_length*(leash_z-track_error_z)/leash_z, _track_leash_length*(leash_xy-track_error_xy)/leash_xy);
RC_Channel_aux::move_servo(RC_Channel_aux::k_sprayer_pump, MIN(MAX(ground_speed * _pump_pct_1ms, 100 *_pump_min_pct),10000),0,10000);
The problem with using min() and max() is that they conflict with some
C++ headers. Name the macros in uppercase instead. We may go case by
case later converting them to be typesafe.
Changes generated with:
git ls-files '*.cpp' '*.h' -z | xargs -0 sed -i 's/\([^_[:alnum:]]\)max(/\1MAX(/g'
git ls-files '*.cpp' '*.h' -z | xargs -0 sed -i 's/\([^_[:alnum:]]\)min(/\1MIN(/g'