Dependents:   OBROT_ALL f3rc_3_auto_encode f3rc_3_auto_lintrace_912 EMG_Realtime_Filter ... more

Committer:
inst
Date:
Wed Oct 14 03:55:49 2015 +0000
Revision:
0:067c036b09e0

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inst 0:067c036b09e0 1 #include "Math.h"
inst 0:067c036b09e0 2 #include "mbed.h"
inst 0:067c036b09e0 3
inst 0:067c036b09e0 4 const float gPI = 3.1415926536f;
inst 0:067c036b09e0 5
inst 0:067c036b09e0 6 float convertRange( float in, float oldMin, float oldMax, float newMin, float newMax ){
inst 0:067c036b09e0 7 return ( in - oldMin ) * ( newMax - newMin ) / ( oldMax - oldMin ) + newMin;
inst 0:067c036b09e0 8 }
inst 0:067c036b09e0 9
inst 0:067c036b09e0 10 float convertRangePlusMinusPi( float deg ){
inst 0:067c036b09e0 11 while ( ( deg > gPI ) || ( deg < -gPI ) ){
inst 0:067c036b09e0 12 while ( deg > gPI ){
inst 0:067c036b09e0 13 deg -= 2.0f * gPI;
inst 0:067c036b09e0 14 }
inst 0:067c036b09e0 15 while ( deg < -gPI ){
inst 0:067c036b09e0 16 deg += 2.0f * gPI;
inst 0:067c036b09e0 17 }
inst 0:067c036b09e0 18 }
inst 0:067c036b09e0 19
inst 0:067c036b09e0 20 return deg;
inst 0:067c036b09e0 21 }
inst 0:067c036b09e0 22
inst 0:067c036b09e0 23 bool isNear( float a, float b, float error ){
inst 0:067c036b09e0 24 return ( abs( a - b ) < error );
inst 0:067c036b09e0 25 }