Dependents: OBROT_ALL f3rc_3_auto_encode f3rc_3_auto_lintrace_912 EMG_Realtime_Filter ... more
Revision 0:067c036b09e0, committed 2015-10-14
- Comitter:
- inst
- Date:
- Wed Oct 14 03:55:49 2015 +0000
- Commit message:
Changed in this revision
| Math.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Math.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Math.cpp Wed Oct 14 03:55:49 2015 +0000
@@ -0,0 +1,25 @@
+#include "Math.h"
+#include "mbed.h"
+
+const float gPI = 3.1415926536f;
+
+float convertRange( float in, float oldMin, float oldMax, float newMin, float newMax ){
+ return ( in - oldMin ) * ( newMax - newMin ) / ( oldMax - oldMin ) + newMin;
+}
+
+float convertRangePlusMinusPi( float deg ){
+ while ( ( deg > gPI ) || ( deg < -gPI ) ){
+ while ( deg > gPI ){
+ deg -= 2.0f * gPI;
+ }
+ while ( deg < -gPI ){
+ deg += 2.0f * gPI;
+ }
+ }
+
+ return deg;
+}
+
+bool isNear( float a, float b, float error ){
+ return ( abs( a - b ) < error );
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Math.h Wed Oct 14 03:55:49 2015 +0000 @@ -0,0 +1,10 @@ +#ifndef INCLUDED_MATH_H +#define INCLUDED_MATH_H + +extern const float gPI; + +float convertRange( float in, float oldMin, float oldMax, float newMin, float newMax ); +float convertRangePlusMinusPi( float deg ); +bool isNear( float a, float b, float error ); + +#endif