Skip to content

Commit 81f6129

Browse files
authored
Merge pull request #72 from narmstro2020/CommandHID
[cmd] Add deadband trigger methods to CommandGenericHID
2 parents 125788e + 0014b48 commit 81f6129

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: commands2/button/commandgenerichid.py

+18
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,24 @@ def axisGreaterThan(
177177
if loop is None:
178178
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
179179
return Trigger(loop, lambda: self._hid.getRawAxis(axis) > threshold)
180+
181+
def axisMagnitudeGreaterThan(
182+
self, axis: int, threshold: float, loop: Optional[EventLoop] = None
183+
) -> Trigger:
184+
"""
185+
Constructs a Trigger instance that is true when the axis magnitude is greater than
186+
``threshold``, attached to the given loop.
187+
188+
:param axis: The axis to read, starting at 0
189+
:param threshold: The value above which this trigger should return true.
190+
:param loop: the event loop instance to attach the trigger to.
191+
192+
:returns: a Trigger instance that is true when the axis magnitude is greater than the provided
193+
threshold.
194+
"""
195+
if loop is None:
196+
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
197+
return Trigger(loop, lambda: abs(self._hid.getRawAxis(axis)) > threshold)
180198

181199
def getRawAxis(self, axis: int) -> float:
182200
"""

0 commit comments

Comments
 (0)