Constrain range helper function
This commit is contained in:
parent
cc7b3a97d5
commit
5bd9945e95
2
Makefile
2
Makefile
@ -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
20
src/math/Utilities.cpp
Normal 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
10
src/math/Utilities.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef PI
|
||||
#define PI 3.14159265358979f
|
||||
#endif
|
||||
|
||||
|
||||
namespace math {
|
||||
|
||||
float constrain(float value, float range);
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user