From a5f9779e46d64735b8f6d5588e7b7cd74b2b9fa9 Mon Sep 17 00:00:00 2001 From: David Carley Date: Fri, 19 Aug 2022 18:06:32 +0000 Subject: [PATCH] Fixed the deadband issue. --- src/py/bbctrl/Jog.py | 4 +- src/py/inevent/JogHandler.py | 71 +++++++++++++----------------------- 2 files changed, 27 insertions(+), 48 deletions(-) diff --git a/src/py/bbctrl/Jog.py b/src/py/bbctrl/Jog.py index f198bdf..39c1537 100644 --- a/src/py/bbctrl/Jog.py +++ b/src/py/bbctrl/Jog.py @@ -37,7 +37,7 @@ class Jog(inevent.JogHandler): config = { "Logitech Logitech RumblePad 2 USB": { - "deadband": 0.1, + "deadband": 0.15, "axes": [ABS_X, ABS_Y, ABS_RZ, ABS_Z], "dir": [1, -1, -1, 1], "arrows": [ABS_HAT0X, ABS_HAT0Y], @@ -46,7 +46,7 @@ class Jog(inevent.JogHandler): }, "default": { - "deadband": 0.1, + "deadband": 0.15, "axes": [ABS_X, ABS_Y, ABS_RY, ABS_RX], "dir": [1, -1, -1, 1], "arrows": [ABS_HAT0X, ABS_HAT0Y], diff --git a/src/py/inevent/JogHandler.py b/src/py/inevent/JogHandler.py index f03c5a8..2deac48 100644 --- a/src/py/inevent/JogHandler.py +++ b/src/py/inevent/JogHandler.py @@ -1,30 +1,3 @@ -################################################################################ -# # -# This file is part of the Buildbotics firmware. # -# # -# Copyright (c) 2015 - 2018, Buildbotics LLC # -# All rights reserved. # -# # -# This file ("the software") is free software: you can redistribute it # -# and/or modify it under the terms of the GNU General Public License, # -# version 2 as published by the Free Software Foundation. You should # -# have received a copy of the GNU General Public License, version 2 # -# along with the software. If not, see . # -# # -# The software is distributed in the hope that it will be useful, but # -# WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # -# Lesser General Public License for more details. # -# # -# You should have received a copy of the GNU Lesser General Public # -# License along with the software. If not, see # -# . # -# # -# For information regarding this software email: # -# "Joseph Coffland" # -# # -################################################################################ - import logging from inevent.Constants import * @@ -97,7 +70,31 @@ class JogHandler: # Process event if event.type == EV_ABS and event.code in config['axes']: - pass + old_axes = list(self.axes) + deadband = config['deadband'] + axis = config['axes'].index(event.code) + + self.axes[axis] = event.stream.state.abs[event.code] + self.axes[axis] *= config['dir'][axis] + + value = abs(self.axes[axis]) + if value >= deadband: + sign = -1 if self.axes[axis] < 0 else 1 + delta = value - deadband + range = 1 - deadband + + # Scale the new value to the available range (full range, minus the deadband) + self.axes[axis] = (delta * sign) / range + else: + self.axes[axis] = 0 + + if self.horizontal_lock and axis not in [0, 3]: + self.axes[axis] = 0 + + if self.vertical_lock and axis not in [1, 2]: + self.axes[axis] = 0 + + if old_axes[axis] != self.axes[axis]: changed = True elif event.type == EV_KEY and event.code in config['speed']: old_speed = self.speed @@ -115,22 +112,4 @@ class JogHandler: log.debug(event_to_string(event, state)) - # Update axes - old_axes = list(self.axes) - - for axis in range(4): - self.axes[axis] = event.stream.state.abs[config['axes'][axis]] - self.axes[axis] *= config['dir'][axis] - - if abs(self.axes[axis]) < config['deadband']: - self.axes[axis] = 0 - - if self.horizontal_lock and axis not in [0, 3]: - self.axes[axis] = 0 - - if self.vertical_lock and axis not in [1, 2]: - self.axes[axis] = 0 - - if old_axes != self.axes: changed = True - if changed: self.changed()