mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-29 13:20:35 +08:00
ControlMath: add addIfNotNan helper functions
This commit is contained in:
committed by
Kabir Mohammed
parent
eb50e89d87
commit
e53ae45188
@@ -215,4 +215,32 @@ bool cross_sphere_line(const Vector3f &sphere_c, const float sphere_r,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void addIfNotNan(float &setpoint, const float addition)
|
||||
{
|
||||
if (PX4_ISFINITE(setpoint) && PX4_ISFINITE(addition)) {
|
||||
// No NAN, add to the setpoint
|
||||
setpoint += addition;
|
||||
|
||||
} else if (!PX4_ISFINITE(setpoint)) {
|
||||
// Setpoint NAN, take addition
|
||||
setpoint = addition;
|
||||
}
|
||||
|
||||
// Addition is NAN or both are NAN, nothing to do
|
||||
}
|
||||
|
||||
void addIfNotNanVector3f(Vector3f &setpoint, const Vector3f &addition)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
addIfNotNan(setpoint(i), addition(i));
|
||||
}
|
||||
}
|
||||
|
||||
void setZeroIfNanVector3f(Vector3f &vector)
|
||||
{
|
||||
// Adding zero vector overwrites elements that are NaN with zero
|
||||
addIfNotNanVector3f(vector, Vector3f());
|
||||
}
|
||||
|
||||
} // ControlMath
|
||||
|
||||
Reference in New Issue
Block a user