From c60481614e7b8e5be964d22910247793bc72578e Mon Sep 17 00:00:00 2001 From: Dennis Mannhart Date: Fri, 9 Mar 2018 11:57:52 +0100 Subject: [PATCH] ControlMath constrainxy: fix one of the condition --- src/modules/mc_pos_control/Utility/ControlMath.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/modules/mc_pos_control/Utility/ControlMath.cpp b/src/modules/mc_pos_control/Utility/ControlMath.cpp index d557f2c182..591a5acdac 100644 --- a/src/modules/mc_pos_control/Utility/ControlMath.cpp +++ b/src/modules/mc_pos_control/Utility/ControlMath.cpp @@ -139,7 +139,7 @@ matrix::Vector2f constrainXY(const matrix::Vector2f &v0, const matrix::Vector2f } else if (v0.length() < 0.001f) { /* The first vector is 0. */ - return v0 * 0.0f; + return v1.normalized() * max; } else { /* @@ -181,12 +181,10 @@ matrix::Vector2f constrainXY(const matrix::Vector2f &v0, const matrix::Vector2f * - s (=scaling factor) needs to be positive * - (max - ||v||) always larger than zero, otherwise it never entered this if-statement * */ - - float s = 0.0f; matrix::Vector2f u1 = v1.normalized(); float m = u1.dot(v0); float c = v0.length() * v0.length() - max * max; - s = -m + sqrtf(m * m - c); + float s = -m + sqrtf(m * m - c); return v0 + u1 * s; } }