Constrain range helper function

This commit is contained in:
philsson 2018-09-02 19:02:49 +02:00
parent cc7b3a97d5
commit 5bd9945e95
3 changed files with 32 additions and 0 deletions

View File

@ -645,6 +645,8 @@ OBJECTS += ./src/drivers/MPU6000.o
OBJECTS += ./src/drivers/MS5611.o
OBJECTS += ./src/drivers/stepper.o
OBJECTS += ./src/drivers/servo.o
OBJECTS += ./src/math/Utilities.o
INCLUDE_PATHS += -I../

20
src/math/Utilities.cpp Normal file
View File

@ -0,0 +1,20 @@
#include "src/math/utilities.h"
#include <stdlib.h>
namespace math {
float constrain(float value, float range)
{
if (value < -range)
{
return -range;
}
if (value > range)
{
return range;
}
return value;
}
}

10
src/math/Utilities.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef PI
#define PI 3.14159265358979f
#endif
namespace math {
float constrain(float value, float range);
}