Added clip for integers and updated attitude from tilt

This commit is contained in:
dario 2024-09-16 15:51:08 +02:00
parent 04f6ad2b1d
commit d9c2f66a01
3 changed files with 19 additions and 2 deletions

View File

@ -9,6 +9,8 @@ namespace sta
{ {
float fast_inv_sqrt(float); float fast_inv_sqrt(float);
int clip(int value, int min, int max);
float clip(float value, float min, float max); float clip(float value, float min, float max);
} // namespace math } // namespace math
} // namespace sta } // namespace sta

View File

@ -24,8 +24,8 @@ namespace sta
az /= norm; az /= norm;
} }
float theta = std::atan(ay / az); float theta = std::atan2(ay, az);
float phi = std::atan(-ax / std::sqrt(ay*ay + az*az)); float phi = std::atan2(-ax, std::sqrt(ay*ay + az*az));
Quaternion tilt( Quaternion tilt(
std::cos(phi / 2.0f) * std::cos(theta / 2.0f), std::cos(phi / 2.0f) * std::cos(theta / 2.0f),

View File

@ -22,6 +22,21 @@ namespace sta
return y; return y;
} }
int clip(int value, int min, int max)
{
if (value < min)
{
return min;
}
if (value > max)
{
return max;
}
return value;
}
float clip(float value, float min, float max) float clip(float value, float min, float max)
{ {
if (value < min) if (value < min)