RoboidControl-cpp/Angle16.h
2024-03-15 10:46:30 +01:00

22 lines
410 B
C

#include "AngleUsing.h"
#include "Angle.h"
#include <math.h>
typedef AngleUsing<signed short> Angle16;
Angle16::AngleUsing(float angle) {
if (!isfinite(angle)) {
value = 0;
return;
}
// map float [-180..180) to integer [-32768..32767]
this->value = (signed short)((angle / 360.0F) * 65536.0F);
}
float Angle16::ToFloat() const {
float f = ((this->value * 180) / 32768.0F);
return f;
}