RoboidControl-cpp/Angle8.cpp

25 lines
596 B
C++

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0.If a copy of the MPL was not distributed with this
// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
#include <math.h>
#include "Angle.h"
template <>
AngleOf<signed char>::AngleOf(float angle) {
if (!isfinite(angle)) {
value = 0;
return;
}
// map float [-180..180) to integer [-128..127]
float f = angle / 360.0F;
this->value = (signed char)(f * 256.0F);
}
template <>
AngleOf<signed char>::operator float() const {
float f = (this->value * 180) / 128.0F;
return f;
}