Commit Graph

115 Commits

Author SHA1 Message Date
murata c6bcb1d54c AP_Math: Collect CRC16 into CRC file
AP_Math: Collect CRC16 into CRC file
2019-05-21 09:19:19 +10:00
Mark Whitehorn b515431008 AP_Math: add expo and throttle_curve functions 2019-04-23 09:46:38 +10:00
Pierre Kancir f6941beeb9 AP_Math: fix circulary inclusion error 2019-04-02 19:00:02 +11:00
Andrew Tridgell ecbe67a0fe AP_Math: fixed inefficient sq() function 2019-02-23 21:04:00 +11:00
Andrew Tridgell d4eaf09baf AP_Math: added rotation_equal() 2018-10-01 14:26:56 +09:00
Peter Barker 6af0dcfed0 AP_Math: create a constrain_int64
The template system doesn't work across 32/64 bit builds (SITL
vs fmuv4), probably because int is typedef'd to int64
2018-06-15 08:01:22 +10:00
Tom Pittenger 3653ba61d7 AP_Math: add is_valid_octal helper function.
returns true if valid
2018-05-23 14:02:45 -07:00
bnsgeyer 600e0dac92 AP_Math: added support for cubic spline interpolation 2018-03-27 09:07:03 +11:00
Peter Barker 1ca76173a5 AP_Math: set radians(...) and degrees(...) as constexpr 2017-10-27 16:33:45 +11:00
Miguel Arroyo 7cea21afa2 AP_Math: Moves rand_vec3f from SITL_State. 2017-06-29 09:22:08 +10:00
Francisco Ferreira da5060964b AP_Math: uniformize template type parameter keyword
Use typename everywhere instead of class
2017-06-21 18:19:31 +09:00
Francisco Ferreira 7b98f41947 AP_Math: correct norm to need two arguments
Correctly use sqrtf instead of the double version
Stop casting to float since sq already returns one
2017-06-21 18:19:31 +09:00
Michael du Breuil 2cd6ff6dd5 AP_Math: Accept float epsilon in is_positive is_negative as a valid result 2017-05-27 10:46:59 -07:00
Michael du Breuil 5a15413513 AP_Math: Add is_negative and is_positive helpers 2017-05-24 15:22:27 -07:00
Andrew Tridgell 607220d12b AP_Math: rename macros to avoid conflicts
these macros were also defined in NuttX in clock.h
2017-05-06 15:21:14 +10:00
Andrew Tridgell 2fcecaa7c5 AP_Math: added rand_float() 2017-05-03 20:12:04 +10: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
Andrew Tridgell a8d10e8c2c AP_Math: added get_random16() 2016-12-02 09:49:38 +11:00
Lucas De Marchi 0d4caa3ccc AP_Math: remove declaration of not implemented functions 2016-08-03 00:16:35 -03:00
Lucas De Marchi 1ac712fa65 AP_Math: fix is_zero() after template conversion 2016-05-17 15:49:29 -07: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
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 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
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
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
dgrat 76362caee0 AP_Math: Replace wrap_* functions with template versions 2016-05-10 11:41:26 -03:00
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