Control code for Triforce robot.

Dependencies:   triforce-esc PwmInRC mbed

Committer:
IonSystems
Date:
Fri May 05 14:12:24 2017 +0000
Revision:
1:026f79cfd378
Cameron has entered the game.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IonSystems 1:026f79cfd378 1 #ifndef MATH_H
IonSystems 1:026f79cfd378 2 #define MATH_H
IonSystems 1:026f79cfd378 3
IonSystems 1:026f79cfd378 4 /******************************************************************************/
IonSystems 1:026f79cfd378 5
IonSystems 1:026f79cfd378 6 float map(float in, float inMin, float inMax, float outMin, float outMax) {
IonSystems 1:026f79cfd378 7 // check it's within the range
IonSystems 1:026f79cfd378 8 if (inMin<inMax) {
IonSystems 1:026f79cfd378 9 if (in <= inMin)
IonSystems 1:026f79cfd378 10 return outMin;
IonSystems 1:026f79cfd378 11 if (in >= inMax)
IonSystems 1:026f79cfd378 12 return outMax;
IonSystems 1:026f79cfd378 13 } else { // cope with input range being backwards.
IonSystems 1:026f79cfd378 14 if (in >= inMin)
IonSystems 1:026f79cfd378 15 return outMin;
IonSystems 1:026f79cfd378 16 if (in <= inMax)
IonSystems 1:026f79cfd378 17 return outMax;
IonSystems 1:026f79cfd378 18 }
IonSystems 1:026f79cfd378 19 // calculate how far into the range we are
IonSystems 1:026f79cfd378 20 float scale = (in-inMin)/(inMax-inMin);
IonSystems 1:026f79cfd378 21 // calculate the output.
IonSystems 1:026f79cfd378 22 return outMin + scale*(outMax-outMin);
IonSystems 1:026f79cfd378 23 }
IonSystems 1:026f79cfd378 24
IonSystems 1:026f79cfd378 25 float clamp(float d, float min, float max) {
IonSystems 1:026f79cfd378 26 const float t = d < min ? min : d;
IonSystems 1:026f79cfd378 27 return t > max ? max : t;
IonSystems 1:026f79cfd378 28 }
IonSystems 1:026f79cfd378 29
IonSystems 1:026f79cfd378 30 #define BETWEEN(value, min, max) (value < max && value > min)
IonSystems 1:026f79cfd378 31 /******************************************************************************/
IonSystems 1:026f79cfd378 32
IonSystems 1:026f79cfd378 33 #endif