Commit Graph

306 Commits

Author SHA1 Message Date
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
Gustavo Jose de Sousa
a2d2661765 waf: use methods from bld instead of ardupilotwaf for the remaining 2016-01-22 20:10:29 -02:00
Gustavo Jose de Sousa
3d22490397 waf: examples: use methods from bld instead of ardupilotwaf 2016-01-22 20:10:29 -02:00
Gustavo Jose de Sousa
d281067bcc waf: make example binaries be placed in 'examples' dir
This commit makes examples' wscripts use ardupilotwaf.example() instead of
ardupilot.program().
2016-01-15 16:46:41 -02:00
Andrew Tridgell
60af7a6087 AP_Math: removed matrix3 parameter support 2016-01-04 11:14:43 +11:00
Andrew Tridgell
16e0a6d7b0 AP_Math: fixed angle between two vector3s 2016-01-01 12:41:05 +11:00
Lucas De Marchi
180359d6dd AP_Math: fix unit test
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.
2015-12-30 20:22:28 -02:00
Lucas De Marchi
ba3325ffd3 AP_Math: rename rotation
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.
2015-12-30 20:22:27 -02:00
Jonathan Challinger
83d5a6664a AP_Math: minor changes to matrix_alg in response to review 2015-12-29 22:57:21 -08: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
bugobliterator
fe62a049bd AP_Math: implement LU decomposition based matrix inverse
Replaces previous matlab generated code, which was giving imprecise results
2015-12-29 10:46:34 -08:00
Siddharth Bharat Purohit
a0c3cbffee AP_Math: add inverse matrix test example
fix example build
2015-12-29 10:46:34 -08:00
Siddharth Bharat Purohit
5af0cc8eaf AP_Math: add inverse rotate example function 2015-12-29 10:46:34 -08:00
Jonathan Challinger
7ed8b3814f AP_Math: add rotate_inverse to Vector3 2015-12-29 10:46:34 -08:00
Lucas De Marchi
a096703b06 Global: don't link with AP_Progmem
AP_Progmem is not used anymore.
2015-12-27 15:58:12 -02:00
Lucas De Marchi
502077d763 AP_Math: stop using Progmem.h 2015-12-27 15:58:12 -02: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
0a701088d4 AP_Math: fix bug in Quaternion::operator*= 2015-12-14 11:15:33 +09: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
Tom Pittenger
103af93ec3 AP_Math: compiler warnings - float compare to constant (zero) 2015-12-07 16:04:59 +09:00
Lucas De Marchi
f5c03c786d AP_Math: remove unused AP_ADC_AnalogSource 2015-12-03 13:32:43 +11:00
Gustavo Jose de Sousa
eef784fbe6 AP_Math: add benchmark for matrix multiplication 2015-12-03 07:54:31 +11:00
Gustavo Jose de Sousa
4266e924d0 AP_Math: add unit test for vector rotations
This unit test already shows that rotation is wrong for
ROTATION_YAW_293_PITCH_68_ROLL_90.
2015-12-03 07:54:31 +11:00
Caio Marcelo de Oliveira Filho
6e7b73610d waf: add waf support 2015-12-03 07:54:30 +11: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
Caio Marcelo de Oliveira Filho
8257e6ab89 AP_Math: examples use millis/micros/panic functions 2015-11-20 12:31:55 +09:00
Andrew Tridgell
8f4ce7f20b build: removed all nocore.inoflag files
these were APM2 specific
2015-11-16 08:05:17 +11:00
José Roberto de Souza
d53911e3f6 AP_Math: Add functions to convert microseconds to/from nanoseconds 2015-11-10 17:05:34 +11:00