123487

Dependencies:   mbed-dev-f303 FastPWM3

Committer:
benkatz
Date:
Sun Apr 09 03:05:52 2017 +0000
Revision:
25:f5741040c4bb
Parent:
20:bf9ea5125d52
Child:
26:2b865c00d7e9
Set current bandwidth from serial interface

Who changed what in which revision?

UserRevisionLine numberNew contents of line
benkatz 20:bf9ea5125d52 1
benkatz 20:bf9ea5125d52 2 #include "math_ops.h"
benkatz 20:bf9ea5125d52 3
benkatz 20:bf9ea5125d52 4
benkatz 20:bf9ea5125d52 5 float fmaxf(float x, float y){
benkatz 25:f5741040c4bb 6 /// Returns maximum of x, y ///
benkatz 20:bf9ea5125d52 7 return (((x)>(y))?(x):(y));
benkatz 20:bf9ea5125d52 8 }
benkatz 20:bf9ea5125d52 9
benkatz 20:bf9ea5125d52 10 float fminf(float x, float y){
benkatz 25:f5741040c4bb 11 /// Returns minimum of x, y ///
benkatz 20:bf9ea5125d52 12 return (((x)<(y))?(x):(y));
benkatz 20:bf9ea5125d52 13 }
benkatz 20:bf9ea5125d52 14
benkatz 20:bf9ea5125d52 15 float fmaxf3(float x, float y, float z){
benkatz 25:f5741040c4bb 16 /// Returns maximum of x, y, z ///
benkatz 20:bf9ea5125d52 17 return (x > y ? (x > z ? x : z) : (y > z ? y : z));
benkatz 20:bf9ea5125d52 18 }
benkatz 20:bf9ea5125d52 19
benkatz 20:bf9ea5125d52 20 float fminf3(float x, float y, float z){
benkatz 25:f5741040c4bb 21 /// Returns minimum of x, y, z ///
benkatz 20:bf9ea5125d52 22 return (x < y ? (x < z ? x : z) : (y < z ? y : z));
benkatz 20:bf9ea5125d52 23 }
benkatz 20:bf9ea5125d52 24
benkatz 20:bf9ea5125d52 25 void limit_norm(float *x, float *y, float limit){
benkatz 25:f5741040c4bb 26 /// Scales the lenght of vector (x, y) to be <= limit ///
benkatz 20:bf9ea5125d52 27 float norm = sqrt(*x * *x + *y * *y);
benkatz 20:bf9ea5125d52 28 if(norm > limit){
benkatz 20:bf9ea5125d52 29 *x = *x * limit/norm;
benkatz 20:bf9ea5125d52 30 *y = *y * limit/norm;
benkatz 20:bf9ea5125d52 31 }
benkatz 20:bf9ea5125d52 32 }