From 234e4688b069c0d1b02fb775a15aa1e1d5d60720 Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Thu, 4 Sep 2025 15:17:29 +0200 Subject: [PATCH] Sticks: calculate expo only upon getter call --- src/lib/sticks/Sticks.cpp | 8 -------- src/lib/sticks/Sticks.hpp | 15 +++++---------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/lib/sticks/Sticks.cpp b/src/lib/sticks/Sticks.cpp index 0150e4af2f..31d06421f3 100644 --- a/src/lib/sticks/Sticks.cpp +++ b/src/lib/sticks/Sticks.cpp @@ -50,18 +50,11 @@ bool Sticks::checkAndUpdateStickInputs() manual_control_setpoint_s manual_control_setpoint; if (_manual_control_setpoint_sub.update(&manual_control_setpoint)) { - // Linear scale _positions(0) = manual_control_setpoint.pitch; _positions(1) = manual_control_setpoint.roll; _positions(2) = -manual_control_setpoint.throttle; _positions(3) = manual_control_setpoint.yaw; - // Exponential scale - _positions_expo(0) = math::expo_deadzone(_positions(0), _param_mpc_xy_man_expo.get(), _param_man_deadzone.get()); - _positions_expo(1) = math::expo_deadzone(_positions(1), _param_mpc_xy_man_expo.get(), _param_man_deadzone.get()); - _positions_expo(2) = math::expo_deadzone(_positions(2), _param_mpc_z_man_expo.get(), _param_man_deadzone.get()); - _positions_expo(3) = math::expo_deadzone(_positions(3), _param_mpc_yaw_expo.get(), _param_man_deadzone.get()); - _aux_positions(0) = manual_control_setpoint.aux1; _aux_positions(1) = manual_control_setpoint.aux2; _aux_positions(2) = manual_control_setpoint.aux3; @@ -85,7 +78,6 @@ bool Sticks::checkAndUpdateStickInputs() if (!_input_available) { // Timeout: set all sticks to zero _positions.zero(); - _positions_expo.zero(); } return _input_available; diff --git a/src/lib/sticks/Sticks.hpp b/src/lib/sticks/Sticks.hpp index a169549b01..56d6016386 100644 --- a/src/lib/sticks/Sticks.hpp +++ b/src/lib/sticks/Sticks.hpp @@ -58,21 +58,17 @@ public: bool isAvailable() { return _input_available; }; - // Position : 0 : pitch, 1 : roll, 2 : throttle, 3 : yaw - const matrix::Vector4f &getPosition() { return _positions; }; // Raw stick position, no deadzone - const matrix::Vector4f &getPositionExpo() { return _positions_expo; }; // Deadzone and expo applied - // Helper functions to get stick values more intuitively float getRoll() const { return _positions(1); } - float getRollExpo() const { return _positions_expo(1); } + float getRollExpo() const { return math::expo_deadzone(_positions(1), _param_mpc_xy_man_expo.get(), _param_man_deadzone.get()); } float getPitch() const { return _positions(0); } - float getPitchExpo() const { return _positions_expo(0); } + float getPitchExpo() const { return math::expo_deadzone(_positions(0), _param_mpc_xy_man_expo.get(), _param_man_deadzone.get()); } float getYaw() const { return _positions(3); } - float getYawExpo() const { return _positions_expo(3); } + float getYawExpo() const { return math::expo_deadzone(_positions(3), _param_mpc_yaw_expo.get(), _param_man_deadzone.get()); } float getThrottleZeroCentered() const { return -_positions(2); } // Convert Z-axis(down) command to Up-axis frame - float getThrottleZeroCenteredExpo() const { return -_positions_expo(2); } + float getThrottleZeroCenteredExpo() const { return -math::expo_deadzone(_positions(2), _param_mpc_z_man_expo.get(), _param_man_deadzone.get()); } const matrix::Vector2f getPitchRoll() { return _positions.slice<2, 1>(0, 0); } - const matrix::Vector2f getPitchRollExpo() { return _positions_expo.slice<2, 1>(0, 0); } + const matrix::Vector2f getPitchRollExpo() { return {getPitchExpo(), getRollExpo()}; } const matrix::Vector &getAux() const { return _aux_positions; } @@ -93,7 +89,6 @@ public: private: bool _input_available{false}; matrix::Vector4f _positions; ///< unmodified manual stick inputs that usually move vehicle in x, y, z and yaw direction - matrix::Vector4f _positions_expo; ///< modified manual sticks using expo function matrix::Vector _aux_positions;