From cf07eb30196818fb21a551eb302d05b82afae0b6 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 12 Oct 2015 12:40:52 +0200 Subject: [PATCH] Fix the joystick range by properly limiting the calculation --- src/Joystick/Joystick.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index 5dbdcb032..beeeaaa7a 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -283,11 +283,16 @@ void Joystick::run(void) axis = _rgFunctionAxis[throttleFunction]; float throttle = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis]); + float roll_limited = std::max(static_cast(-M_PI_4), std::min(roll, static_cast(M_PI_4))); + float pitch_limited = std::max(static_cast(-M_PI_4), std::min(pitch, static_cast(M_PI_4))); + float yaw_limited = std::max(static_cast(-M_PI_4), std::min(yaw, static_cast(M_PI_4))); + float throttle_limited = std::max(static_cast(-M_PI_4), std::min(throttle, static_cast(M_PI_4))); + // Map from unit circle to linear range and limit - roll = std::max(-1.0f, std::min(tanf(asinf(roll)), 1.0f)); - pitch = std::max(-1.0f, std::min(tanf(asinf(pitch)), 1.0f)); - yaw = std::max(-1.0f, std::min(tanf(asinf(yaw)), 1.0f)); - throttle = std::max(-1.0f, std::min(tanf(asinf(throttle)), 1.0f)); + roll = std::max(-1.0f, std::min(tanf(asinf(roll_limited)), 1.0f)); + pitch = std::max(-1.0f, std::min(tanf(asinf(pitch_limited)), 1.0f)); + yaw = std::max(-1.0f, std::min(tanf(asinf(yaw_limited)), 1.0f)); + throttle = std::max(-1.0f, std::min(tanf(asinf(throttle_limited)), 1.0f)); // Adjust throttle to 0:1 range if (_throttleMode == ThrottleModeCenterZero) { -- 2.22.0