Dependents:   OBROT_ALL f3rc_3_auto_encode f3rc_3_auto_lintrace_912 EMG_Realtime_Filter ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Math.cpp Source File

Math.cpp

00001 #include "Math.h"
00002 #include "mbed.h"
00003 
00004 const float gPI = 3.1415926536f;
00005 
00006 float convertRange( float in, float oldMin, float oldMax, float newMin, float newMax ){
00007     return ( in - oldMin ) * ( newMax - newMin ) / ( oldMax - oldMin ) + newMin;
00008 }
00009 
00010 float convertRangePlusMinusPi( float deg ){
00011     while ( ( deg > gPI ) || ( deg < -gPI ) ){
00012         while ( deg > gPI ){
00013             deg -= 2.0f * gPI;
00014         }
00015         while ( deg < -gPI ){
00016             deg += 2.0f * gPI;
00017         }
00018     }
00019     
00020     return deg;
00021 }
00022 
00023 bool isNear( float a, float b, float error ){
00024     return ( abs( a - b ) < error );
00025 }