Commit Graph

84 Commits

Author SHA1 Message Date
Andrew Tridgell e8142b0b5b AP_Math: added wrap_360() 2016-05-07 18:27:21 +10: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
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
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
Andrew Tridgell 60af7a6087 AP_Math: removed matrix3 parameter support 2016-01-04 11:14:43 +11:00
bugobliterator 1a4b4fa85e AP_Math: add inverse matrix test to check if inverse(mat)*mat = I
where I is an identity matrix (a matrix with diagonal elements = 1)
2015-12-29 10:46:35 -08:00
José Roberto de Souza d74bd533c8 AP_Math: Add function to convert frequency to/from microseconds 2015-12-16 08:18:17 +11:00
José Roberto de Souza 38575dd87a AP_Math: Fix parameter name in nsec_to_hz() 2015-12-16 08:18:17 +11:00
Jonathan Challinger fff275fd99 AP_Math: add wrap_2PI 2015-12-09 19:58:25 +09:00
Tom Pittenger f8b0a6a977 AP_Math: compiler warnings - undeclared function 2015-12-07 16:05:00 +09:00
Lucas De Marchi aa9168e0e9 AP_Math: remove unused maxf() 2015-12-01 16:28:18 -02:00
Lucas De Marchi 6f88fba8e5 AP_Math: remove unused minf() 2015-12-01 16:28:18 -02:00
Lucas De Marchi e0a0514c79 AP_Math: turn MIN/MAX macros into inline functions
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);
2015-12-01 16:28:18 -02:00
Lucas De Marchi 2591261af6 Global: rename min and max macros to uppercase
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'
2015-12-01 16:28:09 -02:00
José Roberto de Souza d53911e3f6 AP_Math: Add functions to convert microseconds to/from nanoseconds 2015-11-10 17:05:34 +11:00
José Roberto de Souza ca533a9d94 AP_Math: Add functions to convert frequency to/from nanoseconds 2015-11-10 17:05:34 +11:00
Lucas De Marchi fb28f426da AP_Math: remove check for AVR CPUs
Remove the checks for HAL_CPU_CLASS > HAL_CPU_CLASS_16 and
HAL_CPU_CLASS >= HAL_CPU_CLASS_75. Corresponding dead code will be
removed on separate commits.
2015-11-04 12:14:14 +11:00
Lucas De Marchi c7871d1bca AP_Math: remove checks for HAL_BOARD_APM2 and HAL_BOARD_APM1 2015-11-04 12:14:12 +11:00
Valmantas Palikša d4daf19151 AP_Math: Move simple math function implementations to header for better
compile time optimization

Functions like sq() are better moved to the header file as inline.
Compiler can then optimize these out when used in code, this saves cpu
cycles with stack push, pop during function calls.
2015-09-09 09:57:51 +10:00
Tom Pittenger 4771d19073 AP_Math: added locations_are_same(loc1,loc2) helper
returns true if lat and lng are the same, ignores alt and options
2015-09-08 17:05:54 +10:00
Jonathan Challinger 1c100498d4 AP_Math: use is_zero instead of defining our own epsilon 2015-09-03 16:59:13 +10:00
Siddharth Bharat Purohit b654b1c21b AP_Math: add inverse matrix to math library 2015-09-03 16:59:12 +10:00
Randy Mackay 46c652e42f Math: maxf and minf functions 2015-08-19 16:44:34 +09:00
Gustavo Jose de Sousa 4790371f9b AP_Math: standardize inclusion of libaries headers
This commit changes the way libraries headers are included in source files:

 - If the header is in the same directory the source belongs to, so the
 notation '#include ""' is used with the path relative to the directory
 containing the source.

 - If the header is outside the directory containing the source, then we use
 the notation '#include <>' with the path relative to libraries folder.

Some of the advantages of such approach:

 - Only one search path for libraries headers.

 - OSs like Windows may have a better lookup time.
2015-08-11 16:38:18 +10:00
Andrew Tridgell 77a2b4acf6 AP_Math: removed fast_atan 2015-05-05 13:57:22 +10:00
Andrew Tridgell 936fbbb362 AP_Math: removed AP_Math class 2015-05-05 13:27:03 +10:00
Tom Pittenger 4ec2fb3a9c AP_Math: Compiler warnings: nuke fast_atan2()
per Randy's suggestion, fast_atan2() is no longer necessary over atan2() because only copter uses it and copter is no longer supported on future builds of APM

ccd578664f (commitcomment-11025083)
2015-05-05 13:27:02 +10:00
Tom Pittenger 820f0bf02a AP_Math: compiler warnings: float to double promotion
cast as float because we're in magical template land where T minus T means promote to double
2015-05-05 13:26:58 +10:00
Tom Pittenger c93c773de2 AP_Math: change is_equal and is_zero to static class for better visability 2015-05-05 13:26:50 +10:00
Randy Mackay 0392292489 AP_Math: inline is_equal, add is_zero 2015-04-28 16:19:01 +09:00
dgrat 726d7df710 AP_Math: add is_equal to compare floats 2015-04-28 16:18:59 +09:00
Andrew Tridgell f38f86ab8c AP_Math: added location_path_proportion()
this can be used for glide slope calculations
2015-01-01 15:17:10 +11:00
Niels Joubert 398f32d538 AP_Math: Comments on WGS coordinate conversions 2014-06-30 10:29:56 +10:00
David Dewey 17374ff5e8 AP_Math: fast_atan2
This is 126us per call vs 199us on the AVR.  it is accurate to about
0.28 degrees

Committed by rmackay9 but contribution is from David Dewey
2014-06-06 18:50:41 +09:00
Niels Joubert 879eb5936b AP_MATH: Adding WGS GPS conversions, CRC16 checks, and double-precision Vectors and Matrices 2014-04-05 13:42:23 +11:00
Randy Mackay 37cfbc9ad5 AP_Math: float versions of wrap_360 and wrap_180 2014-02-15 05:27:45 +11:00
Andrew Tridgell 57d5345774 AP_Math: added M_PI_F define 2013-12-11 10:22:47 +11:00
Andrew Tridgell 5434b2c017 AP_Math: update location code to avoid float rounding
this avoids manipulating global coordinates as float variables. Using
a float reduces our precision from 1cm to about 70cm.

This also adds location_diff() which will be used in the L1 controller
to avoid global positions in floats
2013-08-13 12:07:34 +10:00
Andrew Tridgell 1d75b52411 AP_Math: use const references not pointers for location functions
this makes life a bit easier for the new AP_Mission library

Pair-Programmed-With: Brandon Jones <brnjones@gmail.com>
2013-08-05 10:23:40 +10:00
Randy Mackay bd6a60f28b AP_Math: add M_PI_2 definition
Required when building under arduino
2013-07-14 15:57:26 +09:00
Randy Mackay 8b87849acd Math: add wrap_PI 2013-06-01 18:21:29 +09:00
Randy Mackay d81b7b507d Math: add Leonard's fast tan function 2013-05-30 18:24:32 +09:00
Andrew Tridgell 5024da2695 AP_Math: fixed indent-tabs-mode 2013-05-30 09:51:51 +10:00
Randy Mackay 7c9d9b9800 AP_Math: use DEG_TO_RAD in longitude_scale
Also increased accuracy of RadiansToCentiDegrees although it is like the
compiler will throw away the extra digits anyway.
2013-05-05 14:31:24 +09:00
Andrew Tridgell ba83950fc4 libraries: replace constrain() with constrain_float()
this makes the type much more obvious. Thanks to Tobias for the
suggestion.
2013-05-02 10:25:40 +10:00